Hi All,
A quick question for you regarding late binding in C#. I believe I'm very close to getting this to work but not quite there yet. Basically I'm trying to recreate some VB6 code in C#. Here's the VB6 code:
Dim myInterface as (my COM Interface)
Dim myInt as Integer
Set myInterface = CreateObject("MyCurrentlyRunningExecutable"
myInt = myInterface.myMethod(0)
This works just fine.
However C# does not seem to implement Late Binding in the same fashion. I believe I have all the steps down now to reacreate this process, but there is something nitpicky that is wrong, and my suspicion is that it's because I'm trying to use an interface rather than a class. Here's my current code:
Type myType;
object myObject;
object result;
myType = Type.GetTypeFromProgID("MyCurrentlyRunningExecutable"
myObject = Activator.CreateInstance(myType);
result = myType.InvokeMember("myMethod", BindingFlags.Public | BindingFlags.InvokeMethod, null, myObject, new object [] {});
The error I get is "An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Unknown name."
Which isn't very descriptive =)
Any thoughts/suggestions/comments? Am I even close, cause I'm having serious trouble finding anything like this on the net.
Cheers,
SlantyOD
A quick question for you regarding late binding in C#. I believe I'm very close to getting this to work but not quite there yet. Basically I'm trying to recreate some VB6 code in C#. Here's the VB6 code:
Dim myInterface as (my COM Interface)
Dim myInt as Integer
Set myInterface = CreateObject("MyCurrentlyRunningExecutable"
myInt = myInterface.myMethod(0)
This works just fine.
However C# does not seem to implement Late Binding in the same fashion. I believe I have all the steps down now to reacreate this process, but there is something nitpicky that is wrong, and my suspicion is that it's because I'm trying to use an interface rather than a class. Here's my current code:
Type myType;
object myObject;
object result;
myType = Type.GetTypeFromProgID("MyCurrentlyRunningExecutable"
myObject = Activator.CreateInstance(myType);
result = myType.InvokeMember("myMethod", BindingFlags.Public | BindingFlags.InvokeMethod, null, myObject, new object [] {});
The error I get is "An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Unknown name."
Which isn't very descriptive =)
Any thoughts/suggestions/comments? Am I even close, cause I'm having serious trouble finding anything like this on the net.
Cheers,
SlantyOD