如何多次调用Com对象 [英] How I Can Calling Com Object Multiple Time

查看:125
本文介绍了如何多次调用Com对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用c#调用matlab中的函数来循环使用com组件

当我尝试它时我有这个例外



无效的被叫方。 (HRESULT异常:0x80020010(DISP_E_BADCALLEE))



这是代码

i want to call function in matlab from c# inside for loop using com component
when i tried it i had this exception

Invalid callee. (Exception from HRESULT: 0x80020010 (DISP_E_BADCALLEE))

this is the code

for (int j = 1; j < 8; j++)
            {               
                object result1;
                string name = path + j + ".JPG";
                matlab.Feval("WBC_SegProposed", 6, out result1, name, 0, j);
           ...........//code
}



此指令的例外是matlab.Feval(WBC_SegProposed,6,out result1,name,0,j);

我该怎么办?


the exception was for this instruction " matlab.Feval("WBC_SegProposed", 6, out result1, name, 0, j);"
what should i do ?

推荐答案



我很遗憾看到上面所有无益的评论,当它真的是Mathwork的时候导致此错误的执行不佳。解决方案是在for循环中简单地包含result = null:



Hi,
I'm sad to see all the unhelpful comments above when it is really Mathwork's poor implementation leading to this error. The solution is to simply include result = null in your for loop:

for (int j = 1; j < 8; j++)
            {               
                object result1 = null; // <---resetting result back to null
                string name = path + j + ".JPG";
                matlab.Feval("WBC_SegProposed", 6, out result1, name, 0, j);
           ...........//code
}





您的代码适用于第一次迭代,因为result默认设置为null。然后在第一次迭代中为它分配一个值,由于在第二次迭代中传递一个非null变量,Feval会抛出一个错误。



your code works for the first iteration because "result" is set to null by default. Then it gets assigned a value in the first iteration and Feval throws an error due to passing a non-null variable in the second iteration.


这篇关于如何多次调用Com对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆