Trying to create an Instance of a COM object Topic is solved

This forum is reserved for everything you want to talk about. It could be about programming, opinions, open source programs, development in general, or just cool stuff to share!
Post Reply
noel
Earned a small fee
Earned a small fee
Posts: 19
Joined: Wed Nov 22, 2006 8:52 pm

Trying to create an Instance of a COM object

Post by noel »

I'm trying to create an Instance of a COM object, but the code below seems to do not work.

Code: Select all

HRESULT hr; 
IDispatch* pDispatchDB;

const IID DIID__BT = {0x3F707000,0xDC7D,0x4b37,{0xA4,0xC8,0x72,0x70,0x64,0x40,0x20,0xF7}}; //TypeLib
const CLSID CLSID_BT = {0x3F708029,0xDC7D,0x4b37,{0xA4,0xC8,0x72,0x70,0x64,0x40,0x20,0xF7}}; //CLSID 

	hr = CoCreateInstance(CLSID_BT, NULL,CLSCTX_INPROC_HANDLER,DIID__BT, (void**)&pDispatchDB);

        if ( SUCCEEDED ( hr ) )
        {
         wxMessageBox (_T("CoCreateInstance OK!!"));
        }
Any sugestions - very welcome.
WriteLn or not WriteLn ;)
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan »

Hi,
what is error code (hr)?
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

Maybe you should try to create a CoClass from an interface which is guaranteed to work, also maybe the pDispatchDB needs to be initialized first. I am not experienced in the C++ side of COM programming, but I did my Delphi share. Fortunately a lot was hidden from the developer ;-)

Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
noel
Earned a small fee
Earned a small fee
Posts: 19
Joined: Wed Nov 22, 2006 8:52 pm

Post by noel »

tan wrote:Hi,
what is error code (hr)?
Well, to be honest I don't know. And becouse I'm quite a beginner in C++ programming - I' dont know how to check it out.

Also inserting a

Code: Select all

CoInitialize(NULL);
in my code - do not change anythink.
WriteLn or not WriteLn ;)
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan »

Hi,
noel wrote:
tan wrote:Hi,
what is error code (hr)?
Well, to be honest I don't know. And becouse I'm quite a beginner in C++ programming - I' dont know how to check it out.

Code: Select all

        hr = CoCreateInstance(CLSID_BT, NULL,CLSCTX_INPROC_HANDLER,DIID__BT, (void**)&pDispatchDB);

        if ( SUCCEEDED ( hr ) )
        {
         wxMessageBox (_T("CoCreateInstance OK!!"));
        }
        else
        {
         wxLogError(_T("Error code = %08X"), hr);
        }
And what about this object? Is it standard? What is the interface DIID__BT?
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
noel
Earned a small fee
Earned a small fee
Posts: 19
Joined: Wed Nov 22, 2006 8:52 pm

Post by noel »

Error code is: 80040154
when I change CLSCTX_INPROC_HANDLER to CLSCTX_INPROC_SERVER the Error code is; 80004002
And what about this object? Is it standard? What is the interface DIID__BT?
The object is a Libary (*.dll), it is a record object to comunicate with database. Below is a fragment of the Windows registry where this libary is registred.

[HKEY_CLASSES_ROOT\CLSID\{3F708029-DC7D-4b37-A4C8-7270644020F7}]
@="BtDatabase Class"

[HKEY_CLASSES_ROOT\CLSID\{3F708029-DC7D-4b37-A4C8-7270644020F7}\InprocServer32]
@="C:\\Program Files\\Common Files\\Matrix.pl\\MxFk560.dll"
"ThreadingModel"="Apartment"

[HKEY_CLASSES_ROOT\CLSID\{3F708029-DC7D-4b37-A4C8-7270644020F7}\ProgID]
@="MxDokFK.BtDatabase.2"

[HKEY_CLASSES_ROOT\CLSID\{3F708029-DC7D-4b37-A4C8-7270644020F7}\Programmable]

[HKEY_CLASSES_ROOT\CLSID\{3F708029-DC7D-4b37-A4C8-7270644020F7}\TypeLib]
@="{3F707000-DC7D-4b37-A4C8-7270644020F7}"

[HKEY_CLASSES_ROOT\CLSID\{3F708029-DC7D-4b37-A4C8-7270644020F7}\VersionIndependentProgID]
@="MxDokFK.BtDatabase"
WriteLn or not WriteLn ;)
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan »

noel wrote:Error code is: 80040154
when I change CLSCTX_INPROC_HANDLER to CLSCTX_INPROC_SERVER the Error code is; 80004002
Ok, it is quite clear.
1.You have to use CLSCTX_INPROC_SERVER
2.You can't use the DIID__BT in this context, it is the TypeLib, not INTERFACE IID. What interface do you want from this object?
What at all do you know about this object, what interfaces does it implement?
You can try to get Dispatch interface:

Code: Select all

        hr = CoCreateInstance(CLSID_BT, NULL,CLSCTX_INPROC_SERVER, IID_IDispatch, (void**)&pDispatchDB); 
That definitely has to work, but to use any object you must have some knowledge about it :)
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
noel
Earned a small fee
Earned a small fee
Posts: 19
Joined: Wed Nov 22, 2006 8:52 pm

Post by noel »

That definitely has to work, but to use any object you must have some knowledge about it :)
I kow all methots and properities (I can program this object in VB and PHP).

IID_IDispatch ?? - what value of this - how should I declere it ??
WriteLn or not WriteLn ;)
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan »

noel wrote:
That definitely has to work, but to use any object you must have some knowledge about it :)
I kow all methots and properities (I can program this object in VB and PHP).
OK
noel wrote: IID_IDispatch ?? - what value of this - how should I declere it ??
You don't need declare IID_IDispatch, it declared in OAIdl.h. It is IDispatch interface IID.
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

Stupid question, but have you registered the DLL as COM library?

regsvr32 yourdll.dll

Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
noel
Earned a small fee
Earned a small fee
Posts: 19
Joined: Wed Nov 22, 2006 8:52 pm

Post by noel »

Jorg wrote:Stupid question, but have you registered the DLL as COM library?

regsvr32 yourdll.dll

Regards,
- Jorgen
This dll has got installation shild - it's prabobly registred automaticly.
WriteLn or not WriteLn ;)
noel
Earned a small fee
Earned a small fee
Posts: 19
Joined: Wed Nov 22, 2006 8:52 pm

Post by noel »

tan wrote:
noel wrote:
That definitely has to work, but to use any object you must have some knowledge about it :)
I kow all methots and properities (I can program this object in VB and PHP).
OK
noel wrote: IID_IDispatch ?? - what value of this - how should I declere it ??
You don't need declare IID_IDispatch, it declared in OAIdl.h. It is IDispatch interface IID.

Tahnx VERY much tan - CoCreateInstance works - now I have some more code do Develop - but not right now.
WriteLn or not WriteLn ;)
Post Reply