我写了一个最简单的COM,只有一个函数,GetHelloGreeting,返回L"Hello World!",我另外建立一个测试的Project,只是加入下面几句话
#import "e:\ActiveX\TestHelloCom\TestHelloCom.tlb" no_namespacetry
{
IHelloPtr p;
p.CreateInstance(__uuidof(IHello));
CString str;
str = (LPCTSTR)(p->GetHelloGreeting());
AfxMessageBox(str);
}
catch(_com_error& error)
{
AfxMessageBox(error.Description());
AfxMessageBox(error.ErrorMessage());
}
结果 p 在 CreateInstance 之后仍然为 NULL ,怎么办?
#import "e:\ActiveX\TestHelloCom\TestHelloCom.tlb" no_namespacetry
{
IHelloPtr p;
p.CreateInstance(__uuidof(IHello));
CString str;
str = (LPCTSTR)(p->GetHelloGreeting());
AfxMessageBox(str);
}
catch(_com_error& error)
{
AfxMessageBox(error.Description());
AfxMessageBox(error.ErrorMessage());
}
结果 p 在 CreateInstance 之后仍然为 NULL ,怎么办?
HRESULT CoInitialize(
LPVOID pvReserved //Reserved; must be NULL
);::CoInitialize(NULL);
再次,把__uuidof()中的参数改为coclass的名称试试。
再次,我把__uuidof()中的参数改为coclass的名称试了试结果还是如故,我也搞不懂了