如题,假设int g_nCount;定义在module1.exe模块中,module1.exe加载了module2.dll库模块和module3.dll库模块,如何在module2.dll和module3.dll库模块中引用module1.exe模块中定义的全局变量g_nCount?
我知道:在模块内的static全局变量可以被模块内所用函数访问,但不能被模块外其它函数访问;所以用static int g_nCount;肯定是不行的,多谢高手指点.着急,欢迎大家帮忙顶!顶者有分,分不够可以再多给点.
我知道:在模块内的static全局变量可以被模块内所用函数访问,但不能被模块外其它函数访问;所以用static int g_nCount;肯定是不行的,多谢高手指点.着急,欢迎大家帮忙顶!顶者有分,分不够可以再多给点.
int GetGlobalCount()
{
return g_nCount;
}
但是该定义出现在module1.exe可执行模块中,而根据我的理解exe可执行模块并没有dll库模块中的导出函数表的概念,所以恐怕这个思路不能继续下去了。
Re:经过上机试验也证明这个也是行不通的,原因在dll模块做link时会出现如下错误:error LNK2001: unresolved external symbol "int g_nCount" (?g_nCount@@3HA),再说假设你的说法是对的,那么导出函数/变量表恐怕就没有什么意义了。
To syy64(太平洋):对于用接口函数的参数而言,所以要引用该全局变量的dll模块(module2.dll,moduel3.dll...module10001.dll)有10000个,而难道要在这10000个dll模块都定义一个对应的接口函数吗?是不是可能有更简单的方法。
declare an interface pointer
in the exe
assign an object that implements the interface to the interface pointer
IConfig * g_config;
In your Exe
g_config=new CConfig();struct IConfig
{
virtual int GetCount()=0;
}