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
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