RegSvr32 加載失敗,找不到指定的模塊


應用ocx注冊時, 出現下圖錯誤:

解決方案(檢測缺少庫):

  0. 使用管理員運行cmd,注冊ocx

  1. mfc100.dll、mfc100u.dll、msvcp100.dll、msvcr100.dll之類的庫(可能是ocx工程屬性為Use MFC in a Shared DLL

  2. 可能是缺少應用程序需要的庫,可以寫個簡單的win32控制台程序。

   (ocx依賴的庫全部#pragma comment進來,調用一個庫函數),運行demo,會提示缺少庫的名稱

       2. 或者使用win32程序直接調用ocx,查看錯誤提示

    3. 使用depends工具查看缺少庫

  4. 工程間使用不同的MD(MDD)、MT(MTD),  也可能導致程序無法運行

 

 

附ocx注冊為安全組件代碼

  1 // Hello.cpp : Implementation of CHelloApp and DLL registration.
  2 
  3 #include "stdafx.h"
  4 #include <objsafe.h>
  5 
  6 #ifdef _DEBUG
  7 #define new DEBUG_NEW
  8 #endif
  9 
 10 
 11 CHelloApp theApp;
 12 
 13 const GUID CDECL _tlid = { 0x872CF3E6, 0x5EBF, 0x4436, { 0xA5, 0x25, 0x58, 0xCE, 0xF, 0xAA, 0x38, 0x5B } };
 14 //注意與idl middleocx uuid(51DF1D91-DA4E-47DA-A5BE-84A96ADD2425)相同, 之前注冊了ocx,需要卸載后重新注冊
 15 // 注冊ocx: regsvr32    middleocx.ocx
 16 // 卸載ocx: regsvr32 /u middleocx.ocx
 17 const CATID CLSID_SafeItem = { 0x51DF1D91, 0xDA4E, 0x47DA, { 0xA5, 0xBE, 0x84, 0xA9, 0x6A, 0xDD, 0x24, 0x25 } };
 18 const WORD _wVerMajor = 1;
 19 const WORD _wVerMinor = 0;
 20 
 21 
 22 
 23 // CHelloApp::InitInstance - DLL initialization
 24 
 25 BOOL CHelloApp::InitInstance()
 26 {
 27     BOOL bInit = COleControlModule::InitInstance();
 28 
 29     if (bInit)
 30     {
 31         // TODO: Add your own module initialization code here.
 32     }
 33     return bInit;
 34 }
 35 
 36 
 37 
 38 // CHelloApp::ExitInstance - DLL termination
 39 int CHelloApp::ExitInstance()
 40 {
 41     // TODO: Add your own module termination code here.
 42     return COleControlModule::ExitInstance();
 43 }
 44 
 45 
 46 
 47 // 創建組件種類
 48 HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)
 49 {
 50     ICatRegister* pcr = NULL ;
 51     HRESULT hr = S_OK ; 
 52 
 53     hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
 54         NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
 55     if (FAILED(hr))
 56         return hr; 
 57 
 58     // Make sure the HKCR\Component Categories\{..catid...}
 59     // key is registered.
 60     CATEGORYINFO catinfo;
 61     catinfo.catid = catid;
 62     catinfo.lcid = 0x0409 ; // english 
 63 
 64     // Make sure the provided description is not too long.
 65     // Only copy the first 127 characters if it is.
 66     int len = wcslen(catDescription);
 67     if (len>127)
 68         len = 127;
 69     wcsncpy_s(catinfo.szDescription, catDescription, len);
 70     // Make sure the description is null terminated.
 71     catinfo.szDescription[len] = '\0'; 
 72 
 73     hr = pcr->RegisterCategories(1, &catinfo);
 74     pcr->Release(); 
 75 
 76     return hr;
 77 } 
 78 
 79 // 注冊組件種類
 80 HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
 81 {
 82     // Register your component categories information.
 83     ICatRegister* pcr = NULL ;
 84     HRESULT hr = S_OK ;
 85     hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
 86         NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
 87     if (SUCCEEDED(hr))
 88     {
 89         // Register this category as being "implemented" by the class.
 90         CATID rgcatid[1] ;
 91         rgcatid[0] = catid;
 92         hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);
 93     }
 94     if (pcr != NULL)
 95         pcr->Release();
 96     return hr;
 97 }
 98 
 99 // 卸載組件種類
100 HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
101 {
102     ICatRegister* pcr = NULL ;
103     HRESULT hr = S_OK ; 
104 
105     hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
106         NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
107     if (SUCCEEDED(hr))
108     {
109         // Unregister this category as being "implemented" by the class.
110         CATID rgcatid[1] ;
111         rgcatid[0] = catid;
112         hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid);
113     } 
114 
115     if (pcr != NULL)
116         pcr->Release(); 
117 
118     return hr;
119 }
120 
121 // DllRegisterServer - Adds entries to the system registry
122 
123 STDAPI DllRegisterServer(void)
124 {
125     AFX_MANAGE_STATE(_afxModuleAddrThis);
126 
127     if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
128         return ResultFromScode(SELFREG_E_TYPELIB);
129 
130     if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
131         return ResultFromScode(SELFREG_E_CLASS);
132 
133     // 標記控件初始化安全.
134     // 創建初始化安全組件種類
135     HRESULT hr = CreateComponentCategory(CATID_SafeForInitializing,
136         L"Controls safely initializable from persistent data!");
137     if (FAILED(hr))
138         return hr;
139     // 注冊初始化安全
140     hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing);
141     if (FAILED(hr))
142         return hr; 
143 
144     // 標記控件腳本安全
145     // 創建腳本安全組件種類 
146     hr = CreateComponentCategory(CATID_SafeForScripting, L"Controls safely scriptable!");
147     if (FAILED(hr))
148         return hr;
149     // 注冊腳本安全組件種類
150     hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting);
151     if (FAILED(hr))
152         return hr; 
153 
154     return NOERROR;
155 }
156 
157 
158 
159 // DllUnregisterServer - Removes entries from the system registry
160 
161 STDAPI DllUnregisterServer(void)
162 {
163     AFX_MANAGE_STATE(_afxModuleAddrThis);
164 
165     if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
166         return ResultFromScode(SELFREG_E_TYPELIB);
167 
168     if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
169         return ResultFromScode(SELFREG_E_CLASS);
170 
171     return NOERROR;
172 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM