Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: 9 Apr 2006 21:45:03 -0700,    group: microsoft.public.platformsdk.com_ole        back       


COM question - newbie   
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;
}
====================================
date: 9 Apr 2006 21:45:03 -0700   author:   Ehud_A

Re: COM question - newbie   
"Ehud_A"  wrote in message
news:1144644303.813616.210060@j33g2000cwa.googlegroups.com
> 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?

No, you can get the pointer once and cache it.

> Can't they be saved as a class member?

They can.
-- 
With best wishes,
    Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925
date: Mon, 10 Apr 2006 08:04:24 -0400   author:   Igor Tandetnik

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us