|
I think that's what I'm doing, but I get compiler error C2228.
Jon
|
|
|
|
|
Just out of curiousity, is there some reason you are not using the string and list (or vector ) classes?
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
This is an academic assignment and the tutor discouraged me from using strings, because I can understand arrays of chars more easily I guess. I don't know what vectors are to be honest.
Jon
|
|
|
|
|
jon_80 wrote: This is an academic assignment and the tutor discouraged me from using strings, because I can understand arrays of chars more easily I guess.
Most likely, he (or she) wanted you to understand what actually goes on under the hood of the string class (and those like it). This isn't a bad thing, but you should remember that once you understand what it does, there is no need to reinvent the wheel, and doing so is actually bad practice.
edit: Is this code for an assignment? If so, what are the restrictions on the assignment?
jon_80 wrote: I don't know what vectors are to be honest.
A vector is nothing more than an array. The vector template class wraps an array so that you can dynamically add/remove elements in it without worrying about the details of memory allocation/deallocation for the array yourself.
-- modified at 13:41 Thursday 10th August, 2006
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Btw, any idea on how I can resolve it, please? I'm sorry but as you know I'm quite new to c++... no wonder everyone says it's 'techy' tho
Jon
|
|
|
|
|
Without seeing what else you have defined in your CSentenceList class, I can't even tell you if you are using a decent design.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
CSentenceList.h
---------------------------------------------------
class CSentenceList : CGenericList<char*>
{
public:
//Methods
CSentenceList(char strFileToRead[MAX_SENTENCE_LENGTH], bool bSorted = false);
virtual ~CSentenceList(void);
void sort();
unsigned int search(const char *strSearch);
CGenericList<char*> Sentences(); //linked list of sentences
//Properties
unsigned int Size;
private:
unsigned int searchInSentence(const char* sentence, const char* strSearch);
void CSentenceList::readFile(char strFileToRead[MAX_FILENAME_LENGTH]);
};
CSentenceList.cpp (extract)
---------------------------
SentenceList::CSentenceList(char strFileToRead[MAX_SENTENCE_LENGTH + 1], bool bSorted)
: CGenericList<char*> ()
...
void CSentenceList::readFile(char strFileToRead[MAX_FILENAME_LENGTH])
{
char strLine[MAX_SENTENCE_LENGTH + 1];
fstream fileToRead(strFileToRead,ios::in);
while (!fileToRead.eof() && Size < MAX_LINES)
// Read line of text from file and update Sentences.strSentence.
{ fileToRead.getline(strLine, MAX_SENTENCE_LENGTH);
Sentences.Insert(&strLine); //error C2228: left of '.Insert' must have class/struct/union type
Size++;
}
fileToRead.close();
}
Jon
|
|
|
|
|
Hi,
I'm using an active-x control to browse some web pages and part of what I need to do involves not letting it spawn IE windows if a link happens to want to navigate outside of my own browser window. I was finally able to use NewWindow2 to prevent it from spawning new windows, however it did not return the URL the link would have gone to, so I found that NewWindow3 could handle that. Per the docs (http://msdn.microsoft.com/workshop/browser/webbrowser/reference/ifaces/dwebbrowserevents2/newwindow3.asp) there is a BSTR flag that holds the URL of the link that is supposed to be opening. However when I capture the URL I am only getting a line of question marks (like ?????????????????????????????????) instead of the URL I need.
Can someone assist in figuring out how to use NewWindow3 so I can capture the proper URL of the link I click on?
Thanks in advance!
|
|
|
|
|
univega_r304 wrote: However when I capture the URL I am only getting a line of question marks (like ?????????????????????????????????) instead of the URL I need.
In a variable, or in the debug window?
"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
|
|
|
|
|
In a variable. This is the code I am using to test....
void CLoadWebSite::OnNewWindow3(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel, BSTR Flags, BSTR URLContext, BSTR URL)
{
// Convert BSTR to CSTring
CString url = "";
VARIANT vnt;
vnt.bstrVal = URL;
url = vnt.bstrVal;
*Cancel = TRUE; // Prevent IE spawning
AfxMessageBox(url); // display popup of url value.
Browser.Navigate(url,NULL,NULL,NULL,NULL); // navigate to url
}
I get the same value if cancel is set to true or false. If it's false, the IE window spawns to the proper link. Both ways the URL is not returned to my variable, it just appears as all question marks.
|
|
|
|
|
univega_r304 wrote: VARIANT vnt;
You need to set the vt member to VT_BSTR .
"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
|
|
|
|
|
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
|
|
|
|