I'm dealing with a legacy program which exposes a Com API through which I need to do some automation using .Net. I understand how to generate the interop classes. The issue here is that the COM IDL does NOT define a CoClass for the main application object, just an interface. (When using VB6 CreateObject, the application is instantiated by using a local server process, not in process?) Therefore, there is no ApplicationClass on which to call New. (It's not generated by tlbimp because there is no coclass) I can successfully get a reference to a running instance of the program using the Marshal.GetActiveObject() method and cast it to the Application interface.
I can also do the following to create an instance of the object
"ProgID" refers to specific progid)
Dim typ as Type = Type.GetTypeFromProgID("ProgID"
Dim app as Object = Activator.CreateInstance(typ)
Then I can use reflection all day to manipulate the api. But, if anywhere in the code I cast an object to an interface, i.e.
Dim appInterface as Application = Ctype(app, Application)
I get a com exception ("Can not create an instance of an interface"
on the CreateInstance call. Mind you, this exception happens BEFORE the actual cast is made in the code. If I remove the cast, no error.
I am OBVIOUSLY missing something concerning Com interop here. Can anyone steer me in the right direction?
Thanks in advance!
B.J.
I can also do the following to create an instance of the object
Dim typ as Type = Type.GetTypeFromProgID("ProgID"
Dim app as Object = Activator.CreateInstance(typ)
Then I can use reflection all day to manipulate the api. But, if anywhere in the code I cast an object to an interface, i.e.
Dim appInterface as Application = Ctype(app, Application)
I get a com exception ("Can not create an instance of an interface"
I am OBVIOUSLY missing something concerning Com interop here. Can anyone steer me in the right direction?
Thanks in advance!
B.J.