0 registered members (),
1,459
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
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?
Last edited by HeelX; 09/09/11 16:58.
|
|
|
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
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
Which one? The declaration is in the vtable struct:
long __stdcall GetHeartCoherence (void* This);
The This pointer is added because the manual says: 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
Moderator
|
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
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
I added all methods and then I looked into picture.h and there wasn't
// 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:
// 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: Tobias]
#382681
09/11/11 09:16
09/11/11 09:16
|
Joined: Jul 2001
Posts: 6,904
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
You use the preinitialized GUID for the first parameter when you call CoCreateInstance. I wrote that
GUID IID_iInterface =
{0xf9f48469,0x68ab,0x3013,{0xb8,0x06,0xdd,0xa2,0x09,0x63,0xda,0xfb}};
doesn't compile for me. Try yourself!
|
|
|
|