get the IDispatch of a com class

i have a com class (interface) with several functions.
i m writing a function that will execute one of this function ( by using the line: pDispatch->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL);

now, what i need is a way to get the pDispatch ( IDispatch* pDispatch ).
i know only the inteface name & i also have a pointer to it's class (CCbtInterface* m_pCbtInterface;).

how do i do it ?
yaeltAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jhanceCommented:
Getting the IDispatch is basic.  You get it from IUnknown::QueryInterface().  If you can't get IUnknown, you can't do ANYTHING with a COM object!

1) CoInitialize()  - initialize COM - required!

2) CoCreateInstance() - loads the COM object, if necessary and returns you a pointer to the IUnknown interface - also required!

3)Now you have IUnknown, you can use IUnknown::QueryInterface to get a pointer to ANY other interface on the object, including IID_IDispatch.

4) When you're done with IUnknown, don't forget to call IUnknown::Release()

5) When you're don'e with IDispatch, don't forget to call IDispatch::Release()

6) CoUninitialize()
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jhanceCommented:
BTW, if you have m_pCbtInterface, you can still use m_pCbtInterface->QueryInterface() to get IDispatch as ALL COM interfaces MUST inherit from IUnknown.  This means that m_pCbtInterface->QueryInterface() is the SAME as IUnknown::QueryInterface() by definition.
0
yaeltAuthor Commented:
i have a really stupid question ...
but :
i have IDispatch* pDispatch; ,right ? & the QueryInterface function get a
void ** as the 2nd parameter, right ?
how can i pass the pDispatch 2 it ?

help !
( i said it's a stupid qst, didnt i )
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

jhanceCommented:
QueryInterface takes a pointer to a pointer to a void so that it can return to you a pointer to a void.

IDispatch *pDisp;

pUnk->QueryInterface(IID_IDispatch, (LPVOID *)&pDisp);

Now, pDisp has the address of IDispatch.

You pass it the _ADDRESS_ of pDisp so that it can fill it in with the pointer to IDispatch you need.

Have you considered getting a good book on COM?  It seems like you are missing some of the basics.  I'd suggest "Inside COM" by Rogerson as a good starting point.
0
anoopsCommented:
Ney..ney..Don't go for Inside COM..
Read the bible Essential COM by DonBox.
0
jhanceCommented:
anoops,

Personally, I think that Essential COM is a great book and it was the first COM book I purchased.  After trying to read it time after time, I found that it was just not a good introduction and I still didn't understand COM.  

After I then found Inside COM, read it, Essential COM made a LOT more sense.

I just don't feel it's a good place to start with COM.

As always, your mileage may vary...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Components

From novice to tech pro — start learning today.