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 2 1834
Check out http://msdn2.microsoft.com/en-us/library/tt0cf3sx.aspx
and use tlbimp framework tool.
"ra**********@gmail.com" wrote: 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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Midas |
last post by:
In my "main" code, I would like to create two
new objects (ObjectA and ObjectB) and have
ObjectA directly call an ObjectB method. In
order to do this I believe ObjectA must hold
a reference to...
|
by: Matthew Bell |
last post by:
Hi,
I've got a question about whether there are any issues with directly
calling attributes and/or methods of a threaded class instance. I
wonder if someone could give me some advice on this.
...
|
by: Tim Marshall |
last post by:
Here's the scenario, A2003, Jet back end, illustrated with some cut down
code at the end of the post:
A proc dims a snapshot recordset (dim rst as Dao.recordset) and opens
it. There are several...
|
by: Gibby Koldenhof |
last post by:
Hiya,
I'm setting up some code in the spirit of Design Patterns, OOP, etc. All
nice and well, it handles pretty much all OO style things and serves my
purposes well. There's one last final...
|
by: Ross A. Finlayson |
last post by:
Hi,
I hope you can help me understand the varargs facility.
Say I am programming in ISO C including stdarg.h and I declare a
function as so:
void log_printf(const char* logfilename, const...
|
by: Dave |
last post by:
does calling a regular function cost any cpu time? In other words, is it
faster to write the code of two functions into main(), or is it the exact
same thing as calling two functions. I know its...
|
by: Max Yuzhakov |
last post by:
Hello!
It is correct behaviour for python to call __del__ on some
identity of a class object more than once?
In brief I shall describe a situation. Sorry for my english.
For debugin...
|
by: Edwin Gomez |
last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
|
by: Jeremy Chaney |
last post by:
I have an application written in C# that uses objects written in a
managed C++ DLL. When I exit my app, my C# classes have their
destructors called, but the MC++ objects that those classes hold...
|
by: bizt |
last post by:
Hi,
Below I have a simple object / function thing (still getting head
round these) declaration:
function MyObject() {
this.alertMe = function() {
alert('hello');
};
this.alertMeAgain() {
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |