问题描述
- 简单的com组件调用,用类厂的方式,调试到ix->ifun()内存报错。。
-
#include
#include "ComExp1.h"
#include "ComExp1_i.c"int main(int argc, char* argv[])
{
IUnknown *pUnk=NULL;
ICompute *pObject;
//ICompute * pICompute; //定义一个ICompute 的接口指针;
HRESULT hResult;//初始化COM库 if (CoInitialize(NULL) != S_OK) { printf("Initialize COM library failed!n"); return -1; } GUID comExp1CLSID; //定义一个GUID对象--clsID // 通过调用::CLSIDFromProgID将GUID转换成CLSID; hResult=::CLSIDFromProgID(L"ComExp1.Compute",&comExp1CLSID); if(hResult != S_OK) { printf("Can't find the ComExp1 CLSID!n"); return -2; }
// IClassFactory classFactory;
hResult = CoGetClassObject(comExp1CLSID,CLSCTX_INPROC_SERVER,NULL,
IID_IUnknown,(void *)&pUnk);
if(FALSE(hResult))
{
printf("error!n");
}
pUnk->QueryInterface(IID_ICompute,(void**)&pObject);
pUnk->Release();
long k;
long *l=&k;
printf("ok!n");
pObject->Add(6,2,l);//调试到这里内存报错。。编译是没错的
printf("6 + 2 = %ldn",*l);
printf("Compute over...n");
pObject->Release();
CoUninitialize();//释放COM库
return 0;}
时间: 2025-01-27 06:11:40