Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ph0ngwh0ng

A Pointer To IUnknown?

This topic is 5386 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to QueryInterface the first interface I initialize before I initialize it(of course). So, I figured I'd get a pointer to IUnknown. But, how do I manage to do this? I already have this:
IUnknown*  pIUnknown = NULL;

CoInitialize( NULL );

hr = CoCreateInstance( CLSID_????, NULL,CLSCTX_INPROC_SERVER,
                        IID_IUnknown, (LPVOID*) &pIUnknown );
I can't find the CLSID for the IUnknown interface. Any DETAILED solution would be nice. Thanks! ph0ng^_^wh0ng [edited by - ph0ngwh0ng on September 24, 2003 8:08:11 AM]

Share this post


Link to post
Share on other sites
Advertisement
Ok, thanks.
But, if I don''t have an interface(no IID to supply) that implements IUnknown, can I get a pointer to IUnknown?

And, quoted from DX SDK:


IDirectPlay8Peer* g_pDP = NULL;
...
CoInitialize( NULL );
...
hr = CoCreateInstance( CLSID_DirectPlay8Peer, NULL,CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Peer, (LPVOID*) &g_pDP );

hr = g_pDP->Initialize( NULL, DirectPlayMessageHandler, 0 );



ph0ng^_^wh0ng

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
well, if you''re developing with COM and you''re not implementing IUnknown, something is wrong.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
... and because every COM-interface should derive from IUnknown, you should be able to do a cast (which would even be dangerous).

Share this post


Link to post
Share on other sites
AP, I am developing with COm(DirectX is built on COM). All I needed was a way to test for an interface availability before calling its initialization function, like D3DCreate9 for IDirect3D9.

With this, I want to test that the user has the right interfaces installed before running the game i.e. intializing IDirect3D9.

But, I willl init IDirect3D9 with D3DCreate9 and if it returns NULL as a pointer, I''ll assume DX9 is not installed on the machine.

ph0ng^_^wh0ng

Share this post


Link to post
Share on other sites
If I'm understanding you correctly, then you want to do this.

Query for IDirectPlay8Peer's IUnknown ...


HRESULT hr;
CComPtr<IUnknown> pUnk;

hr = CoCreateInstance(CLSID_DirectPlay8Peer, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, reinterpret_cast<IUnknown*>(&pUnk));


If you are using a COM object you will always have IUnknown. Once you have got it you can do the following.


CComPtr<IDirectPlay8Peer> pDP8P;
hr = pUnk->QueryInterface(__uuidof(IDirectPlay8Peer), reinterpret_cast<IDirectPlay8Peer*>(&pDP8P);


... Test HR ...

If the object contains the IDirectPlay8Peer interface then your hr will be S_OK and the pDP8P pointer will be pointing to the interface ...

I haven't used COM for a while, but I think my syntax is OK.

[edited by - MonkeyChuff on September 24, 2003 10:40:52 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by ph0ngwh0ng
With this, I want to test that the user has the right interfaces installed before running the game i.e. intializing IDirect3D9.

That''s the point of COM in a way. You create an object and ask for an interface. If the interface is unavailable, you try another one and so on...

CoCreateInstance(...)
QueryInterface( IDirectX9 )
if FAILED
Queryinterface( IDirectX9 )
// Yeah! Shaders ahoy!

if FAILED
Queryinterface( IDirectX8 )
// Well, so much for enhanced pixel shaders...

if FAILED
Queryinterface( IDirectX7 )
// Hey pal, upgrade a bit! It''s goona be slooooow.

if FAILED
Queryinterface( IDirectX5 )
// Shucks... it''s old Win95. You really wanna play with this?

if FAILED
Queryinterface( IDirectX3 )
// Oh gosh, it''s an NT4 machine... Back to ol'' DirectDraw.


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!