Thus, how I create the g_iYourVariable initialise in one of source files of the first dll, use it in all other sources of the same dll, export it and be able to imported (assuming using __declspec(dllimport)) in any other dll file)? 1 - define a handy macro to make it easy for your DLL to use dllexport and allow clients to use dllimport. Put it in a file, call it "MyDLLExports.h". #ifdef BUILDING_MYDLL # define MyDLLExport __declspec(dllexport) #else # define MyDLLExport __declspec(dllimport) #endif
2 - compile all sources of your DLL with the preprocessor definition 'BUILDING_MYDLL' added - when building only your DLL. 3 - define a header file where your variable will exist. e.g. #ifndef __MyDLL_MyVar_h__ #define __MyDLL_MyVar_h__ #include "MyDLLExports.h" MyDLLExport int MyDLLmyVar; #endif // __MyDLL_MyVar_h__
C
cyrfer
@cyrfer
Posts
-
Dll and global variables.