How to use a COM-Wrapper?

0

Question:

I have to work (in VB.NET) with an application (Aperture)'s OLE automation via COM-Wrapper.

Currently, I switch off option strict, and do it like this (using late-binding):

Dim m_Aperture As Object = CreateObject("Aperture.Application")
Dim m_Project As Object = m_Aperture.Project

You see the problem, everything is an object, no intellisense, etc.
Very bad.

Since I want to get intellisense and and compile-time checking to work, I tried to automatically create a COM-wrapper like this:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\TlbImp.exe" OEAPP.TLB /out:Aperture.dll

So far worked splendidly, it created the wrapper, I can use intellisense on it (return types are all of type dynamic though).

enter image description here

So I tried to rewrite just the above sample code (now in C#):

First attempt was:

Aperture.OEAppClass app = new Aperture.OEAppClass();

But I got this compiler error:

Interop-Type Aperture.OEAppClass cannot be embedded. Use interface instead.

So i tried to do it via interface:

Aperture.OEApp Ap = (Aperture.OEApp)Microsoft.VisualBasic.Interaction.CreateObject("Aperture.Application");

That got me an exception at runtime

InvalidCastException
"System.__ComObject" cannot be converted into interface type "Aperture.OEApp".
0x80010105 (RPC_E_SERVERFAULT)).

So I tried to figure out the interface type using

dynamic Ap2 = Microsoft.VisualBasic.Interaction.CreateObject("Aperture.Application");

and object-inspector.

I found out the interface is actually of type Aperture._IOEApp. So I used

Aperture._IOEApp Ap = (Aperture._IOEApp)Microsoft.VisualBasic.Interaction.CreateObject("Aperture.Application");

But now I get

InvalidCastException
"System.__ComObject" cannot be converted into interface type "Aperture._IOEApp".
0x80010105 (RPC_E_SERVERFAULT)).

Now I don't know what the problem could be anymore.

Can anybody tell me what I do wrong ?
Or how this is supposed to work ?

c#
vb.net
com
com-interop
asked on Stack Overflow Jun 7, 2013 by Stefan Steiger • edited Jun 9, 2013 by Stefan Steiger

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0