我做的一个DLL中某个类有成员变量CBitmap bmp,在类构造函数中进行bmp.LoadBitmap(IDB_XXX)调入了位图。
当在其它模块中使用此DLL中的bmp时却显示不出指定的位图,程序未出错,而此类其它的
成员变量(如CString型)可以正常得到值。
等待高手作答

解决方案 »

  1.   

    用API函数LoadBitmap(HINSTANCE,IDB_XXX)吧。我看好象是INSTANCE问题,因为你要从DLL中装载。
      

  2.   

    这是我的辅助函数:global function!
    file:picturedll.cpp
    CPictureDllApp theApp;
    extern "C" BOOL PASCAL EXPORT LoadPictureFromDll(int index,HBITMAP &hBitmap)
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    HINSTANCE hInstance=::GetModuleHandle("PictureDll.dll");
    if(hBitmap=::LoadBitmap(hInstance,MAKEINTRESOURCE(index)))
    return true;
    else return false;
    }
    //index 是picturedll.dll中的bitmap资源的id!
    ----------------
    在别的工程中的用法是:
    void CTestPictureDllDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    typedef BOOL (PASCAL LOADBITMAPFROMDLL)(int index,HBITMAP &hBitmap);
    HINSTANCE hInstance;
    LOADBITMAPFROMDLL *pLoadBitmapFromDll;
    if(!this->m_hInstanceDll)
    {
      VERIFY(hInstance=::LoadLibrary("PictureDll.dll"));
    if(hInstance)
    {
      this->m_bLoaded=true;
      this->m_hInstanceDll=hInstance;
    }
    else
      return ;
    }
    VERIFY(pLoadBitmapFromDll=(LOADBITMAPFROMDLL*)::GetProcAddress(this->m_hInstanceDll,"LoadPictureFromDll"));

    HBITMAP hBitmap;
    int index= IDB_BITMAP_GIRL;
    if((pLoadBitmapFromDll)(index,hBitmap))
    {
      this->m_PictureCtrl.SetBitmap(hBitmap);
      Invalidate();
    }
    else
    {
      MessageBox("failed to load the dynamic library");
    }
    }
      

  3.   

    file :picturedll.def
    -----------------------
    ; PictureDll.def : Declares the module parameters for the DLL.LIBRARY      "PictureDll"
    DESCRIPTION  'PictureDll Windows Dynamic Link Library'EXPORTS
        ; Explicit exports can go here
    LoadPictureFromDll
      

  4.   

    上面的 m_hInstanceDll;
    是类CTestPictureDllDlg中的一个成员变量!
    CTestPictureDllDlg
    {
    ...
    private:
    BOOL m_bLoaded;
    HINSTANCE m_hInstanceDll;}