MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [求助]matlab与Vc++混合编程,我的程序为什么不能创建COM组建的对象的呀? (https://www.labfans.com/bbs/showthread.php?t=6381)

shaoliangw 2009-02-11 16:04

[求助]matlab与Vc++混合编程,我的程序为什么不能创建COM组建的对象的呀?
 
我按照网上的例子,请详见[URL="http://www.edacn.net/html/76/27076-2398.html"]例子[/URL]
[url=http://www.edacn.net/html/76/27076-2398.html]dz��VC��Matlab���ϱ��<��> - Jiang_online - EDA�й��Ż���վ - Powered by X-Space[/url]
我是一步一步按照例子上做下来的
我用的matlab版本是6.5的,vc++6.0

在最后程序代码中我加了一下代码以方便调试

if(FAILED(CoInitialize(NULL)))
{
AfxMessageBox("unable to initialize COM");
return;
}
else AfxMessageBox("COM is initialized");


HRESULT hr=S_OK;
CLSID CLSID_huatu;
hr = CLSIDFromProgID(OLESTR("component.huatu.1_0"), &CLSID_huatu);
if(FAILED(hr))
{
AfxMessageBox("转换失败!");
return;
}
else AfxMessageBox("转换成功!");

Ihuatu *pImyclass=NULL;
hr = CoCreateInstance(CLSID_huatu, NULL, CLSCTX_ALL, IID_Ihuatu,(void **)&pImyclass);
if(pImyclass==NULL)
{
AfxMessageBox("pImyclass is NULL!");
}
if(FAILED(hr))
{
AfxMessageBox("create instance failed!");
return;
}
else AfxMessageBox("create instance succeeded!");

hr=pImyclass->huatu();
CoUninitialize();

我的程序运行的结果是:
COM能够正常初始化,也能把ProgID正常转换为CLSID;
但是,pImyclass为NULL,COM组件的对象创建失败。

请各位大侠赐教啊。
我的QQ:183915960,如有那位大侠知道我哪里出错,请留言或者跟我联系,谢谢!!!

未注册 2009-02-23 11:05

回复: [求助]matlab与Vc++混合编程,我的程序为什么不能创建COM组建的对象的呀?
 
问题已解决,感谢广大网友的支持


所有时间均为北京时间。现在的时间是 14:02

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.