본문 바로가기

Programming/C#

C++/CLI wrapper for native C++ to use as reference in C#

C++로 dll을 만들고 이를 C#에서 사용하려면 다음과 같이 몇가지 작업을 해주어야 한다.

첨부 문서를 보고 좀 더 자세히 확인합시다.

다음 클라우드 / work/documents/C#/CPP_CLI_tutorial.pdf


첫째, #using 키워드를 이용해서 Systeml.dll 사용을 선언한다.

#using <mscorlib.dll>

#using <System.dll>

using namespace System;

using namespace System::Text;

using namespace System::IO;

using namespace System::Net;

using namespace System::Net::Sockets;

using namespace System::Collections;


둘째, 위처럼만 하면 에러가 주루룩 뜬다.. 이는 CLI 런타임을 추가해주면 해결된다.

Choose Project -> Properties from the menu bar. In the Project properties window, under Configuration Properties -> General, make sure that Common Language Runtime Support is set to Common Language Runtime Support (/clr)



셋째, 아래와 같이 레퍼런스 클래스를 만든다.