|
COM+: CoInitialize(NULL) always fails
#382275
09/06/11 19:09
09/06/11 19:09
|
Joined: Jul 2001
Posts: 6,904
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
Hi, my client passed me a COM+ DLL, written in VB6, which now works in a standard MS VS2005 console application (click image to enlarge): Now, in Lite-C I just want to do the same. I read through all pages in the manual regarding COM and also digged the forum. It seems that only a few tried that. My options are either writing the COM connection in Lite-C (preferred) or writing a wrapper DLL in C++/VS2005 (will work for sure, but I really don't want to do that). Now, if I run CoInitialize, it already fails, it says: "CoInitialize Failed: 1"...:
#include <acknex.h>
#include <default.c>
#include <com.h>
int main ()
{
// open the COM interface
HRESULT hr = CoInitialize(NULL);
if (hr != S_OK)
{
printf("CoInitialize Failed: %x\n\n", hr);
return 0;
}
else
printf("CoInitialize succeeded\n");
}
So, what is going on? I don't know, since CoInitialize does not fail in my C++ app, but in Lite-C...?
Last edited by HeelX; 09/07/11 20:55.
|
|
|
Re: COM+: CoInitialize(NULL) already fails
[Re: HeelX]
#382305
09/07/11 00:24
09/07/11 00:24
|
Joined: Aug 2002
Posts: 164 Houston
Nicholas
Member
|
Member
Joined: Aug 2002
Posts: 164
Houston
|
I'm guessing you're trying to connect to an external device through a com port. if not, ignore this :-p I am trying to do the same thing and am having a lot of luck using the code that EvilSOB came up with. here's the link http://www.opserver.de/ubb7/ubbthreads.p...true#Post280484I got someone to write me a c++ dll for it a few years ago, but never got the flexibility I needed from it. good luck
Last edited by Nicholas; 09/07/11 00:25.
Black holes are where God divided by zero.
|
|
|
Re: COM+: CoInitialize(NULL) already fails
[Re: Nicholas]
#382318
09/07/11 07:25
09/07/11 07:25
|
Joined: Jul 2001
Posts: 6,904
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
Hi Nicholas, hmn, in the end it will connect indeed to an external device, but in my case I need to connect to a DLL, which is accessible via COM. The DLL has been written in VB6 and this is the only way to connect to it from a C++ app. If I get not any further with this these days I will write a wrapper DLL.
I am just a bit curious because even the initialization function fails, but in my console application not.
P.S: Happy birthday!
Last edited by HeelX; 09/07/11 07:26.
|
|
|
Re: COM+: CoInitialize(NULL) always fails
[Re: HeelX]
#382396
09/07/11 20:47
09/07/11 20:47
|
Joined: Jul 2001
Posts: 6,904
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
Hm, no one? If I get it not to work until Sunday evening, I will have to write a wrapper DLL...
Last edited by HeelX; 09/07/11 20:55.
|
|
|
Re: COM+: CoInitialize(NULL) always fails
[Re: Myrkling]
#382408
09/07/11 22:55
09/07/11 22:55
|
Joined: Jul 2001
Posts: 6,904
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
It seems to work when CoUninitialize() is called before CoInitialize(). [...] Perhaps COM gets initialized automatically by lite-C? Indeed! When I execute CoUninitialize(); before CoInitialize(NULL); it seems to succeed. Weird!! OK, I will now try to access the DLL functions. In the meantime it would be cool if JCL or alike could tell us / me, why I have to uninitialize it before I initialized it? I thought that CoInitialize has to be called only once on a thread, so it seems that this has been done already by Lite-C. I have the feeling that the "NETPORT I/O modules over the network" feature could be related to it... Hmmm. At least, it is suspicious
|
|
|
Re: COM+: CoInitialize(NULL) always fails
[Re: Myrkling]
#382410
09/07/11 22:57
09/07/11 22:57
|
Joined: Jul 2008
Posts: 894
TechMuc
User
|
User
Joined: Jul 2008
Posts: 894
|
http://msdn.microsoft.com/en-us/library/ms680582(v=vs.85).aspx Implement this to get the last error description PS: though probably the solution of my preposter is correct...
|
|
|
Re: COM+: CoInitialize(NULL) always fails
[Re: jcl]
#382432
09/08/11 10:40
09/08/11 10:40
|
Joined: Jul 2001
Posts: 6,904
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
You need neither to uninitilize nor initialize it. COM is already initialized on the engine thread. Didn't know that. Where is this written in the manual? Because the only COM example in the manual uses actually CoInitialize. Thanks!
Last edited by HeelX; 09/08/11 10:40.
|
|
|
|