Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by M_D. 04/26/24 20:22
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 818 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
COM+: CoInitialize(NULL) always fails #382275
09/06/11 19:09
09/06/11 19:09
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline OP
Senior Expert
HeelX  Offline OP
Senior Expert
H

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"...:

Code:
#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 Offline
Member
Nicholas  Offline
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#Post280484

I 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
H
HeelX Offline OP
Senior Expert
HeelX  Offline OP
Senior Expert
H

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
H
HeelX Offline OP
Senior Expert
HeelX  Offline OP
Senior Expert
H

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

Last edited by HeelX; 09/07/11 20:55.
Re: COM+: CoInitialize(NULL) always fails [Re: HeelX] #382401
09/07/11 21:48
09/07/11 21:48
Joined: Feb 2011
Posts: 135
Myrkling Offline
Member
Myrkling  Offline
Member

Joined: Feb 2011
Posts: 135
Isn't S_FALSE (==1) returned if COM is already initialized?

It seems to work when CoUninitialize() is called before CoInitialize(). At least the "CoInitialize succeeded" message is shown then.
Perhaps COM gets initialized automatically by lite-C?

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
H
HeelX Offline OP
Senior Expert
HeelX  Offline OP
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Originally Posted By: Myrkling
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 grin

Re: COM+: CoInitialize(NULL) always fails [Re: Myrkling] #382410
09/07/11 22:57
09/07/11 22:57
Joined: Jul 2008
Posts: 894
T
TechMuc Offline
User
TechMuc  Offline
User
T

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 laugh
PS: though probably the solution of my preposter is correct...

Re: COM+: CoInitialize(NULL) always fails [Re: TechMuc] #382423
09/08/11 08:14
09/08/11 08:14
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
You need neither to uninitilize nor initialize it. COM is already initialized on the engine thread.

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
H
HeelX Offline OP
Senior Expert
HeelX  Offline OP
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Originally Posted By: jcl
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.
Re: COM+: CoInitialize(NULL) always fails [Re: HeelX] #382433
09/08/11 10:43
09/08/11 10:43
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
This info will be added to the manual. But the example in the manual is correct; engine programs are not the same as Windows programs, called 'legacy mode'.

Page 1 of 3 1 2 3

Moderated by  old_bill, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1