|
Didn't seem to make any difference.. Here is my updated code (I hope I made the change you recommended correctly...):
ON_EVENT(CLoadWebSite, IDC_EXPLORER, 273 /* NewWindow3 */, OnNewWindow3Explorer1, VTS_DISPATCH VTS_PBOOL VTS_BSTR VTS_BSTR VTS_BSTR)
void CLoadWebSite::OnNewWindow3Explorer1(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel, BSTR *Flags, BSTR *URLContext, BSTR *URL)
{
CString url = "";
VARIANT vnt;
vnt.vt = VT_BSTR;
vnt.pbstrVal = URL;
url = vnt.bstrVal;
*Cancel = TRUE;
AfxMessageBox(url);
// Browser.Navigate(url,NULL,NULL,NULL,NULL);
}
|
|
|
|
|
univega_r304 wrote: void CLoadWebSite::OnNewWindow3Explorer1(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel, BSTR *Flags, BSTR *URLContext, BSTR *URL)
I made an error. The last three parameters are indeed pass-by-value, not pass-by-reference. You can remove the '*' from them.
You should be able to set a breakpoint on the first statement in OnNewWindow3Explorer1() and see the value of URL . If it's not correct then, nor shall it be when assigned to url .
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Ok, I set it back to pass-by-value (I caught your earlier post you had deleted)
I set up a breakpoint on the line: url = vnt.bstrVal; and it shows me the URL! But why then is it displaying in AfxMessageBox as all ? marks.... hmmmm....
|
|
|
|
|
This is what I see in the debugger (Autos tab):
url tree ->
Name: url
Value: {...}
Type: ATL::CStringT<char,strtraitmfc<char,atl::chtraitscrt<char> > >
Name: ATL::CSimpleStringT<char,0>
Value: "*edited value* http://myinternallink"
Type: ATL::CSimpleStringT<char,0>
Name: m_pszData
Value: 0x6aed22a7 <bad ptr="">
Type: char *
Name: <warning symbol="">
Value: CXX0030: Error: expression cannot be evaluated
|
|
|
|
|
None of the vnt stuff is necessary. Just use:
CString url(V_BSTR(&URL));
AfxMessageBox(url);
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
That didn't work. The compiler didn't like it one bit
error C2227: left of '->bstrVal' must point to class/struct/union/generic type
type is 'BSTR *'
|
|
|
|
|
Show me your code once more. Did you try it with/out the ampersand?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Tried it with and without the ampersand. Pretty much the same error:
with:
error C2227: left of '->bstrVal' must point to class/struct/union/generic type
type is 'BSTR *'
without:
error C2227: left of '->bstrVal' must point to class/struct/union/generic type
type is 'BSTR'
Here's my code:
ON_EVENT(CLoadWebSite, IDC_EXPLORER, 273 /* NewWindow3 */, OnNewWindow3Explorer1, VTS_DISPATCH VTS_PBOOL VTS_BSTR VTS_BSTR VTS_BSTR)
void CLoadWebSite::OnNewWindow3Explorer1(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel, BSTR Flags, BSTR URLContext, BSTR URL)
{
CString url(V_BSTR(URL));
AfxMessageBox(url);
*Cancel = TRUE;
// Browser.Navigate(url,NULL,NULL,NULL,NULL);
}
|
|
|
|
|
I messed up (again). Since URL is already a BSTR , as opposed to a VARIANT , it obviously cannot be run through the V_BSTR() macro.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I've tried converting the value to CString every which way and it always comes to the same results no matter what, a line of several dozen ? marks.
This is getting quite frustrating
I have to assume then that it may be a problem with BSTR URL not reporting a proper url.
To test the NewWindow3 function I had my default site go to google.com, I searched on a something irrelevant and right-clicked to Open to a new window to trigger the event. In the debugger URL always comes back as a bunch of square shapes (I think because debugger can't display BSTR?, at least there's a doc somewhere on codeproject that said it couldn't, but it might have been for an older version of VS) and converting always results in ? marks...
If you want to test this you can do do very easily by going to this link:
http://www.codeproject.com/com/webbrowser.asp[^]
This is basically something similar to what I have. Just edit the code, change the default site if you wish and add the event for the NewWindow3 compile and have at it to see what you can find...
|
|
|
|
|
univega_r304 wrote: I think because debugger can't display BSTR
It might indeed be a Unicode thing. This is the default for VS2003 and VS2005, but not so with VS6 (what I'm using).
In the Watch window, the symbol for strings is s while the symbol for Unicode strings is su . See here for more.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Yeah, I'm using VS2005...
Here's a new bit a code that came very close...
void CLoadWebSite::OnNewWindow3Explorer1(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel, BSTR Flags, BSTR URLContext, BSTR URL)
{
BSTR b = URL;
_bstr_t orig(b);
CString cstring((char *)orig);
AfxMessageBox(_T(cstring));
*Cancel = TRUE;
Browser.Navigate(cstring,NULL,NULL,NULL,NULL);
}
When I debug this code the value for cstring is the URL I need! However, when I try to view it with AfxMessageBox or Navigate to it, it still thinks the value is all question marks.... I don't understand why it could show me one thing and do another... I wish there was a way to post a screenshot....
Any ideas?
|
|
|
|
|
univega_r304 wrote: AfxMessageBox(_T(cstring));
The _T() macro is for string literals.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
univega_r304 wrote:
If you want to test this you can do do very easily by going to this link:
http://www.codeproject.com/com/webbrowser.asp[^]
This is basically something similar to what I have. Just edit the code, change the default site if you wish and add the event for the NewWindow3 compile and have at it to see what you can find...
I already had an application that uses this control, but for some reason it does not support the NewWindow3 event. What version of shdocvw.dll do you have? Mine is 6.0.2900.2937.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Unless it's on mulitple locations on my drive the version I have appears to be older... I have 6.0.2900.2919. According to the article on MSDN: NewWindow3 is available only in Microsoft Windows XP Service Pack 2 (SP2) or later. So if you have that, it should work...
FYI, after messing around a bit and not getting anywhere I put the code back that was showing me the proper URL in the debugger stopped working again. Same code, but bad results. I have't been able to get it to reproduce the proper URL in the debugger since.
|
|
|
|
|
Would you believe I *FINALLY* got it working?
Here's the code to make it work....
ON_EVENT(CLoadWebSite, IDC_EXPLORER, 273 /* NewWindow3 */, OnNewWindow3Explorer1, VTS_DISPATCH VTS_PBOOL VTS_BSTR VTS_BSTR VTS_BSTR)
void CLoadWebSite::OnNewWindow3Explorer1(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel, BSTR Flags, BSTR URLContext, BSTR URL)
{
CString strURL;
// capture URL of any link clicked that would attempt to open in a new window
if (URL != NULL)
strURL = (LPCTSTR)URL;
*Cancel = TRUE; // prevent IE from spawning
Browser.Navigate(strURL,NULL,NULL,NULL,NULL); // loads resulting URL into the web browser control instead of a spawned IE window
}
|
|
|
|
|
univega_r304 wrote: strURL = (LPCTSTR)URL;
This makes sense since a BSTR is really a type of char* . Could you have also done:
strURL = URL; as the assignment operator should handle the typecast automatically? If not, oh well.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Have a look at following code :
-----------------------------------------------------------------------------------------------------------------------
#include <afx.h>
#include <afxwin.h>
#include <conio.h>
#include <iostream>
using namespace std;
int main( int, char* [] )
{
CRect rc( 100,100, 500, 500 );
CRect rcOld;
CPoint pt;
GetCursorPos(&pt);
cout << "Current Position " << pt.x << ", " << pt.y << endl;
GetClipCursor(&rcOld);
ClipCursor( &rc );
cout << "Press any key to restore.." << endl;
getch();
ClipCursor( &rcOld );
return 0;
}
-----------------------------------------------------------------------------------------------------------------------
Looks foolproof.
Just build and run this application.
You will find that cursor indeed gets clipped in the area specified.
But, just do a right click and all clipping goes away !!!!
How can I resolve this? I dont want the clipped rect to go away till I restore the original rectangle back...
|
|
|
|
|
This is the correct behavior. The cursor is a shared system resource, no one app is allowed total control over it. Imagine if ClipCursor() worked 100% of the time. All you'd have to do was write an app that calls ClipCursor(0,0,1,1) and boom - instant denial of service.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
I know that this question is not really related to Visual C++ but hopefully there will be someone here who has experience in real-time programming.
I'd like to allocate memory using malloc( ) function which allocates it on the internal SRAM. Does anyone know how I could do dynamic memory allocation on the SDRAM?
Time is the fire in which we burn.
|
|
|
|
|
where else do you think you can dynamically allocate some memory ?
use malloc(), it will do the job for you, unless you use C++, then, use new instead.
but never forget : when you dynamically allocate some memory, you have to free it yourself, otherwise you'll get into memory leaks hell...
|
|
|
|
|
ohhhhh! nice memory leaks never clean it after yourself!
is in C++ 'new' is a stub to call 'malloc'. by the way malloc is much faster than 'new' when called several hundred times.
9ine
|
|
|
|
|
9ine wrote: by the way malloc is much faster than 'new' when called several hundred times
but non reentrant... so, bad !
|
|
|
|
|
toxcct wrote: where else do you think you can dynamically allocate some memory ?
In multiple heap scenarios you can define your own memory segments to specify which area of memory is used to allocate various elements such as messages, semaphores etc. I have a feeling that this is processor dependend and not something that I can do with C standard functions. Is there a way of doing this without depending on the platform being used? I realize that my previous question is not clear enough and I apologize for that. I must stress that this is a Real-Time programming related question.
Time is the fire in which we burn.
|
|
|
|
|
That is platform dependent.
|
|
|
|