【发布时间】:2016-04-28 04:09:07
【问题描述】:
为什么会出现这个错误?引用计数增加,线程模型是单个单元。 Coll-object 和 EmptyColl-function 都位于一个 dll 中。 ATL 工程的默认调用转换为 __stdcall。此 dll 中的其他对象也发生了同样的错误。
使用 NULL 对象清除 VARIANT 时,VariantClear 会引发异常:
在 VB6.EXE 中的 0x75C14974 (oleaut32.dll) 处引发异常:0xC0000005:
访问冲突读取位置 0x00000008。
frmMain.frm(错误,原因见下文):
Private Sub Form_Load()
Dim c As Coll
Set c = EmptyColl
'error when ends here with variable "c" in the watch window.
End Sub
frmMain.frm(无错误):
Private Sub Form_Load()
Dim c2 As Coll 'instead of Coll can be any object of same library
Set c2 = New Coll 'creation
Set c2 = Nothing 'destroying (optionaly)
Dim c As Coll
Set c = EmptyColl
'no error
End Sub
filyus.idl:
[
object,
uuid(6FA7FAEB-5CE3-4A80-9288-2667EE5E7596),
dual,
nonextensible,
pointer_default(unique)
]
interface IColl : IDispatch{
//some methods
};
[
uuid(157F3D2F-A427-4D5A-B908-87868297EA43),
version(1.0),
]
library Filyus
{
importlib("stdole2.tlb");
[
dllname("Filyus")
]
module Filyus{
[entry("EmptyColl")]
HRESULT EmptyColl([out, retval] IColl** Coll);
}
};
filyus.def:
LIBRARY
EXPORTS
DllCanUnloadNow PRIVATE
DllGetClassObject PRIVATE
DllRegisterServer PRIVATE
DllUnregisterServer PRIVATE
DllInstall PRIVATE
EmptyColl
ole.h:
extern HRESULT EmptyColl(IColl** Coll);
ole.cpp:
HRESULT EmptyColl(IColl** Coll) {
HRESULT hr; CComObject<CColl>* Object;
if (Coll != nullptr) {
hr = CComObject<CColl>::CreateInstance(&Object);
if (hr == S_OK) {
Object->AddRef();
*Coll = Object; //same error with using QueryInterface
}
}
else hr = E_POINTER;
return hr;
}
【问题讨论】:
-
"这个 dll 中的其他对象也发生了同样的错误" - 那么很明显你在你的 DLL 中做了一些根本性的错误。请提供Minimal, Complete, and Verifiable example,显示更多您的 DLL 代码。特别是它是如何声明和设置
CColl类以及您遇到问题的其他类的。