반응형

To use a C++/CLI library in an MFC project, you will need to do the following:

  1. Create a C++/CLI wrapper class for the library. This class should include declarations for the library's functions and types that you want to use in your MFC project.
  2. In the MFC project's properties, under Configuration Properties -> Common Language Runtime Support, select "Common Language Runtime Support"
  3. In the MFC project's properties, under Configuration Properties -> General, set "Use of MFC" to Use MFC in a Shared DLL
  4. In the MFC project's properties, under C/C++ -> General, set "Common Language Runtime Support" to "Common Language Runtime Support (/clr)"
  5. In the MFC project's properties, under Linker->Input->Additional Dependencies add the path of the C++/CLI library
  6. In the MFC class, include the C++/CLI wrapper class's header file and use the library's functions and types as needed.
  7. In the MFC class's constructor or OnInitDialog function, use #using <msclr/marshal.h> to marshal String^ to CString if you want to pass String^ or get CString from String^.

It's also important to note that, C++/CLI library should be built as "mulit-threaded" to match the runtime of the MFC

An example of how to use a C++/CLI wrapper class in an MFC project:

 

#using <msclr/marshal.h>
using namespace msclr::interop;

class CMFCDlg : public CDialogEx
{
  public:
    CMFCDlg(CWnd* pParent = NULL);
    ...
    // create an instance of the C++/CLI class
    CLIWrapper^ m_pCLIWrapper;
};

CMFCDlg::CMFCDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CMFCDlg::IDD, pParent)
, m_pCLIWrapper(gcnew CLIWrapper())
{
   // to use
   m_pCLIWrapper->useCLILibrary();
}

It's important to note that, when building your project, you will need to make sure that the C++/CLI library is included in the project properties, so that it is linked with your MFC project at build time.

반응형

'[====== Development ======] > C++' 카테고리의 다른 글

EnumDisplayMonitors API  (0) 2023.08.17
DoEvents for C++  (0) 2023.02.27
MFC 프로젝트에서 C# 라이브러리를 사용하는 방법  (0) 2023.01.12
C++ Save Raw file  (0) 2022.12.02
System::String에서 Char로 변환  (0) 2022.09.04

+ Recent posts