Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 to create so that my wrapper will be exposed to C#. I see in Visual Studio 2008 there are different types of projects under Visual C++--->CLR---->

class library,
CLR Empty Project,
Windows form control library,
CLR Console Application,
Windows Forms Application,
Windows Service

Which one should I use?

like image 817
krishna555 Avatar asked May 17 '12 19:05

krishna555


People also ask

What is C++/CLI application?

You can create Visual C++ programs that target the Common Language Runtime (CLR) and use the . NET Framework, and build them on the command line. Visual C++ supports the C++/CLI programming language, which has additional types and operators to target the . NET programming model.

Can I create C project in Visual Studio?

Two options. Great, now that Visual Studio Community is installed, you have two options for developing and running C programs on Windows. The first option involves using any text editor you like to write your source code, and using the "cl" command within the Developer Command Prompt to compile your code.

What is C++ CLR project?

A common language runtime (CLR) project is used to create C++/CLI project, i.e. to use C++/CLI to target the . NET platform. The main difference between projects is what Visual Studio comes up with in terms of pre-created files.


1 Answers

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.

like image 91
Viktor Latypov Avatar answered Oct 07 '22 00:10

Viktor Latypov