> The DLL component is CLI supported and there is some code in this
> component that uses the .NET syntax and Frameworks.
> So what setting should I do in the project setting for some of my
> classes/files to be complied as an unmanaged pure native C++?
You can set /CLR on or off in each .cpp file individually. Turn it on for
the whole project,. as you have done, then turn it off for the files
containing only native (unmanaged) code. When you have the VC++ procject
properties dialog open, you can still click on files/projects in the
solution explorer to change the scope that you're working on. Click on the
unmanaged .cpp file to set options for just that file.
> Ok, in every file that uses the myNativeClass.h, I will do it like
> that:
[quoted text clipped - 5 lines]
> But what about another unmanaged pure native C++ class that is used
> by the first unmanaged pure native C++ class?
Doesn't matter. That's why it's good practice to use the push/pop features
of #pragma managed (and a number of other compiler pragmas, for that
matter). It's safe to wrap everywhere, and the contents of the header file
will always be interpreted as unmanged. For portability/reuse reasons, you
might not want to do the wrapping when the #include is in an unmanged file,
but it does not harm to do so.
> Do I need also to add the #pragma managed(push,off) and #pragma
> managed(pop) in the unmanaged pure native C++ that uses another
[quoted text clipped - 3 lines]
> classes/files in a separate unmanaged pure native DLL component, and
> use the DLL in another managed C++/CLI DLL component?
That is a common solution. If you have a lot of native code to integrate,
it may well be the better solution. Design a pure C or COM interface to the
native code, and then use that component from your managed code.
> What is the safest way to do it? Or event better; what is the
> deployment that will make the unmanaged pure native C++ code run the
> fastest?
Done correctly, either approach will be just as safe and just as performant.
If anything, the performance factors probably lean slightly towards the
mixed-mode DLL, since the compiler-interop can work at the C++ level and you
don't have to force your API into C or COM.
-cd
Ben Voigt [C++ MVP] - 25 Jun 2007 06:36 GMT
>> Maybe it's better to simply put all the unmanaged pure native C++
>> classes/files in a separate unmanaged pure native DLL component, and
[quoted text clipped - 12 lines]
> towards the mixed-mode DLL, since the compiler-interop can work at the C++
> level and you don't have to force your API into C or COM.
It's probably preferable to make the native code a static library instead of
a DLL. Then you get the benefits of a separate build environment and the
benefits of mixed-mode.
> -cd