简单的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;

}

查看全部
qs1005650933
qs1005650933
2013/11/09 12:20
  • com组件
  • 内存报错
  • 类厂
  • 调用函数
  • 点赞
  • 收藏
  • 回答
    私信

0个回复