如题,假设int g_nCount;定义在module1.exe模块中,module1.exe加载了module2.dll库模块和module3.dll库模块,如何在module2.dll和module3.dll库模块中引用module1.exe模块中定义的全局变量g_nCount?
我知道:在模块内的static全局变量可以被模块内所用函数访问,但不能被模块外其它函数访问;所以用static int g_nCount;肯定是不行的,多谢高手指点.着急,欢迎大家帮忙顶!顶者有分,分不够可以再多给点.

解决方案 »

  1.   

    To jun_01(无名小卒):假设用来输出该全局变量的函数如下:
    int GetGlobalCount()
    {
      return g_nCount; 
    }
    但是该定义出现在module1.exe可执行模块中,而根据我的理解exe可执行模块并没有dll库模块中的导出函数表的概念,所以恐怕这个思路不能继续下去了。
      

  2.   

    static int g_nCount;是可以的在exe程序中declare static int g_nCount;然后在dll中declare extern static int g_nCount
      

  3.   

    To spanzhang(红尘斩丝客):static int g_nCount;是可以的在exe程序中declare static int g_nCount;然后在dll中declare extern static int g_nCount
    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模块都定义一个对应的接口函数吗?是不是可能有更简单的方法。
      

  4.   

    in the DLL 
    declare an interface pointer 
    in the exe
    assign an object  that implements the interface to the interface pointer
      

  5.   

    To jiangsheng(蒋晟.Net[MVP]):thanks for your suggestions, but I can't understand your abstract solution about the interface pointer, neither to implement your idea concretely. would you please show me some code snippets in the DLL and in the EXE? thanks again.
      

  6.   

    in your DLL
    IConfig * g_config;
    In your Exe
    g_config=new CConfig();struct IConfig 
    {
        virtual int GetCount()=0;
    }
      

  7.   

    定义abstract class,各个dll实现virtual interface
      

  8.   

    appreciated so much for your help, receive your points you deserve.