I am trying to use the functionality of new ActiveXObject()
found in JScript.NET in C#. How can I do this?
And don't say that anything you can do with COM objects can be done in C#. If I wanted to do it that way, I already would have.
You can create instances of COM objects using
Activator.CreateInstance(Type.GetTypeFromProgID(ProgID))
and then work with them using late binding. For example:
using System.Reflection;
...
Type wshType = Type.GetTypeFromProgID("WScript.Shell");
object wshShell = Activator.CreateInstance(wshType);
wshType.InvokeMember("Popup", BindingFlags.InvokeMethod, null, wshShell, new object[] {"Hello, world!"});
or, using C# 4's dynamic
keyword:
// NB: Add reference to Microsoft.CSharp.dll
dynamic wshShell = Activator.CreateInstance(Type.GetTypeFromProgID("WScript.Shell"));
wshShell.Popup("Hello, world!");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With