Convert some VB code to C#
-
Hello, I'm converting some VBS scripts to C# and one of them uses the following lines of code Set MyDCOM = CreateObject("NODMON.NODCLS") retval = MyDCOM.addmsg("", "", 1, Now, 0, 3000, Message) Could someone point me in the right direction for how I should go about converting this? It's mainly the CreateObject statement I'm unsure of!. Thanks
-
Hello, I'm converting some VBS scripts to C# and one of them uses the following lines of code Set MyDCOM = CreateObject("NODMON.NODCLS") retval = MyDCOM.addmsg("", "", 1, Now, 0, 3000, Message) Could someone point me in the right direction for how I should go about converting this? It's mainly the CreateObject statement I'm unsure of!. Thanks
Gareth_Hastings wrote: Set MyDCOM = CreateObject("NODMON.NODCLS") retval = MyDCOM.addmsg("", "", 1, Now, 0, 3000, Message) What you are doing here is late binding in VB. While C# does support late-bound object creation (i.e.; look at
Activator.CreateInstance
), there are several ways to access what you are doing. One is to generate the appropriate interop assemblies (for example if you are using Visual Studio .NET you can simply use the Add Reference -> COM tab), this will allow you to declare the object and take advantage of early-binding at compile-time or you could use reflection to generate the object at run-time (theActivator
class). - Nick Parker
My Blog | My Articles