views:

66

answers:

1

More to the point, I have a native C++ application, that may never need to use managed types. I would like the CLR to remain unloaded until I the codepath that actually depends on managed types is actually hit.

I was trying to accomplish this using the /clr switch in Visual Studio 2005, but as far as I can tell as soon as I use that switch, the entire C++ app becomes a managed app. Is there a way to specify it only for a certain compilation unit or function? I tried to mark my main() function in my test app with #pragma unmanaged, but that didn't stop it from loading the CLR at startup.

+2  A: 

If you have a mixed mode C++ DLL the CLR will load as soon as your DLL / EXE is loaded into the process. There is no way to change this behavior.

The best way to achieve what you're looking for is to break up your DLL into 2 parts

  1. Parts that are purely native
  2. Parts that require the use of managed code.

You can control when the CLR starts up by controlling when #2 is loaded into the process. This requires a bit of setup work but should get the result you're looking for.

JaredPar
Thanks for this suggestion. Can you explain how to achieve this or point to a resource that explains it?
Leeks and Leaks
Would this be using delayed loading features in the linker?
Leeks and Leaks