请教各位大侠:
    我在dll中写了一个类,类中准备用win32方式注册一个窗口,但是在注册窗口的时候要用当前程序的实例句柄,不然,注册不成功,请问怎么才能获得当前dll的hinstance实例句柄,代码如下:怎么老是注册不成功,就不能使用窗口的消息队列????
         static TCHAR szAppName[]=TEXT("隐含窗口");
MSG msg;
WNDCLASS wndclass;
HINSTANCE hInstancemain=AfxGetInstanceHandle( );
wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
    wndclass.lpfnWndProc   = WndProc1;
    wndclass.cbClsExtra    = 0 ;
    wndclass.cbWndExtra    = 0 ;
    wndclass.hInstance     = hInstancemain ;
    wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
    wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
    wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
    wndclass.lpszMenuName  = NULL ;
    wndclass.lpszClassName = NULL ;
     if (!AfxRegisterClass(&wndclass))
     {
          return 0 ;
     } m_hwnd= CreateWindow (szAppName,      // window class name
                          TEXT (" "), // window caption
                          WS_OVERLAPPEDWINDOW,  // window style
                          CW_USEDEFAULT,          // initial x position
                          CW_USEDEFAULT,           // initial y position
                          CW_USEDEFAULT,            // initial x size
                          CW_USEDEFAULT,           // initial y size
                          NULL,                   // parent window handle
                          NULL,                    // window menu handle
                          hInstancemain,          // program instance handle
                          NULL) ;                     // creation parameters
     
     ShowWindow (m_hwnd,SW_HIDE) ;
     UpdateWindow (m_hwnd) ;while (GetMessage (&msg, NULL, 0, 0))
     {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
     }
     return  1;
}

解决方案 »

  1.   

    GetModuleHandle
    The GetModuleHandle function retrieves a module handle for the specified module if the file has been mapped into the address space of the calling process. To avoid the race conditions described in the Res section, use the GetModuleHandleEx function.HMODULE GetModuleHandle(
      LPCTSTR lpModuleName   // module name
    );
      

  2.   

    我用hInstance = GetModuleHandle取得的事例句柄,hInstance得值为unused,在执行下面的语句时不成功,窗口没有注册成功?请问为什么(急用)
    if (!AfxRegisterClass(&wndclass))
         {
              return 0 ;
         }
      

  3.   

    首先告诉你,DLL里不支持MESSAGE
      

  4.   

    那个HINSTANCE应在DllMain()中抓住,做为全部变量存放起来以便提供给各个函数使用.
      

  5.   

    HINSTANCE 是个好东西,可以通过他得到很多东西!