我自己写的最简单的 COM ,为什么调试它时总出错?
我写了一个最简单的COM,只有一个函数,GetHelloGreeting,返回L"Hello World!",我另外建立一个测试的Project,只是加入下面几句话
#import "e:\ActiveX\TestHelloCom\TestHelloCom.tlb" no_namespace
try
{
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 ,怎么办?