|
In general I would suggest you don't use it, having to tends to suggest you have some badly designed code. Prefer inheritance and virtual functions.
Steve
|
|
|
|
|
I concur with Stephen. Almost every example I've seen is contrived. There are a few exceptions, though with some of those better design would prevent having to use it.
|
|
|
|
|
i write a class derived from CHtmlView, and write the code as below, when it run, no bar appear, and a messageBox show a string '0x80040100', what is the reason? how can i make it work. any suggestion or help are appreciated
void CXxView::OnShowBar()
{
IWebBrowser2 *pBrowser = NULL;
HRESULT hr = m_pBrowserApp->QueryInterface(IID_IWebBrowser2, (void **) &pBrowser);
if (SUCCEEDED(hr))
{
VARIANT vtBandGUID, vtShow;
vtBandGUID.vt = VT_BSTR;
vtBandGUID.bstrVal = SysAllocString(OLESTR("{30D02401-6A81-11d0-8274-00C04FD5AE38}"));
vtShow.vt = VT_BOOL;
vtShow.boolVal = TRUE;
HRESULT hrx = pBrowser->ShowBrowserBar(&vtBandGUID, &vtShow, 0);
if (FAILED(hrx))
{
CString _str;
_str.Format("0x%x", hrx);
AfxMessageBox(_str);
}
SysFreeString(vtBandGUID.bstrVal);
pBrowser->Release();
}
}
|
|
|
|
|
It is what you asked for
_str.Format("0x%x", hrx);
AfxMessageBox(_str);
"0x%x" means put a 0x in front and return the hex and hence you get 0x80040100
IWebBrowser2::ShowBrowserBar returns either S_OK status or E_FAIL see the documentation
http://msdn.microsoft.com/en-us/library/aa768268%28v=vs.85%29.aspx[^]
So it is returning E_FAIL and the value is given.
Now as to what the problem is I have suspicions on this line
vtShow.boolVal = TRUE;
Are you sure I thought these had to be lower case true or VARIANT_TRUE which is the same thing but definitely all Microsoft code I have ever seen uses VARIANT_TRUE
If that isn't it I guess there is something with the GUID implementation and talk to Microsoft.
|
|
|
|
|
thank you for your help. i use VARIANT_TRUE and true, the problem keeps the same. and i copy the guid from msdn, it also keeps the same. anyone more suggestions?
|
|
|
|
|
Hi,
I see two errors:
Leon de Boer is correct that you should set vtShow.boolVal to VARIANT_TRUE ;
I see another error... the third argument to ShowBrowserBar Function[^] should be a pointer to an empty VARIANT... not a NULL pointer.
VARIANT vtEmpty = {0};
Best Wishes,
-David Delaune
|
|
|
|
|
thank your help info. i change the variable as code below, but the problem keeps the same:
IWebBrowser2 *pBrowser = NULL;
HRESULT hr = m_pBrowserApp->QueryInterface(IID_IWebBrowser2, (void **) &pBrowser);
if (!SUCCEEDED(hr))
return;
VARIANT vtBandGUID, vtShow;
vtBandGUID.vt = VT_BSTR;
vtBandGUID.bstrVal = SysAllocString(OLESTR("{30D02401-6A81-11D0-8274-00C04FD5AE38}"));
vtShow.vt = VT_BOOL;
vtShow.boolVal = VARIANT_TRUE;
VARIANT vtEmpty = {0};
hr = pBrowser->ShowBrowserBar(&vtBandGUID, &vtShow, &vtEmpty);
SysFreeString(vtBandGUID.bstrVal);
pBrowser->Release();
|
|
|
|
|
Hi,
Your code appears to be absolutely correct. The error you are encountering could be caused by the browser control not supporting explorer bars.
Best Wishes,
-David Delaune
|
|
|
|
|
thank you for you reply.
i think the reason is as you pointed out.
my enviroment: windowsXP sp3 + IE8
|
|
|
|
|
i write a class derived from CHtmlView, and write the code as below, when it run, no bar appear, and a messageBox show a string '0x80040100', what is the reason? how can i make it work. any suggestion or help are appreciated
void CXxView::OnShowBar()
{
IWebBrowser2 *pBrowser = NULL;
HRESULT hr = m_pBrowserApp->QueryInterface(IID_IWebBrowser2, (void **) &pBrowser);
if (SUCCEEDED(hr))
{
VARIANT vtBandGUID, vtShow;
vtBandGUID.vt = VT_BSTR;
vtBandGUID.bstrVal = SysAllocString(OLESTR("{30D02401-6A81-11d0-8274-00C04FD5AE38}"));
vtShow.vt = VT_BOOL;
vtShow.boolVal = TRUE;
HRESULT hrx = pBrowser->ShowBrowserBar(&vtBandGUID, &vtShow, 0);
if (FAILED(hrx))
{
CString _str;
_str.Format("0x%x", hrx);
AfxMessageBox(_str);
}
SysFreeString(vtBandGUID.bstrVal);
pBrowser->Release();
}
}
|
|
|
|
|
I just can't understand the meaning of unique_ptr or auto_ptr, as we all know, once the parameter gets out of its scope, we won't get memory leaks. However, is it a better idea if I create the parameter on the stack rather on the heap. I don't see its advantage over normal parameters. If we really need to create parameters on the heap, then we must use '
new ' operator, right?
Here is a little code snippet:
class Base
{
public:
Base()
{
cout << "Base::()" << endl;
}
virtual ~Base()
{
cout << "~Base()" << endl;
}
virtual void iPhone()
{
cout << "I'm iPhone5s" << endl;
}
};
class Derive : public Base
{
public:
Derive()
{
cout << "Derive()" << endl;
}
virtual void iPhone()
{
cout << "I'm iPhone 6" << endl;
}
virtual ~Derive()
{
cout << "~Derive()" << endl;
}
};
void main()
{
{
auto_ptr<Base> ptr(new Derive()); ptr->iPhone();
Derive d; Base* base = &d;
base->iPhone();
}
}
|
|
|
|
|
Note: std::auto_ptr has been (mostly) replaced by std::unique_ptr .
The use of std::unique_ptr and std::shared_ptr offer better memory management (garbage control, ... ) than naked pointer (google for the difference between unique and shared).
{
Derive* p = new Derive;
}
{
std::unique_ptr<Derive> p(new Derive);
}
In all (most) cases it would be better to not use pointers at all; but when it happens, use std::unique_ptr or stdshared_ptr depending on your need.
So in your example, it could simple be :
{
Derive d;
d.iPhone();
}
In simple examples using one or the other will probably not make a difference, but in larger systems, it will.
I'd rather be phishing!
|
|
|
|
|
It's essentially meant for the cases where you do need the heap... when you're already using new/delete. It eliminates the need to call delete explicitly and prevents leaks by taking care of the deallocation automatically. That's pretty much the crux of it (I personally don't use it at all).
|
|
|
|
|
I never found it especially useful. By the time it arrived I had disciplined myself when I created code that I didn't see failures to deallocate anymore.
I did find that attempting to refactor code (others) that did have problems was at best a futile exorcize but maybe I never understood it in detail enough.
|
|
|
|
|
|
In general it may indeed be better to create it on the stack. The reason you'd use new is when you want more control over it's lifetime. For example you can't use the stack if it need to stay "alive" after the function returns (more generally, when it goes out of scope).
Steve
|
|
|
|
|
In Embedded programming working with Win c, can we develop Win c applications in visual studio, for that any special licence required.
|
|
|
|
|
I develop Win CE program using VS2005,but need SDK from hardware vendor.
then my program can run on it's hardware platform.
|
|
|
|
|
ok thank you for your reply, can u tell me if i am using visual studio 2008 or 2010 is there any necessity of SDK in these versions also, please help me.
|
|
|
|
|
I think you need to ask the hardware vendor. for example, if you use ARM CPU, and I assume you develop WinCE based program, then, either hardware vendor create a SDK for you, or you can create a SDK for yourself with PlatForm Builder.
PlatForm Builder is a software from Microsoft.
|
|
|
|
|
Visual studio 12 will allow you to compile direct to Windows RT on an ARM processor which can be useful.
Personally however I cheat I usually write a UI interface that emulates the the embedded target on the PC or I have an old version of WINE which I have doctored and call Darkside which provides all the basic API interface of windows but runs a very simple concept of a device context and no multitasking.
It sort of weird I often have a linux thread kernel pushing into a faked version of Windows UI .... seems all wrong if you think about it.
The trick with all these techniques it to have a clear idea of interfaces on your embedded project so you can do the emulations. You can't just start random coding and hot and hope planning is everything.
|
|
|
|
|
Does it have any constraint in MFC, because the same code works fine when I run on win32 console. Will be grateful.
|
|
|
|
|
SetWindowsHookEx [^] is a Windows API . Calling it (correctly) in a MFC application or in a Win32 console application is the same.
Veni, vidi, vici.
|
|
|
|
|
What error code do you get?
|
|
|
|
|