Click to See Complete Forum and Search --> : IWebBrowser2 and BSTR problem


AltPluzF4
August 2nd, 2005, 07:09 PM
I am trying to get an element on a page with a toolbar, and I have it do
pID->get_name(&bstr);

I have tried several ways to compare the value of bstr to "passwd" in a if () statement....

What would be the correct way to compare the value of a bstr to text such as char pass[] = "test";

I had the if-else statement send a messagebox with the value of bstr, and it goes through all the wrong items, and then sends the "passwd", but it still accepts it as wrong... even though its the exact text im looking for...

So, I know the program is finding the item on the page, but it is not comparing it right...

Can anyone help me with this little problem? I am completly new to ATL stuff :-/

kirants
August 2nd, 2005, 07:31 PM
If using ATL, you can do this:

CComBSTR oBstr;
pID->get_name(&oBstr);

For conversion, see this article:
http://www.codeguru.com/Cpp/Cpp/string/conversions/article.php/c5639/

AltPluzF4
August 2nd, 2005, 07:44 PM
I'm not having any luck.... I have tried several conversions...

One problem is that I am not using MFC, so I can't use CString (at least, I don't know how to use it without mfc..)

Anyway, can you show me a small example similar to this, except one that works :p


//test
IHTMLInputTextElement* pID;
BSTR bstr;
pID->get_name(&bstr);

char pass[] = "Password";

//Do conversions or w/e
....
//Check if found Password Box
if (bstrConversion == passConversion)
MessageBox(_T("Found Password Box!"), _T("Success:"), MB_OK);
else
MessageBox(_T("Not Found!"), _T("Error:"), MB_OK);

pID->Release();


What would be the correct way to do this? Thanks for any help... This is driving me crazy... my only reference uses a CString instead of a char, and just does
CString pass = bstr;
but that won't work with my char, and I can't figure out how to use a CString in a ATL COM project :-/

Sorry for my ignorance, hope you can help! Thanks.

kirants
August 2nd, 2005, 08:09 PM
Just curious, doesn't this work ?

CComBSTR &bstr;
pID->get_name(&bstr);

CComBSTR &bstrComparison("Password");

//now compare
if(bstr == bstrComparison)
{
}

AltPluzF4
August 2nd, 2005, 08:30 PM
... I'm retarded... Thank you very much!

Just tested with success :D

kirants
August 2nd, 2005, 08:36 PM
U r welcome and good luck :wave: