What type of project needs to be created for C++/CLI?

前端 未结 1 1115
逝去的感伤
逝去的感伤 2021-01-06 02:33

I am writing a wrapper for my native C++ methods in C++/CLI which will expose them to C#. Now I am using Visual Studio 2008. Can any one tell me what type of project I need

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-06 03:13

    You have to create the project of type Class Library. The most important thing is to specify the "Common Language Runtime Support" option (set to "Common Language Runtime Support (/clr)") in the Project Properties -> Configuration Properties -> General

    This will allow you to use the

    #pragma managed
    ... use your native stuff here
    #pragma unmanaged
    

    pragmas and link with the native .lib files.

    See this link for subtle details

    http://www.codeguru.com/cpp/cpp/cpp_managed/interop/article.php/c6867/Consuming-Unmanaged-C-Class-Libraries-from-NET-Clients.htm

    There is a catch (not mentioned in this article) for 64-bit builds. The "Linker->Input->Force Symbol References" must be set to "_DllMainCRTStartup" for 64-bit and to "_DllMainCRTStartup@12" for 32-bit.

    0 讨论(0)
提交回复
热议问题