Saturday, February 12, 2011

Some notes on porting C++ application to C++\CLI.

In this post listed some issues which I experienced while porting a plugin (.dll) for native C++ application to C++\CLI.

__fastcall calling convention
C++\CLI code can't compile if there is functions with __fastcall.

 __declspec(naked) functions, and functions calling them.
They should be wrapped with "#pragma managed(push, off)" / "#pragma managed(pop)".

Loader lock
Dlls with managed code can't be loaded by LoadLibrary from DllMain.
(discussions about calling LoadLibrary from DllMain : stackoverflow.com, rsdn.ru)

boost.thread
For now (boost 1.45) it can't be used in C++\CLI. It uses something related with TLS, but it isn't allowed for managed code. System loader will yield 0xC000007B error (STATUS_INVALID_IMAGE_FORMAT, ERROR_BAD_EXE_FORMAT). 

VEH
MSVS may hang during debugging managed code with managed vectored exception handler. So VEH callback function must be wrapped with #pragma managed(push, off). But be ready that it will catch managed exceptions. For example it can catch breakpoint (0x80000003) during debugging.

No comments:

Post a Comment