calling COM objects

R

ramaseshan.k

Hi

I am c# newbie coming from c++ background. I need to call a COM
object(which was written in VC++) from my c# program.

The c++ application(Let's call it abc) has an .ODL file that defines
the COM interface. It generates a tlb(abc.tlb) file. The application's
COM is registered in the registry. I then reference abc.tlb in my c#
application by going into the Add References | COM tab, and then by
browsing for the appropriate .tlb file and selecting it.

The added COM interface shows up in the object browser, and is also
recognized by the intellisense. I instantiate an object of that COM
class, and the code builds fine. When I run this code, it throws an
exception at the line where the COM object is getting instantiated. The
exception is:

An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
WindowsApplication1.exe

Additional information: COM object with CLSID
{7F9CB933-374F-4A3E-BAA3-C4E929181708} is either not valid or not
registered.

In the registry, abc.ComAuto is registered with the ID
9726830A-FAB2-4B0B-A045-2BB2700FEBED.

INterestingly, this is what the abc.odl file looks like:

// abc.odl : type library source for abc.exe

// This file will be processed by the MIDL compiler to produce the
// type library (abc.tlb).

[ uuid(E881AA79-D08A-46FD-9B99-FA66680557A0), version(1.0) ]
library abc
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");

// Primary dispatch interface for CComAuto
[ uuid(9726830A-FAB2-4B0B-A045-2BB2700FEBED) ]
dispinterface IComAuto
{
properties:
// NOTE - ClassWizard will maintain property information here.
// Use extreme caution when editing this section.
//{{AFX_ODL_PROP(CComAuto)
//}}AFX_ODL_PROP

methods:
// NOTE - ClassWizard will maintain method information here.
// Use extreme caution when editing this section.
//{{AFX_ODL_METHOD(CComAuto)
[id(1)] short Open(BSTR sPathName);
[id(2)] short Analyse();
[id(3)] short Save();
[id(4)] short SaveAs(BSTR sPathName);
...
...
...

//}}AFX_ODL_METHOD

};
// Class information for CComAuto
[ uuid(7F9CB933-374F-4A3E-BAA3-C4E929181708) ]
coclass ComAuto
{
[default] dispinterface IComAuto;
};
//{{AFX_APPEND_ODL}}
//}}AFX_APPEND_ODL}}
};

Obviously, c# is trying to refer to the other ID when it generates the
interop wrapper. I don't have any experience making any COM interfaces,
nor with COM interop, so I really dont know why this is happening.

Can anyone please help...

Thanks
Ramaseshan
 
R

ramaseshan.k

Hi
Thanks for the reply. I have already tried the same thing using the
tlbimp tool.
My suspicion is that since the COM interface is quite OLD (It uses the
deprecated .odl, instead of the new idl ), c# is having problems
getting the correct classID.
I say this because there is another inhouse application of ours, which
has a COM interface based out of an idl file, and i can import it
perfectly fine, and instantiate it without any exceptions.

Any one has more insights on odl vs idl vis-a-vis interop?

Thanks
Ramaseshan
 

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