Board index » cppbuilder » IDispatch Tutorial

IDispatch Tutorial


2003-12-19 12:48:02 AM
cppbuilder58
Can someone point me to a good tutorial on how to use an IDispatch?
I am trying to use the TCppWebBrowser::Document to get to the raw HTML and
I have no idea on how to do this. There was a previous post with an example
but
I would prefer to have a better understanding of what to do and why it works
rather
than just cutting and pasting the code.
I am looking for something like the "Idiots Guide To Using IDispatch."
Thanks,
Jim
 
 

Re:IDispatch Tutorial

"James Wheeler, PE" < XXXX@XXXXX.COM >wrote in message
Quote
I am trying to use the TCppWebBrowser::Document to get to
the raw HTML and I have no idea on how to do this.
You need to call QueryInterface() on the Document to get an
IPersistStreamInit interface. Then you can call its Save() method to store
the HTML data into an IStream. For convenience, you can use the VCL's
TStreamAdapter to "adapt" a TStream, such as TStringStream, into a suitable
IStream.
Quote
I would prefer to have a better understanding of what to do and
why it works rather than just cutting and pasting the code.
What you are asking for is a very broad subject as it hits at the very core
of ActiveX/COM programming in general, and is much too big to discuss in a
single message. There are entire books on the subject.
Just some basics -
- ActiveX controls are made up of a bunch of classes called interfaces.
Every interface derives from IUnknown, and possible IDispatch as well.
- Every interface is reference-counted. IUnknown exposes AddRef() and
Release() methods for manipulating the reference count. Whenever you pass
an interface pointer around, you need to call AddRef(), and whenever you are
done with the pointer, you need to call Release(). When the reference count
falls to 0, the interfacer automatically frees itself.
- Although the implementation of an interface can derive from multiple base
classes, the caller does not use normal polymorphism to access those
classes. Instead, IUnknown exposes a method named QueryInterface() for
that. Every interface has a unique ID associated with it, called a GUID.
You pass QueryInterface() the desired GUID, and it returns an appropriate
interface pointer if the GUID is supported.
Gambit
 

Re:IDispatch Tutorial

Ok...
Let me restate what I think you said and then ask some other questions.
1) I can use TCppWebBrowser::Document to get a pointer to a class that I
identify by passing
in a GUID. Where can I get a list of the available GUID's?
2) Assuming I get a ptr returned from step 1, I can then use it to call the
methods of the class identified by
the GUID I used to fetch the ptr. Where do you go to see what methods the
class supports?
In my futile efforts to try and get my hands around this I found some stuff
on MSDN and I am wondering
why I wouldn't use IID_IHTMLDocument2 in my call to QueryInterface.
Anyway, I know it is a broad subject. I was just looking for a very high
level overview.
Thanks,
Jim
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"James Wheeler, PE" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I am trying to use the TCppWebBrowser::Document to get to
>the raw HTML and I have no idea on how to do this.

You need to call QueryInterface() on the Document to get an
IPersistStreamInit interface. Then you can call its Save() method to
store
the HTML data into an IStream. For convenience, you can use the VCL's
TStreamAdapter to "adapt" a TStream, such as TStringStream, into a
suitable
IStream.

>I would prefer to have a better understanding of what to do and
>why it works rather than just cutting and pasting the code.

What you are asking for is a very broad subject as it hits at the very
core
of ActiveX/COM programming in general, and is much too big to discuss in a
single message. There are entire books on the subject.

Just some basics -

- ActiveX controls are made up of a bunch of classes called interfaces.
Every interface derives from IUnknown, and possible IDispatch as well.

- Every interface is reference-counted. IUnknown exposes AddRef() and
Release() methods for manipulating the reference count. Whenever you pass
an interface pointer around, you need to call AddRef(), and whenever you
are
done with the pointer, you need to call Release(). When the reference
count
falls to 0, the interfacer automatically frees itself.

- Although the implementation of an interface can derive from multiple
base
classes, the caller does not use normal polymorphism to access those
classes. Instead, IUnknown exposes a method named QueryInterface() for
that. Every interface has a unique ID associated with it, called a GUID.
You pass QueryInterface() the desired GUID, and it returns an appropriate
interface pointer if the GUID is supported.


Gambit


 

{smallsort}

Re:IDispatch Tutorial

"James Wheeler, PE" < XXXX@XXXXX.COM >wrote in message
Quote
1) I can use TCppWebBrowser::Document to get a pointer
to a class that I identify by passing in a GUID.
Yes.
Quote
Where can I get a list of the available GUID's?
All of the available GUIDs for the IE DOM interfaces are in mshtml.h.
Quote
2) Assuming I get a ptr returned from step 1, I can then use it to
call the methods of the class identified by the GUID I used to
fetch the ptr.
Yes. Interfaces are still classes like any other, so you can cal their
methods normally as expected.
Quote
Where do you go to see what methods the class supports?
All of IE's DOM interfaces are documented at MSDN:
Interfaces and Scripting Objects
msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/interface.asp
Quote
In my futile efforts to try and get my hands around this I found
some stuff on MSDN and I am wondering why I wouldn't use
IID_IHTMLDocument2 in my call to QueryInterface.
You would. That is the correct GUID to use. The IID type is just a typedef
for GUID, as is CLSID. Thus, an IID, a CLSID, and a GUID are all the same
thing, they are just spelled out in name for better clearity as to which is
used for what purpose (CLSID for loading libraries, IID for accessing
interfaces, and GUID for everything else).
Gambit