S
shu
I get a _CrtIsValidHeapPointer assertion when trying to have a
unmanaged static object linked to my managed project.
I have tried to reduce the problem to a very simple case:
One unmanaged .cpp file (compiled with "No Common language Runtime
Support") added to a managed .exe project. This unmanaged .cpp
declares a static object, with
its constructor and destructor.
At runtime, the constructor gets called at startup. Then, the code
enters the atexit function in order to make sure that the static
destructor gets called at program exit. And inside this function is
when I get the assertion.
I have tried the same test in a managed DLL instead of an EXE, and
everything works fine. It looks like and issue with the CRT
initialization.
I have been 2 days investigating, reading through forums, etc... Some
people have come with the solution of calling __crt_dll_initialize at
the managed main(). It works. But it gets called of course after the
static constructor, suggesting that the assertion is being solved only
because calling the function forces the linker to link something...
Anyway, it seems a bug for me. Or at least, a documentation problem.
Any help will be greatly appreciated.
unmanaged static object linked to my managed project.
I have tried to reduce the problem to a very simple case:
One unmanaged .cpp file (compiled with "No Common language Runtime
Support") added to a managed .exe project. This unmanaged .cpp
declares a static object, with
its constructor and destructor.
At runtime, the constructor gets called at startup. Then, the code
enters the atexit function in order to make sure that the static
destructor gets called at program exit. And inside this function is
when I get the assertion.
I have tried the same test in a managed DLL instead of an EXE, and
everything works fine. It looks like and issue with the CRT
initialization.
I have been 2 days investigating, reading through forums, etc... Some
people have come with the solution of calling __crt_dll_initialize at
the managed main(). It works. But it gets called of course after the
static constructor, suggesting that the assertion is being solved only
because calling the function forces the linker to link something...
Anyway, it seems a bug for me. Or at least, a documentation problem.
Any help will be greatly appreciated.