Tech Support > Microsoft Windows > Development Resources > Initializing a global variable of an application using a DLL exported data!
Initializing a global variable of an application using a DLL exported data!
Posted by Jay on November 21st, 2006


Hi,

I am having some problems initializing a global variable of an
application using a DLL exported data.

I have written a DLL where I am exporting a variable (int a) using the
".DEF" file.

I am trying to access the variable using _declspec(dllimport) in the
application.

Now, I have another global variable "glob" in my application file
app.c.

When I do,

int *glod = &a;

in app.c I get the following error during compilation :

error C2099: initializer is not a constant

If I do the same thing within a function it works. It doesn't work for
global variables only.

What should I do to solve this problem? Please let me know.

Thanks in advance!

Regards,
Jayaraghavendran.K

Posted by David Lowndes on November 21st, 2006


It seems a reasonable limitation to me. The DLL could be loaded at
different addresses so there's no way to know the load address of the
exported variable at the time the main program is loaded.

Dave


Similar Posts