Hi,
I am trying to implement a seemingly simply thing here. But, I just can't seem to get it to work.
What I need is: Access a variable from an EXE, where the variable is located in a DLL.
#define __ZG_WIN32__
#ifdef __ZG_WIN32__
#define __ZG_DLL_EXPORT__ __declspec(dllexport)
#endif
#ifdef __ZG_LINUX__ //LINUX
#define __ZG_DLL_EXPORT__ extern
#endif
__ZG_DLL_EXPORT__ int ZGKillerStarter = -1;
#define __ZG_WIN32__
#ifdef __ZG_WIN32__
#define __ZG_DLL_IMPORT__ __declspec(dllimport)
#endif
#ifdef __ZG_LINUX__ //LINUX
#define __ZG_DLL_IMPORT__
#endif
__ZG_DLL_IMPORT__ int ZGKillerStarter;
Then, I linked the dll in the compiler as an additional dependency. I even checked the variable's name with Dependency Walker.
When I run the program, ZGKillerStarter's value is its initial value of -1, and never changes even when I change it on the DLL side! ><<br mode="hold" />
Furthermore, I even tried to "Get" the variable's value using an EXPORT/IMPORT function, but it kept on returning the initial value every time. Moreover, I did the same but using a function that returns the variable's address, still initial value ><;
Q1: What am I missing here?
Q2: What is the equivalent of this code in Linux?
Q3: How do I do the inverted action of the above!? (NOT at the same time, just exporting variables from EXE, importing to DLL)
NOTE: There are certain restrictions that I need to follow, which prohibits me from using function pointers.
reference:
http://msdn.microsoft.com/en-us/library/8fskxacy%28v=vs.80%29.aspx[
^]
__ZG_DLL_IMPORT__ int ZGKillerStarter;__ZG_DLL_IMPORT__ int ZG_getZG( );__ZG_DLL_IMPORT__ int *ZG_getZG( );
int XXXXX = 0; int IIII = 9;
__ZG_DLL_EXPORT__ int ZG_getZG( ){
return ZGKillerStarter;
}
__ZG_DLL_EXPORT__ int *ZG_getZG( ){
return &ZGKillerStarter;
}
void funcX()
{
if( ZGKillerStarter < 10000 ) ZGKillerStarter += 8;
}
__ZG_DLL_IMPORT__ int ZGKillerStarter;__ZG_DLL_IMPORT__ int ZG_getZG( );__ZG_DLL_IMPORT__ int *ZG_getZG( );
int XXXXX = 0; int IIII = 9;
__ZG_DLL_EXPORT__ int ZG_getZG( ){
return ZGKillerStarter;
}
__ZG_DLL_EXPORT__ int *ZG_getZG( ){
return &ZGKillerStarter;
}
void funcX()
{
if( ZGKillerStarter < 10000 ) ZGKillerStarter += 8;
}