[Dev-C++] Windows, COM, CoCreateInstance and OleInitialize
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Mark A. <am...@ho...> - 2005-08-11 15:19:23
|
Hi there!
I was trying all possibilities of DEV-C++ and I was pretty excited about =
it.
But I've encountered a problem.
In the Windows-operating-systems it is pretty important to use =
components (COM).
I've made a "windows application" project and added the following code:
----------------------------------------
const CLSID CLSID_Printing =3D =
{0x76A73923,0xD88C,0x11D6,{0xB5,0x51,0xEB,0xCE,0x0B,0x59,0xDA,0x72}};
const IID IID_IUnknown =3D =
{0x00000000,0x0000,0x0000,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
const IID IID_IClassFactory =
=3D{0x00000001,0x0000,0x0000,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
const CLSID CLSID_MySimpleObj =
=3D{0x14C0CBCC,0x8E68,0x4BB0,{0xB4,0x49,0x2D,0x9D,0xFB,0x80,0x9A,0x16}};
const IID IID_IMySimpleObj =
=3D{0x14C0CBCD,0x8E68,0x4BB0,{0xB4,0x49,0x2D,0x9D,0xFB,0x80,0x9A,0x16}};
interface IMySimpleObj : public IUnknown {
virtual HRESULT msg()=3D0;
};
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil) {
MessageBox(0,"Test Start..","Project2",0);
//OleInitialize(0); //<-Creates a crash!
IUnknown * schaap;
schaap =3D NULL;
HRESULT hr;
hr =3D =
CoCreateInstance(CLSID_MySimpleObj,0,CLSCTX_INPROC,IID_IUnknown,(void**)&=
schaap);
if (schaap!=3DNULL) {
MessageBox(0,"Test CoCreateInstance Worked!","Project2",0);
schaap->Release();
schaap =3D NULL;
}
//OleUninitialize();
MessageBox(0,"Test Done..","Project2",0);
//HERE THE REST OF THE WinMain-Code!
}
----------------------------------------
Secondly: in the menu 'Project' -> 'Project Options' --tab-> Parameters =
--button-> Add Library or Object
I've added the OLE32.LIB from Microsoft Visual C++ 5.0.
The problem is that CoCreateInstance never succeeds in creating an =
object!
So I also tried to do a "OleInitialize(0)", but this one always results =
in crashing!
I hope this problem can be solved to meet the important requirement of =
using COM in DEV-C++ !
greetings,
Mark Ament |