System.__ComObject problem

  • Thread starter Axel Strube-Zettler
  • Start date
A

Axel Strube-Zettler

I'm stuck now for a whole afternoon with a little Interop problem:

static object m_ovl = m_app.GetInterfaceObject("VL.Application.nn");

(m_app.GetInterfaceObject() returns the in-process VL Application)

m_ovl is a System.__ComObject, and I can't find a way to cast or cenvert
it to
the correct datatype.

In the ObjectBrowser I can find these two types:

public abstract interface VlApplication : VLLib.DVlApplication,
VLLib._DVlApplicationEvents_Event
public class VlApplicationClass : System Object

When I have a look at VL.tlb with OLE/COM Object Viewer, there are only
Dispinterfaces and CoClasses.

I have read a lot of ng postings and documention today, but nothing works:

if((m_ovl as VlApplication) != null){
...
}else if((m_ovl as VlApplicationClass) != null){
...
}else if((m_ovl as DVlApplication) != null){
...
}else{
That's where I always end up!
}

I've tried this too:

VlApplication m_vl = (VlApplication)Marshal.CreateWrapperOfType(m_ovl,
typeof(VlApplication));

=> Exception: the source object cannot be converted to target type
because it does not support all necessary interfaces
(I hope this translation of the error message is correct)

Since all that stuff is very new to me, I have no more idea how to continue.

Thanks for any ideas!

Axel
 
A

Ankur

How is type checking taking place in your project. I mean have you added any
reference to the component you are using in your project.

Ankur
 
S

Scott Allen

Hi Axel,

Take a look at the Marshal class in System.Runtime.InteropServices.

Marshal.CreateWrapperOfType(m_ovl, typeof(VlApplicationClass)) might
do the trick for you.
 
A

Axel Strube-Zettler

Thanks for the answers, but:

(MyComObject as VLApplicationClass) - I couldn't even compile that, if I
hadn't included a reference to the appropriate .tlb

Marshal.CreateWrapperOfType() was my first guess - I mentioned that it
does not work.

In the meantime I got a hint in the german C# group:

My.ComObject.GetType().InvokeMember(...) does the Job - but it blows up
code to an ugly monster, because I have to this again and again when
diving into hierarchy. It's like working on ASSEMBLER level;-)

Obviously the problem is that the .tlb only contains dispinterfaces and
coclasses but no interfaces. But I have surely NOT the experience to
know what that really *means*. It will take me weeks to understand...

Thanks, Axel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top