Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, monk12, TipmyPip, Quad, aliswee), 1,029 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: COM+: CoInitialize(NULL) always fails [Re: jcl] #382443
09/08/11 12:26
09/08/11 12:26
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
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'.


Nice to know! Thank you very much smile

Re: COM+: CoInitialize(NULL) always fails [Re: HeelX] #382578
09/09/11 16:56
09/09/11 16:56
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline OP
Senior Expert
HeelX  Offline OP
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Me again smile I finally made CoCreateInstance to succeed.

Well, my generated header file (I use the #import directive for .tlb type library files) contains named, pre-initialized GUIDs like these:

Code:
extern "C" const GUID __declspec(selectany) IID_iInterface =
    {0xf9f48469,0x68ab,0x3013,{0xb8,0x06,0xdd,0xa2,0x09,0x63,0xda,0xfb}};
extern "C" const GUID __declspec(selectany) CLSID_ComPlusClass =
    {0x2f307f57,0xb30a,0x3bdf,{0x83,0x15,0x95,0x26,0x6f,0x00,0x61,0x48}};


So I tried to use them in Lite-C, too, but

Code:
GUID IID_iInterface =
    {0xf9f48469,0x68ab,0x3013,{0xb8,0x06,0xdd,0xa2,0x09,0x63,0xda,0xfb}};


just throws a syntax error during compilation. Is there a way to overcome this?

Anyway, the file also contained uuid's like these lines:

Code:
struct __declspec(uuid("f9f48469-68ab-3013-b806-dda20963dafb"))
/* dual interface */ iInterface;


and I used them like this:

Code:
GUID CLSID_ComPlusClass;
IIDFromStr("{2f307f57-b30a-3bdf-8315-95266f006148}", &CLSID_ComPlusClass);
	
IID IID_iInterface;
IIDFromStr("{f9f48469-68ab-3013-b806-dda20963dafb}", &IID_iInterface);



and my structs are looking like that:

Code:
typedef struct _iInterfaceVtbl
{
	// COM object standard methods
	HRESULT __stdcall QueryInterface (void* This, IID *riid, void** ppvObject);
	DWORD __stdcall AddRef (void* This);
	DWORD __stdcall Release (void* This);

} iInterfaceVtbl;

typedef interface iInterface {iInterfaceVtbl* lpVtbl;} iInterface;



and CoCreateInstance --succeeds--! Yeah smile

Being happy, I wanted to test out, if the method calls to the classe are working. My header file tells me the following:

Code:
struct __declspec(uuid("f9f48469-68ab-3013-b806-dda20963dafb"))
iInterface : IDispatch
{
    //
    // Wrapper methods for error-handling
    //

    long SetHeartCoherence (
        long the_heart_coherence );
    long GetHeartCoherence ( );
    long SetInterbeatIntervalCircleData (
        BSTR data );
    BSTR GetInterbeatIntervalCircleData ( );
    long SetAmplitudeHartritmeVariatie (
        double data );
    double GetAmplitudeHartritmeVariatie ( );
    long SetInterbeatInterval (
        long data );
    long GetInterbeatInterval ( );
    long SetAverageHeartbeat (
        long data );
    long GetAverageHeartbeat ( );
    long SetAdemhalingsFrequentie (
        double data );
    double GetAdemhalingsFrequentie ( );
    long SetFFTArray (
        BSTR data );
    BSTR GetFFTArray ( );

    //
    // Raw methods provided by interface
    //

      virtual HRESULT __stdcall raw_SetHeartCoherence (
        /*[in]*/ long the_heart_coherence,
        /*[out,retval]*/ long * pRetVal ) = 0;
      virtual HRESULT __stdcall raw_GetHeartCoherence (
        /*[out,retval]*/ long * pRetVal ) = 0;
      virtual HRESULT __stdcall raw_SetInterbeatIntervalCircleData (
        /*[in]*/ BSTR data,
        /*[out,retval]*/ long * pRetVal ) = 0;
      virtual HRESULT __stdcall raw_GetInterbeatIntervalCircleData (
        /*[out,retval]*/ BSTR * pRetVal ) = 0;
      virtual HRESULT __stdcall raw_SetAmplitudeHartritmeVariatie (
        /*[in]*/ double data,
        /*[out,retval]*/ long * pRetVal ) = 0;
      virtual HRESULT __stdcall raw_GetAmplitudeHartritmeVariatie (
        /*[out,retval]*/ double * pRetVal ) = 0;
      virtual HRESULT __stdcall raw_SetInterbeatInterval (
        /*[in]*/ long data,
        /*[out,retval]*/ long * pRetVal ) = 0;
      virtual HRESULT __stdcall raw_GetInterbeatInterval (
        /*[out,retval]*/ long * pRetVal ) = 0;
      virtual HRESULT __stdcall raw_SetAverageHeartbeat (
        /*[in]*/ long data,
        /*[out,retval]*/ long * pRetVal ) = 0;
      virtual HRESULT __stdcall raw_GetAverageHeartbeat (
        /*[out,retval]*/ long * pRetVal ) = 0;
      virtual HRESULT __stdcall raw_SetAdemhalingsFrequentie (
        /*[in]*/ double data,
        /*[out,retval]*/ long * pRetVal ) = 0;
      virtual HRESULT __stdcall raw_GetAdemhalingsFrequentie (
        /*[out,retval]*/ double * pRetVal ) = 0;
      virtual HRESULT __stdcall raw_SetFFTArray (
        /*[in]*/ BSTR data,
        /*[out,retval]*/ long * pRetVal ) = 0;
      virtual HRESULT __stdcall raw_GetFFTArray (
        /*[out,retval]*/ BSTR * pRetVal ) = 0;
};



and I wanted to call the method, which is working in my C++ console application, which is looking like this::

Code:
if (hr == S_OK)
	{
		int m_hr = pComInterface->GetHeartCoherence();
		sprintf (stringbuffer, "%d ", m_hr);
		printf ("HeartCoherence result: [%s]", stringbuffer);
	}


So I took it simple and added the "getHeartCoherence" method to the Lite-C _iInterfaceVtbl struct as follows:

Code:
typedef struct _iInterfaceVtbl
{
	// COM object standard methods
	HRESULT __stdcall QueryInterface (void* This, IID *riid, void** ppvObject);
	DWORD __stdcall AddRef (void* This);
	DWORD __stdcall Release (void* This);
	
	// specific methods
	long __stdcall GetHeartCoherence (void* This);
	
} iInterfaceVtbl;


Now, if CoCreateInstance is OK, I just execute

Code:
long hc = pComInterface->GetHeartCoherence();
printf("HeartCoherence result: [%d]", (int)hc);



As soon as a I call the method, the engine simply -!!-crashes-!!-. Now I am not happy anymore wink

So, here are my summarized questions:

1) How do I use the above listed preinitialized GUIDs?
2) What have I forgotten?
3) What could be the reason for the crash?

Last edited by HeelX; 09/09/11 16:58.
Re: COM+: CoInitialize(NULL) always fails [Re: HeelX] #382615
09/10/11 09:37
09/10/11 09:37
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Looks as if the function parameter is missing in your GetHeartCoherence declaration?

Re: COM+: CoInitialize(NULL) always fails [Re: Tobias] #382618
09/10/11 10:07
09/10/11 10:07
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline OP
Senior Expert
HeelX  Offline OP
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Which one?

The declaration is in the vtable struct:
Code:
long __stdcall GetHeartCoherence (void* This);



The This pointer is added because the manual says:
Quote:
Note that each of the methods has an additional parameter called "This". You have to pass the This pointer parameter explicitly in C, but it can be passed automatically in lite-C. Any additional parameters come after This, as above.


So I guess when I call a method with a void parameter, I just call and declare it like I do in the above post...?

Re: COM+: CoInitialize(NULL) always fails [Re: HeelX] #382619
09/10/11 10:20
09/10/11 10:20
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Yes, I looked at the wrong function, SetHeartCoherence that needs a long parameter. I had a similar job last year and found no problem with COM interfacing, so I don't know why it crashes, but you can see an example for a COM interface in pictures.h.

Another idea, the virtual functions in your header look as if those functions must be defined before calling the method, maybe the method crashes when its virtual function is not defined.

Or one little thing, in your typedef the interface name and type name are the same (iInterface), in the examples they are different, maybe that's also causing a problem.

Re: COM+: CoInitialize(NULL) always fails [Re: Tobias] #382628
09/10/11 12:39
09/10/11 12:39
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline OP
Senior Expert
HeelX  Offline OP
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
I added all methods and then I looked into picture.h and there wasn't
Code:
// COM object standard methods
HRESULT __stdcall QueryInterface (void* This, IID *riid, void** ppvObject);
DWORD __stdcall AddRef (void* This);
DWORD __stdcall Release (void* This);



as opposed to what is stated in the manual.. hmmm. After I removed that in my code, the engine didn't crashed anymore. Though, I get a wrong return value for my function - but that could be related to the DLL.

Nevertheless, that DLL uses a BSTR, has anyone successfully send and received a BSTR from a VB6 DLL? I made this typedef chain, I am not sure if this is correct, but it compiles very well:

Code:
// typedef chain for BSTR
typedef unsigned short wchar_t;
typedef wchar_t WCHAR;
typedef WCHAR OLECHAR;
typedef OLECHAR* BSTR;
typedef BSTR* LPBSTR;



@Tobias: do you know how I can use the above posted preinitialized GUIDs?

Last edited by HeelX; 09/10/11 12:39.
Re: COM+: CoInitialize(NULL) always fails [Re: HeelX] #382679
09/11/11 08:19
09/11/11 08:19
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Hmm, I had the standard methods also defined in my struct and it worked. Dunno why it crashes for you. In the d3d9.h header there are lots of those interfaces and they all have the standard methods included. I needed them also because I call Release().

You use the preinitialized GUID for the first parameter when you call CoCreateInstance.

I have not yet had a BSTR but believe it is not a char* but a struct similar to CString. In that case your typedef chain would not work.

Re: COM+: CoInitialize(NULL) always fails [Re: Tobias] #382681
09/11/11 09:16
09/11/11 09:16
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: Tobias
You use the preinitialized GUID for the first parameter when you call CoCreateInstance.


I wrote that
Code:
GUID IID_iInterface =
    {0xf9f48469,0x68ab,0x3013,{0xb8,0x06,0xdd,0xa2,0x09,0x63,0xda,0xfb}};



doesn't compile for me. Try yourself!

Re: COM+: CoInitialize(NULL) always fails [Re: HeelX] #382707
09/11/11 16:04
09/11/11 16:04
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
BSTR stores the string length in some bytes before the string. Use SysAllocString and SysFreeString for conversion.

Re: COM+: CoInitialize(NULL) always fails [Re: Joey] #382746
09/12/11 12:56
09/12/11 12:56
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
HeelX: This line won't even compile - lists are only possible for array definitions. Look in the manual DLL interface chapter for the correct syntax to define a GUID. You had it already right in your previous example. You can also find an example in the pictures.h header as Tobias suggested, and use that as a template.

A GUID is a 16-byte sequence that you use for uniquely identifying a COM interface. You use it for example when you create an instance of that interface.

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