Me again
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:
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
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:
struct __declspec(uuid("f9f48469-68ab-3013-b806-dda20963dafb"))
/* dual interface */ iInterface;
and I used them like this:
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:
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
Being happy, I wanted to test out, if the method calls to the classe are working. My header file tells me the following:
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::
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:
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
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
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?