?
Solved

get the IDispatch of a com class

Posted on 2000-02-06
6
Medium Priority
?
362 Views
Last Modified: 2013-11-18
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 ?
0
Comment
Question by:yaelt
  • 4
6 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 80 total points
ID: 2493932
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
 
LVL 32

Expert Comment

by:jhance
ID: 2493934
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
 

Author Comment

by:yaelt
ID: 2496120
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 32

Expert Comment

by:jhance
ID: 2496285
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
 
LVL 1

Expert Comment

by:anoops
ID: 2503515
Ney..ney..Don't go for Inside COM..
Read the bible Essential COM by DonBox.
0
 
LVL 32

Expert Comment

by:jhance
ID: 2503845
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question