0
我意外地收到一個工作對象的錯誤424。錯誤424與C + + ATL OleAutomation
我有一些使用ATL在C++中編寫的OleAutomation類。
我可以通過早期或晚期綁定實例化它們。 我可以調用它們的方法和屬性並獲得預期的結果。
但是,如果我測試它們是否爲空,我會收到錯誤424。
對這個問題有什麼建議嗎?
Excel中VBA代碼觸發錯誤:
Sub ObjectTest()
Dim o As About
Set o = New About
' this works - prints 1.4
Debug.Print "Version ", o.Version
' generates Error 424
Debug.Print "About ", o Is Null
End Sub
的IDL
[
object,
oleautomation,
uuid(...),
dual,
nonextensible,
pointer_default(unique),
public
]
interface IAbout : IDispatch
{
...
[propget, id(3), helpstring("Library version string")]
HRESULT Version([out, retval] BSTR* pResult);
...
};
[
uuid(...)
]
coclass About
{
[default] interface IAbout;
};
登記
HKCR
{
MyLibrary.About.1 = s 'About MyLibrary'
{
CLSID = s '{...}'
}
MyLibrary.About = s 'About MyLibrary'
{
CLSID = s '{...}'
CurVer = s 'MyLibrary.About.1'
}
NoRemove CLSID
{
ForceRemove {...} = s 'Class About'
{
ProgID = s 'MyLibrary.About.1'
VersionIndependentProgID = s 'MyLibrary.About'
ForceRemove Programmable
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Apartment'
}
TypeLib = s '{...}'
Version = s '1.0'
}
}
}
和類
class ATL_NO_VTABLE CAbout :
public ATL::CComObjectRootEx<ATL::CComSingleThreadModel>,
public ATL::CComCoClass<CAbout, &CLSID_About>,
public ATL::ISupportErrorInfoImpl<&CLSID_About>,
public ATL::IDispatchImpl<IAbout, &IID_IAbout, &LIBID_MyLibrary, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
CAbout()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_ABOUT)
DECLARE_NOT_AGGREGATABLE(CAbout)
BEGIN_COM_MAP(CAbout)
COM_INTERFACE_ENTRY(IAbout)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
public:
...
STDMETHOD(get_Version)(/* [out, retval] */ BSTR* pResult);
...
};
OBJECT_ENTRY_AUTO(__uuidof(About), CAbout)
它爲什麼會產生測試錯誤424的任何幫助「爲空」?
[錯誤檢查NULL在VBScript中]可能的重複(http://stackoverflow.com/questions/14507526/error-checking-for-null-in-vbscript) –
這只是壞的語法,空不是與Nothing相同的東西。將'Option Strict On'放在源代碼文件的頂部。 –
我喜歡你期望得到一個錯誤代碼,如果它的工作! –