Hello,
I need help on global variable usage in an ActiveX(ATL) project. Basically the ActiveX component function is to navigae to a specified URL in composite control(webbrowser embedded). The URL string is initialize in the beginning and saved in a global variable. here is my source code file of ActiveX project.
(Do not be concerned about the grammar, I just want to show the code flow).
MyComponentInit.cpp
// MyComponentInit.cpp : Implementation of MyComponentInit.cpp
#include "stdafx.h"
#include <ios>
char szURL[1024] = "\0"; // global variable holding URL string
STDMETHODIMP CMyComponentInit::InitPlugin(BSTR url)
{
// convert BSTR to string
......
memcpy(szURL, szUrl, len);
}
MyComponentCtrl.cpp
// MyComponentCtrl.cpp : Implementation of MyComponentCtrl.cpp
#include "stdafx.h"
extern char szURL[1024]
LRESULT CMyComponentCtrl::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
......
m_spWebbrowser->Navigate(szURL, &v, &v, &v, &v);
}
The use of mycomponent ActiveX is in a MFC SDI(Single Doc/View) test application. The flow is like:
- In App Initinstance, I called activeX InitPlugin to initialize the URL string.
- In a Information dialog window, insert MyComponentCtrl ActiveX, the Information dialog is brought up by clicking Mainframe Information menu item. The goal is when Information dialog window pop up, it can always go to the specified url.
After my MFC test app starts, I click Information dialog menu, the Information dialog window can be up and navigate to the url correctly.
But the problem is if I close the Information dialog, wait fro a while (around 2~3 minutes), I tried to bring up Information dialog again, it could not navigate to the URL. I debug it and found the global variable szURL in MyComponenet project lost its value.
Can you please tell me what should I do to resolve this problem?
Thanks a lot in advance!
Bionicoder