473,508 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Visual C++ BHO question

Hi All-

I'm trying to customize this project ( http://www.codeproject.com/shell/IEMenuButton.asp
) and I'm getting an access voilation and was hoping somebody would be
able to give me some idea

Here's the method I'm trying to work with

STDMETHODIMP CMasterObject::Exec(const GUID*, DWORD nCmdID, DWORD,
VARIANTARG*, VARIANTARG*)
{
if(m_spUnkSite == 0 || m_pWebBrowser2 == 0) return S_OK;

HRESULT hRes = S_OK;

CComPtr<IDispatch pDocDisp;
CComQIPtr<IHTMLDocument2pHtmlDoc2;

hRes = m_pWebBrowser2->get_Document(&pDocDisp);
if(SUCCEEDED(hRes) && pDocDisp)
{
hRes = pDocDisp->QueryInterface(IID_IHTMLDocument2,
(void**)&pHtmlDoc2);
if(SUCCEEDED(hRes) && pHtmlDoc2)
{
SHANDLE_PTR nBrowser = 0;
m_pWebBrowser2->get_HWND(&nBrowser);
HWND hWndParent = (HWND)nBrowser;

POINT pt;
GetCursorPos(&pt);

HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();

HMENU hMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU_POPUP) );
HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0);

if(hMenuTrackPopup && hWndParent)
{
BOOL bIsChevron = FALSE;
HWND hWndMenuParent = NULL;
HWND hWndToolBar = NULL;

hWndMenuParent = hWndParent;
hWndToolBar = WindowFromPoint(pt);

if(m_bIsIe7)
{
HWND hWndIe7ActiveTab = hWndParent;
HWND hWnd = GetWindow(hWndParent, GW_CHILD);

// looking for the Internet Explorer_Server window
// this window should be a parent for TrackPopupMenu
if(hWnd)
{
TCHAR szClassName[MAX_PATH];
while(hWnd)
{
memset(szClassName,0,MAX_PATH);
GetClassName(hWnd, szClassName, MAX_PATH);
if(_tcscmp(szClassName,_T("TabWindowClass"))==0)
{
// the active tab should be visible
if(IsWindowVisible(hWnd))
{
hWnd = GetWindow(hWnd, GW_CHILD);
while(hWnd)
{
memset(szClassName,0,MAX_PATH);
GetClassName(hWnd, szClassName, MAX_PATH);

if(_tcscmp(szClassName,_T("Shell DocObject View"))==0)
{
hWnd = FindWindowEx(hWnd, NULL, _T("Internet
Explorer_Server"), NULL);
if(hWnd) hWndIe7ActiveTab = hWnd;
break;
}
hWnd = GetWindow(hWnd, GW_HWNDNEXT);
}
}
}
hWnd = GetWindow(hWnd, GW_HWNDNEXT);
}
}

if(hWndIe7ActiveTab) hWndMenuParent = hWndIe7ActiveTab;
}

int nIDCommand = -1;
BOOL bRightAlign = FALSE;
if(hWndToolBar)
{
ScreenToClient(hWndToolBar,&pt);
int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0,
(LPARAM)&pt);
if(nButton>0)
{
TBBUTTON pTBBtn;
memset(&pTBBtn,0,sizeof(TBBUTTON));
if(::SendMessage(hWndToolBar, TB_GETBUTTON, nButton,
(LPARAM)&pTBBtn))
{
nIDCommand = pTBBtn.idCommand;
RECT rcButton;
if(::SendMessage(hWndToolBar,TB_GETRECT,nIDCommand ,
(LPARAM)&rcButton))
{
pt.x = rcButton.left;
pt.y = rcButton.bottom;
ClientToScreen(hWndToolBar,&pt);

RECT rcWorkArea;
SystemParametersInfo(SPI_GETWORKAREA,0,(LPVOID)&rc WorkArea,0);
if(rcWorkArea.right-pt.x<150)
{
bRightAlign = TRUE;
pt.x = rcButton.right;
pt.y = rcButton.bottom;
ClientToScreen(hWndToolBar,&pt);
}
}
}
}
else
{
GetCursorPos(&pt);
bIsChevron = TRUE;
}
}

UINT nFlags = TPM_NONOTIFY|TPM_RETURNCMD|TPM_LEFTBUTTON;
if(bRightAlign) nFlags |= TPM_RIGHTALIGN;
else nFlags |= TPM_LEFTALIGN;

// draw pressed button
if(nIDCommand!=-1 && !bIsChevron) ::SendMessage(hWndToolBar,
TB_PRESSBUTTON, nIDCommand, MAKELPARAM(1,0));
// popup the menu
int nCommand = TrackPopupMenu(hMenuTrackPopup, nFlags, pt.x, pt.y,
0, hWndMenuParent, 0);
// release the button
if(nIDCommand!=-1 && !bIsChevron) ::SendMessage(hWndToolBar,
TB_PRESSBUTTON, nIDCommand, MAKELPARAM(0,0));

switch (nCommand)
{
case ID_ITEM1:
MessageBox(hWndParent,_T("Item 1 is
selected"),_T("TestExtension"), MB_OK|MB_ICONEXCLAMATION);
break;
case ID_ITEM2:
MessageBox(hWndParent,_T("Item 2 is
selected"),_T("TestExtension"), MB_OK|MB_ICONEXCLAMATION);
break;
case ID_about:
MessageBox(hWndParent,_T("TestExtension 1.0\nCopyright © 2006
Igor Tolmachev\nhttp://www.itsamples.com"), _T("TestExtension"), MB_OK|
MB_ICONINFORMATION);
break;
}
}
}
}
return S_OK;
}
Basically I need to get the URL of the website that's in IE's window
and I'm getting an access violation error when I do it. I'm putting
this right before "switch (nCommand)"

pHtmlDoc2->get_URL(pURL);
BSTR outURL = *pURL;
_bstr_t(sURL);

This works sometimes but not others. I'm not sure if it's because the
page hasn't fully loaded or what it is, but I'd like to get it to work
all the time.

Thanks,
Dave

Apr 21 '07 #1
2 4252
Sorry I just realized I posted wrong, I've been trying lots of stuff
and it's late, anyways, this is what my part of the code should look
like

pHtmlDoc2->get_URL(pURL);
BSTR outURL = *pURL;
_bstr_t sURL(outURL);

Apr 21 '07 #2
Dave King wrote:
Sorry I just realized I posted wrong, I've been trying lots of stuff
and it's late, anyways, this is what my part of the code should look
like

pHtmlDoc2->get_URL(pURL);
BSTR outURL = *pURL;
_bstr_t sURL(outURL);
This realy should go to a windows programming group.

--
Ian Collins.
Apr 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2471
by: FLChamp | last post by:
SOrry if this message is a little confused, it most probably reflects the state of the author! I have made a small program that plots the orbit of a planet in visual python using visual.vector...
2
2040
by: PkingTom | last post by:
I have read that Visual Basic 6.0 is included with Visual Studio 6.0 Professional Edition. Maybe this is a dumb question but how do I bring up the VB Editor? I wasn't sure if I installed it even...
2
2116
by: Durham Writer | last post by:
Hi all, I am trying to learn c++ for the first time, having used 'c' in the past. It was a long time ago and I'm getting back into programming. I was wondering if I could get some help...
17
2558
by: Andi Plotsky | last post by:
I am not a .NET developer. I want the Developer's Edition of Visual Studio for use with my Access2000 databases. Does anyone have a clue as to where to find it - my office manager says only .NET...
65
18963
by: xuanbai98 | last post by:
I want to know the current support status of c99 on Microsoft Visual Studio. Anyone know whether Microsoft has any plan to support c99 on Visual Studio? Thanks, Xuan
5
13983
by: Ditoa | last post by:
Hi all, I would like to learn how to program in C# and have been looking at some books to help me get started. As I have found the Sams Teach Yourself... books very good in the past I would...
4
1838
by: Geoff Cox | last post by:
Hello, After much effort I have got the Visual C# code below to work using Visual C# 2005 Express Beta 2 and now I am trying to convert it to Visual C++ code so that I can use it in Visual C++...
4
5158
by: Andy | last post by:
In visual studio, I have an asp.net project. When I debug, I have to manually attach to aspnet_wp.exe. My project used to automatically attach to this process. How do I get it to automatically...
6
2084
by: VR | last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages, my MasterPage does not have a form tag itself...
6
2507
by: Salman | last post by:
I would like to know how I can distribute the application that I create with Visual C++ express edition. I checked the menu options to find a deploy option similar to the one found on the Visual...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7382
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7042
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.