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
13const 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   
16// 卸载ocx: regsvr32 /
17const CATID CLSID_SafeItem = { 0x51DF1D91, 0xDA4E, 0x47DA, { 0xA5, 0xBE, 0x84, 0xA9, 0x6A, 0xDD, 0x24, 0x25 } };
18const WORD _wVerMajor = 1;
19const WORD _wVerMinor = 0;
20
21
22
23// CHelloApp::InitInstance - DLL initialization
24
25 BOOL CHelloApp::InitInstance()
26 {
27    BOOL bInit = COleControlModule::InitInstance();
28
29if (bInit)
30    {
31// TODO: Add your own module initialization code here.
32    }
33return bInit;
34 }
35
36
37
38// CHelloApp::ExitInstance - DLL termination
39int CHelloApp::ExitInstance()
40 {
41// TODO: Add your own module termination code here.
42return 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); 55if (FAILED(hr))
56return hr;
57
58// Make sure the HKCR\Component Categories\{..}
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.
66int len = wcslen(catDescription);
67if (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
76return 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); 87if (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    }
94if (pcr != NULL)
95        pcr->Release();
96return 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); 107if (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
115if (pcr != NULL)黄绮珊资料
116        pcr->Release();
117
118return hr;
119 }
120
121// DllRegisterServer - Adds entries to the system registry
122
123 STDAPI DllRegisterServer(void)
女明星性感图片
124 {
125    AFX_MANAGE_STATE(_afxModuleAddrThis);
126
127if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
128return ResultFromScode(SELFREG_E_TYPELIB);
129
130if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
131return ResultFromScode(SELFREG_E_CLASS);
132
133// 标记控件初始化安全.
134// 创建初始化安全组件种类
135    HRESULT hr = CreateComponentCategory(CATID_SafeForInitializing, 136        L"Controls safely initializable from persistent data!");
137if (FAILED(hr))
138return hr;
139// 注册初始化安全
140    hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing);
141if (FAILED(hr))
142return hr;
143
144// 标记控件脚本安全
145// 创建脚本安全组件种类
146    hr = CreateComponentCategory(CATID_SafeForScripting, L"Controls safely scriptable!"); 147if (FAILED(hr))
148return hr;
149// 注册脚本安全组件种类
150    hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting);
151if (FAILED(hr))
152return hr;
153
154return 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
165if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
166return ResultFromScode(SELFREG_E_TYPELIB);
167
168if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
169return ResultFromScode(SELFREG_E_CLASS);
170
171return NOERROR;
172 }