Is it possible to run unmanaged C ++, usually from a managed C ++ / CLI project?

I am in the process of packaging a clean unmanaged VC ++ 9 project in C ++ / CLI to use it directly from a .NET application. I know how to write wrappers , and that unmanaged code can be executed with .NET , but that I cannot completely wrap my head:

  • Unmanaged lib is a very complex C ++ library and uses many built-in and other functions, so I can not compile them into a managed DLL /clr. I need to compile this into a separate DLL using a regular VC ++ compiler.

  • How to export characters from this unmanaged code so that it can be used from a C ++ / CLI project? I will mark every class I need, how extern? Is it easy or is there some difficulty?

  • How do I access exported characters from a C ++ / CLI project? I just include the unmanaged source code header files and does C ++ compose the personal code from the unmanaged DLL? Or do I need to manually write a separate set of "extern" classes in a new header file that points to classes in the DLL?

  • When my C ++ / CLI project creates unmanaged classes, will the unmanaged code work fine in a normal VC9 runtime or force it to run in .NET? causing more compatibility issues?

  • A C ++ project creates many instances and has its own custom-made garbage collector written in simple C ++, this is a DirectX sound visualization tool and manages many DirectX objects. Will all of this work fine, or will such Win32 features be affected in any way?

+5
source share
3 answers

You can start with a regular native C ++ project (imported, say, from Visual Studio 6.0 from more than ten years ago), and when you create it today, it will reference the current version of the VC runtime.

foo.cpp, , /CLR. IL , , .NET , JIT IL.

- -, , .

, "" CLR , CLR () . ++/CLI , , CLR. .

foo.h :

void bar(int a, int b);

, foo.cpp CLR. / . - CLR.

:

  • /ZI - ,
  • /Gm - Minimal rebuild
  • /EHsc - ++, SEH (/EHa)
  • /RTC - ,
  • - .
  • /GR- - - On (/GR)

/CLR .

+7

Daniel, . '#pragma managed' , .

, . , PLUS ++/CLI . , , Dll, .NET( ++/CLI) !

, , . ++/CLI dll/assembly , ( ).

, - ++, DirectX. , .

pInvoke .NET. , . - (, 10 ) , , OO-, ++/CLI. # . .NET, /, ++/CLI. VS 2012 Intellisense.

+1

PInvoke DLL. API Windows .Net. , ++, C.

It also seems that C ++ interaction technology might come in handy: http://msdn.microsoft.com/en-us/library/2x8kf7zx(v=vs.80).aspx

0
source

All Articles