大家都知道一个标准的Win32 dll每当有一个exe调用他时系统会把他映射到该exe的虚拟地址空间中,这样所有的exe都可以相互独立的访问dll,互不干扰。可我现在由于需求特殊,需要他们互相"干扰",也就是说,希望dll只有一个实例,每个exe访问的都是这个实例,请大家不吝指教~

解决方案 »

  1.   

    考虑将Dll里边的计数器锁定在1(唯一加载一次)
      

  2.   

    在你的DllMain中进行设置BOOL WINAPI DllMain(
        HINSTANCE hinstDLL,  // handle to DLL module
        DWORD fdwReason,     // reason for calling function
        LPVOID lpReserved )  // reserved
    {
        // Perform actions based on the reason for calling.
        switch( fdwReason ) 
        { 
            case DLL_PROCESS_ATTACH:
             // Initialize once for each new process.
             // Return FALSE to fail DLL load.
                break;        case DLL_THREAD_ATTACH:
             // Do thread-specific initialization.
                break;        case DLL_THREAD_DETACH:
             // Do thread-specific cleanup.
                break;        case DLL_PROCESS_DETACH:
             // Perform any necessary cleanup.
                break;
        }
        return TRUE;  // Successful DLL_PROCESS_ATTACH.
    }
      

  3.   

    通过共享数据段共享数据 data_seg
      

  4.   

    To jiangsheng(蒋晟.MSMVP2004Jan):
    共享数据段不符合我的要求,麻烦您看看下面的连接好吗?http://community.csdn.net/Expert/topic/3907/3907722.xml?temp=.7537042