应用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