IDispatch接口调用COM接口从C#成员 [英] Calling a member of IDispatch COM interface from C#

查看:198
本文介绍了IDispatch接口调用COM接口从C#成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打电话从实现在C#中的IDispatch接口的COM对象的GetIDsOfNames功能。我已经写了下面的code,但它无法与DISP_E_UNKNOWNNAME。这是为了做到这一点,正确的做法?

I wanted to call the GetIdsOfNames function from a COM object that implements the IDispatch interface in c#. I've written the following code but it fails with the DISP_E_UNKNOWNNAME. Is this the correct approach to do this?

 Object so = Activator.CreateInstance(Type.GetTypeFromProgID("ProgID"));            
 Object[] args = new Object[5];
 string[] rgsNames = new string[1];
 rgsNames[0] = "PrintNormal";
 uint LOCALE_SYSTEM_DEFAULT = 0x0800;
 uint lcid = LOCALE_SYSTEM_DEFAULT;
 int cNames = 1;
 int[] rgDispId = new int[1];
 args[0] = IntPtr.Zero;
 args[1] = rgsNames;
 args[2] = cNames;
 args[3] = lcid;
 args[4] = rgDispId;             
 Object result = so.GetType().InvokeMember("GetIDsOfNames", BindingFlags.InvokeMethod, null, so, args);

谢谢,

理查德

推荐答案

没有你不能,因为InvokeMember内部使用的GetIDsOfNames,而这一次只检查实际的方法,而不是在IDispatch的第6。或者,换句话说,GetIDsOfNames将不能使用的IDispatch的方法Invoke调用。这就是COM是如何工作的。

No you cannot, because InvokeMember internally uses GetIDsOfNames, and this one only checks actual methods, not the first 6 in IDispatch. Or in other words, GetIDsOfNames cannot be invoked using IDispatch's method Invoke. That is how COM works.

这篇关于IDispatch接口调用COM接口从C#成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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