我正在处理一个包含多个C++ COM Dlls的遗留项目。每次在调试配置上构建解决方案时,生成过程都会为每个COM项目提供错误:
Error 10 error MSB3073: The command "
regsvr32 /s /c "D:\*****removed intentionally****_d.dll"
echo regsvr32 exec. time > ".\Debug\regsvr32.trg"
echo Server registration done!
:VCEnd
" exited with code -1073741819.
我最近加入了这个项目,所以当我问到这个项目时,我被告知每个人都忽略这些错误,因为解决方案成功地建立在第二个构建上。
我决定进行更深入的研究,似乎COM注册本身就成功了(这就解释了为什么第二个构建没有重新尝试注册),但是对regsvr32的调用返回一个错误代码(0xC0000005)。这就是建筑失败的原因。
我还尝试从自定义构建步骤中删除注册,而是选择从链接器属性表“RegistryOutput=YES”注册,并得到了相同的错误。
我尝试用其中一个dll调试regsvr32,并发现了以下内容:
在regsvr32.exe: 0xC0000005:访问冲突读取位置0x005bf028的0x759849c1处出现第一次异常。
oleaut32.dll!_MemFree@4() + 0x25 bytes
oleaut32.dll!OLE_TYPEMGR::Release() + 0x1b138 bytes
oleaut32.dll!ReleaseAppData() + 0x317 bytes
oleaut32.dll!_OACleanup@0() + 0x5 bytes
ole32.dll!wCoUninitialize(COleTls & Tls, int fHostThread) Line 2830 C++
ole32.dll!CoUninitialize() Line 2620 C++
regsvr32.exe!_wWinMain@16() + 0xa77 bytes
regsvr32.exe!__initterm_e() + 0x1b1 bytes
kernel32.dll!@BaseThreadInitThunk@12() + 0x12 bytes
ntdll.dll!___RtlUserThreadStart@8() + 0x27 bytes
ntdll.dll!__RtlUserThreadStart@8() + 0x1b bytes
你对此有何看法?我是否应该像团队的其他成员一样忽略它(产品在开发和生产中运行良好)?
你知道为什么即使注册成功,我也会被违反访问权吗?在注册COM dll之后还有其他进程/逻辑运行吗?还有其他方向吗?
这是处理注册的类代码:
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_C3DT2D, CC3DT2D)
END_OBJECT_MAP()
class CMy3DT2DApp : public CWinApp
{
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMy3DT2DApp)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
//}}AFX_VIRTUAL
//{{AFX_MSG(CMy3DT2DApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMy3DT2DApp, CWinApp)
//{{AFX_MSG_MAP(CMy3DT2DApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CMy3DT2DApp theApp;
BOOL CMy3DT2DApp::InitInstance()
{
_Module.Init(ObjectMap, m_hInstance, &LIBID_MY3DT2DLib);
return CWinApp::InitInstance();
}
int CMy3DT2DApp::ExitInstance()
{
_Module.Term();
return CWinApp::ExitInstance();
}
/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
return _Module.GetClassObject(rclsid, riid, ppv);
}
/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
// registers object, typelib and all interfaces in typelib
return _Module.RegisterServer(TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
return _Module.UnregisterServer(TRUE);
}
发布于 2013-11-18 16:42:38
发布于 2013-11-18 11:38:47
我认为内存损坏是通过混合ATL和MFC代码来进行初始化/终止的。
如果使用VS2010生成"MFC ActiveX控件“,您将注意到:
1 CMy3DT2DApp
应该从COleControlModule
而不是CWinApp
派生
2 InitInstance
和ExitInstance
方法应该调用COleControlModule::InitInstance
和COleControlModule::ExitInstance
3 DllRegisterServer应该是:
AFX_MANAGE_STATE(_afxModuleAddrThis);
if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
return ResultFromScode(SELFREG_E_TYPELIB);
if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
return ResultFromScode(SELFREG_E_CLASS);
return NOERROR;
4类似于DllUnregisterServer
的实现(使用AfxOleUnregisterTypeLib
)
5没有DllCanUnloadNow
的实现
一种解决方案可能是禁止对CComModule _Module的所有引用,并使用常规MFC代码。
另一种解决方案是让Dll成为常规的ATL DLL。
您应该使用VS2010向导向您展示这两种代码库。(创建ATL Dll后,使用"Add“菜单选项,然后选择"ATL控件”
解决方案在很大程度上取决于在剩余代码中使用MFC和/或ATL函数。
建议:使DLL完整MFC,取消"atl模块“,然后使用向现有的mfc应用程序添加ATL支持添加对ATL的支持。
https://stackoverflow.com/questions/20044040
复制相似问题