COM question - newbie

E

Ehud_A

Hi all,
I'm new to COM. My question is with a specific goal, but i guess this a
general COM issue, so I hope some COM expert could help me.

I developed a webbrowser based on the webbrowser activeX control. When
I noticed that it doesn't respond to keys like tab,delete and others, i
googled a bit and found that when adding the code below to the WinMain
message handle loop it works.
The important class is named BrowserWindow and it holds pointers to
IWebBrowser2 interface and a CAxWindow object.
My question:
is it necessary to do in every round of the loop the queryInterface(),
release() stuff to get the objects i need, including the
IOleInPlaceActiveObject pointer?
Can't they be saved as a class member?

In every example i saw they are queried each time, i don't understand
why.

thanks for your help
========================================
this code is taken from the WinMain()

MSG msg ;

while(GetMessage(&msg, NULL , NULL, NULL) != 0) {

TranslateMessage(&msg);

LPDISPATCH lpDispatch = NULL;

HWND parent = msg.hwnd ;

// climb up until you find the top parent
while(GetParent(parent)){
parent = GetParent(parent) ;
}

// get the BrowserWindow that is saved in a map with its handle
BrowserWindow* bw = BrowserWindow::getByHwnd(parent);

if (bw != NULL) {

lpDispatch = bw->GetDoc();
if (lpDispatch!=NULL){

IOleInPlaceActiveObject* pIOIPAO = NULL;

lpDispatch->QueryInterface(IID_IOleInPlaceActiveObject,
(void**)&pIOIPAO);
lpDispatch->Release();

if (pIOIPAO!= NULL) {
pIOIPAO->TranslateAccelerator(&msg);
pIOIPAO->Release();
}
}
}

DispatchMessage(&msg);
}

.....
====================================
IHTMLDocument2* BrowserWindow::GetDoc(){

IDispatch *dispatch;
HRESULT hr = spBrowser->get_Document(&dispatch);
if (!SUCCEEDED(hr) || dispatch==NULL) {
return NULL;
}

IHTMLDocument2 *doc;
dispatch->QueryInterface(IID_IHTMLDocument2,(void**)&doc);
dispatch->Release();

return doc;
}
====================================
 
R

red floyd

Ehud_A said:
Hi all,
I'm new to COM. My question is with a specific goal, but i guess this a
general COM issue, so I hope some COM expert could help me.
[redacted]

COM is OT here. May I suggest a newsgroup in the microsoft.public.*
hierarchy?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top