c++ - Initialize variable shared beetween dlls -
i all, have win32 application , several dlls must use global variable. in each dll put
extern mytype* myvariable = null;
and in main program have
mytype* myvariable = null; mavariable = new mytype(); ....
now, when dlls loaded myvariable null , cannot use it. how can share instance of main program dlls?
you should make changes in program. if possible can move myvariable
exe 1 dll. can continue use import libraries.
it general can export functions or data exe, in cases there less sense this. can see seldom. example winword.exe or excel.exe this.
if need export frunction or data exe , use in dll should use dynamical binding respect of getprocaddress , getmodulehandle(null). can such kind of manual binding inside of dllmain. address of myvariable
of exe can save in local myvariable
of dll.
Comments
Post a Comment