From: StefanWebb on
Hi,
I am trying to get the IDispatch for an HTML Control using the
DTM_BROWSERDISPATCH message. Here is some of my code:

IDispatch* pDisp = 0;
IWebBrowser2* pWebBrowser = 0;
SendMessage(hWndHtml, DTM_BROWSERDISPATCH, 0, (LPARAM) pDisp);

HRESULT hr = pDisp->QueryInterface(IID_IWebBrowser2, (void**) pWebBrowser);
if (FAILED(hr)) {
hr = S_OK;
}
long hi;
pWebBrowser->get_Height(&hi);

The problem is that after the sendmessage, the IDispatch pointer is still
NULL. Does anyone know how to solve this? Thanks.
From: René König on
Hello!

> SendMessage(hWndHtml, DTM_BROWSERDISPATCH, 0, (LPARAM) pDisp);

The dispatch pointer has to be passed as pointer, it is an [out]
parameter, and you forgot the ampersand. Try:
SendMessage(hWndHtml, DTM_BROWSERDISPATCH, 0, (LPARAM) &pDisp);
^

Rene
From: StefanWebb on
Thanks René. I feel a bit stupid for not realising that. Now I have a valid
pointer to an IDispatch interface. However, when I query it for an
IWebBrowser2 interface it returns E_NOINTERFACE. How can get the IWebBrowser2
interface? Here is some of my code.

IDispatch* pDisp = 0;
IWebBrowser2* pWebBrowser = 0;

SendMessage(hWndHtml, DTM_BROWSERDISPATCH, 0, (LPARAM) &pDisp);
HRESULT hr = pDisp->QueryInterface(IID_IWebBrowser2, (void**)&pWebBrowser);
if (FAILED(hr)) {
if (hr == E_NOINTERFACE)
MessageBox(hWnd, TEXT("Interface doesn't exist"), TEXT("Browser
Control Problem:") , NULL);
if (hr == E_NOTIMPL)
MessageBox(hWnd, TEXT("Queryinterface not implemented"), TEXT("Browser
Control Problem:") , NULL);
hr = S_OK;
}