dll创建无模式对话框

来源:互联网 发布:程序员转正答辩演讲稿 编辑:程序博客网 时间:2024/06/04 18:30

由资源冲突造成的,可以这样解决  
   
  在DllMain函数所在的cpp文件中定义一个全局变量  
  HINSTANCE   g_hInstance;  
   
  在DllMain函数的  
  if   (dwReason   ==   DLL_PROCESS_ATTACH)  
  {  
  TRACE0("DOCUSERTOOLS.DLL   Initializing!/n");  
   
  //   Extension   DLL   one-time   initialization  
  if   (!AfxInitExtensionModule(DocUserToolsDLL,   hInstance))  
  return   0;  
   
  这几句之后加入  
  g_hInstance   =   hInstance;  
   
  然后在你的DLL导出函数所在的cpp文件中加入如下定义  
  extern   HINSTANCE   g_hInstance;  
  即使用上面所定义的全局变量  
   
  然后加入如下宏定义  
  #define   BEGININSTANCE   HINSTANCE   hOldInstance   =   ::AfxGetResourceHandle();::AfxSetResourceHandle(g_hInstance);  
  #define   ENDINSTANCE   ::AfxSetResourceHandle(hOldInstance);  
   
  将这几句  
  theApp.pMyDlg     =   new   CMyDlg(pParentWnd);  
  theApp.pMyDlg->Create(IDD_MYDLG,pParentWnd);  
  theApp.pMyDlg->ShowWindow(SW_SHOW);  
   
  改为这样  
  BEGININSTANCE  
  theApp.pMyDlg     =   new   CMyDlg(pParentWnd);  
  theApp.pMyDlg->Create(IDD_MYDLG,pParentWnd);  
  theApp.pMyDlg->ShowWindow(SW_SHOW);  
  ENDINSTANCE  

原创粉丝点击