开发者

Manual way to call COM object through .NET

Is there a manual way to call a COM object i开发者_运维技巧n the GAC in .NET, without adding it as a reference?

The reason I ask is I only know how to code in C# and want to call a .NET COM object and tests that its CMO calls are visible, but obviously you can't add a .NET COM object to a .NET assembly! As you have to reference it, so I was wondering can you call it if its registered in the GAC manually through c# code?


Type myType = Type.GetTypeFromProgID("IMyLib.MyClass");
object obj = Activator.CreateInstance(myType);
object[] args = new object[2];
args[0] = "Hello";
args[1] = 3;
myType.InvokeMember("MyMethod", BindingFlags.InvokeMethod, obj, args);

In .Net 4 something like this

Type myType = Type.GetTypeFromProgID("IMyLib.MyClass");
dynamic obj = Activator.CreateInstance(myType);
obj.MyMethod("Hello", 3);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜