I all,
I have a win32 application and several DLLs that must use a global variable. In each dll I put
extern MYTYPE* myvariable = NULL;
and in the main program I have
MYTYPE* myvariable = NULL;
mavariable = new MYTYPE();
....
now, when the DLLs are loaded myvariable is NULL and I cannot use it. How can I share the instance of the main program with all the DLLs?
You should make some changes in your program. If it is possible you can just move
myvariablefrom the EXE to one from DLL. Then you can continue to use import libraries.It general you can export functions or data from an EXE, but in the most cases there are less sense to do this. So you can see this very seldom. For example WinWord.exe or Excel.exe do this.
If really need to export frunction or data from EXE and use it in the DLL you should use dynamical binding with respect of GetProcAddress and GetModuleHandle(NULL). You can do such kind of manual binding inside of DllMain. The address of
myvariableof the EXE you can save in the localmyvariableof the DLL.