2 qs1005650933 qs1005650933 于 2013.11.09 20:20 提问

简单的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 = %ld\n",*l);
printf("Compute over...\n");
pObject->Release();
CoUninitialize();//释放COM库
return 0;

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!