J
Jesper Schmidt
Hi,
I have a relatively large C++ code base, which requires that static
initializers are called when a dll is loaded. This seems to work well
for native code, but it does not work for files compiled with the /CLR
option enabled. I will try to give a simple example that illustrates my
problem.
Library code:
-----------
#include <cstdio>
static int dummy = std:uts("initializer called");
Program code:
-----------------
#include "windows.h"
int main()
{
LoadLibrary("library.dll");
return 0;
}
The program prints, "initializer called", when the library is
compiled without the /CLR option, but it prints nothing if the library
is compiled with the /CLR option. My initial thought was that the
linker eliminated the unreferenced 'dummy' symbol, but this does
not seem to be the case because I can locate the 'dummy'
initializer in the 'library.dll'. Does anybody know why the CLR
loader does not call the 'dummy' initializer when the library is
loaded, or does anybody know how I force the CLR loader to call the
'dummy' initializer without referring directly to the 'dummy'
symbol itself?
Many thanks in advance for any help!
Jesper
I have a relatively large C++ code base, which requires that static
initializers are called when a dll is loaded. This seems to work well
for native code, but it does not work for files compiled with the /CLR
option enabled. I will try to give a simple example that illustrates my
problem.
Library code:
-----------
#include <cstdio>
static int dummy = std:uts("initializer called");
Program code:
-----------------
#include "windows.h"
int main()
{
LoadLibrary("library.dll");
return 0;
}
The program prints, "initializer called", when the library is
compiled without the /CLR option, but it prints nothing if the library
is compiled with the /CLR option. My initial thought was that the
linker eliminated the unreferenced 'dummy' symbol, but this does
not seem to be the case because I can locate the 'dummy'
initializer in the 'library.dll'. Does anybody know why the CLR
loader does not call the 'dummy' initializer when the library is
loaded, or does anybody know how I force the CLR loader to call the
'dummy' initializer without referring directly to the 'dummy'
symbol itself?
Many thanks in advance for any help!
Jesper