我是COM的新手。我在为自己的软件创建插件时遇到麻烦,该插件会通过clsid拦截第三方软件上的流量:
第三方所有者提供的所有信息->
* clsid:0BBB797E-D6A8-40F9-B5D1-8E72F4729A03
*接收数据的事件-OnRecvData(NetworkData)//字符串的NetworkData类型
*发送数据的事件-OnSendData(NetworkData)//字符串的NetworkData类型
我已经引用了Invoke method using Reflection on COM Object,并试图获取所创建实例所包含的方法,事件和属性。
这是我使用的代码->
class Program
{
private const string WORD_CLSID = "{0BBB797E-D6A8-40F9-B5D1-8E72F4729A03}";
public static void Main()
{
try
{
Type comType = Type.GetTypeFromCLSID(new Guid(WORD_CLSID));
var instance = Activator.CreateInstance(comType);
Console.WriteLine("//////////////////");
Console.WriteLine("Created an instance of: " + comType.Name + "-->\nCLSID = " + WORD_CLSID);
var invokedData = comType.InvokeMember("NetworkData",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.InvokeMethod, null, instance, null);
Console.WriteLine("NetworkData ->" + invokedData);
Console.WriteLine("\nEVENTS ----");
var comEvents = comType.GetEvents();
foreach (var comEvent in comEvents)
Console.WriteLine(comEvent);
if (comEvents.Count() == 0)
Console.WriteLine("0");
var comMethods = comType.GetMethods();
Console.WriteLine("\nMETHODS --");
foreach (var comMethod in comMethods)
{
var methodDetails = string.Format("{0} {1}({2})", comMethod.ReturnParameter, comMethod.Name,
string.Join(",", comMethod.GetParameters().Select(p => p.ParameterType.Name)));
Console.WriteLine("\t" + methodDetails);
}
var comProperties = instance.GetType().GetProperties();
Console.WriteLine("\nPROPERTIES----");
foreach (var comProperty in comProperties)
Console.WriteLine(comProperty);
if (comProperties.Count() == 0)
Console.WriteLine(0);
Console.WriteLine("\n--------------------------OVER");
}
catch (COMException ex)
{
Console.WriteLine("Unable to instantiate object. MESSAGE: " + ex.Message);
}
Console.Read();
}
}
,我收到以下类型的错误: HRESULT 0x80020006未知名称。
如何解决此类问题?