需要写的DLL要链接到一个ActiveX控件中,这个ActiveX控件被DEPHI程序调用,
我需要在DLL中设置程序的光标,光标资源放在DLL中,原来用AfxGetApp()->LoadCursor可以在MFC的DEMO程序上跑通。
但放到DEPHI上却不行。void TTCCanvas::SetCursor(UINT resource)
{
HCURSOR hcursor = NULL;
HINSTANCE hinstance = NULL;
HINSTANCE hinstanceOld = NULL; //hcursor = AfxGetApp()->LoadCursor(resource); hinstanceOld = AfxGetResourceHandle();
hinstance = AfxFindResourceHandle(MAKEINTRESOURCE(resource),RT_CURSOR);
AfxSetResourceHandle(hinstance);
hcursor = LoadCursor(hinstance,MAKEINTRESOURCE(resource));
::SetCursor(hcursor);
AfxSetResourceHandle(hinstanceOld);
}这样也不行,
HINSTANCE hInst;
//hcursor = AfxGetApp()->LoadCursor(resource);
hInst = AfxFindResourceHandle(MAKEINTRESOURCE(resource),RT_CURSOR);
hcursor = ::LoadCursor(hInst,MAKEINTRESOURCE(resource));谢谢!!!

解决方案 »

  1.   

    你估计是个共享dll吧
    要不你改静态链接资源那种dll
    要不然的话你可以试试
    ::AfxSetResourceHandle(::GetModuleHandle(_T("IMDIALOG.dll/*你的dll名字*/")));
    /////....引用资源的代码
    ::AfxSetResourceHandle(::GetModuleHandle(NULL));
      

  2.   

    对,是MFC扩展DLL,动态链接MFC的,你说的那个共享DLL,我不知道指的是什么,能将DLL静态链接到ACTIVEX中?怎么做?
      

  3.   

    BOOL WINAPI DllMain(
      HINSTANCE hinstDLL,
      DWORD fdwReason,
      LPVOID lpvReserved
    );
    dll入口点记住hinstDLL 后面装载资源用void TTCCanvas::SetCursor(UINT resource) 

    HCURSOR hcursor = NULL; 
    hcursor = ::LoadCursor(hinstDLL,MAKEINTRESOURCE(RT_CURSOR)); 
    ::SetCursor(hcursor); 
      

  4.   

    ::AfxSetResourceHandle(::GetModuleHandle(_T("IMDIALOG.dll/*你的dll名字*/"))); 
    这个可以用,但是要是DLL文件名改变了怎么办啊
      

  5.   

    在函数开头加上AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
    AfxSetResourceHandle(hinstance); //hinstance要是你dll的instance
      

  6.   

    在你dll的所有导出函数的每一个函数第一行加上 AFX_MANAGE_STATE(AfxGetStaticModuleState()); 
      

  7.   

    对了
    要及时释放
    ::AfxSetResourceHandle(::GetModuleHandle(NULL));
      

  8.   

    AFX_MANAGE_STATE(AfxGetStaticModuleState())
    放到函数里面会报错,、mfcs42d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in TTMeas.obj
    mfcs42d.lib(dllmodul.obj) : error LNK2005: __pRawDllMain already defined in TTMeas.obj
    mfcs42d.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in TTMeas.obj; second definition ignored
    mfcs42d.lib(dllmodul.obj) : warning LNK4006: __pRawDllMain already defined in TTMeas.obj; second definition ignored
      

  9.   

    我的DLL是MFC扩展DLL,把整个类都导出来,不能用AFX_MANAGE_STATE(AfxGetStaticModuleState())
    要换成,AFX_MANAGE_STATE(AfxGetAppModuleState()) ,但放到函数前面会有ASSERT错误!,好像是没设置ResourceHandle.
      

  10.   

    void TTCCanvas::SetCursor(UINT resource)
    {
    HCURSOR hcursor = NULL;
    HINSTANCE hinstance = NULL;
    HINSTANCE hinstanceOld = NULL; //FIXME:不能使用AfxGetApp()->LoadCursor
    hcursor = ::LoadCursor(g_hInst_resource,MAKEINTRESOURCE(resource));
    ::SetCursor(hcursor);
    }已经解决,DLL初始化的时候我保存了HINSTANCE,多谢各位!!!