Embed Windows Internet Explorer

Marco Leise Marco.Leise at gmx.de
Thu Dec 19 11:18:33 PST 2013


Am Thu, 19 Dec 2013 17:36:57 +0000
schrieb Richard Webb <richard.webb at boldonjames.com>:

> On 18/12/2013 20:48, Andre wrote:
>  > => myURL.bstrVal = SysAllocString(cast(const(wchar*))url);
> 
> 
> Looks like the problem there is casting a string to a wchar* - I guess 
> the resulting BSTR will contain garbage instead of the intended value.
> 
> 
>  >
>  > It only works with statement:
>  > myURL.bstrVal = cast(wchar*)"http://www.google.de";
>  >
> 
> 
> Treating a wchar* as a BSTR might cause unexpected things to happen - 
> converting the string to a wchar* and then passing that to 
> SysAllocString would be safer.

Oh yes, you are right and I was totally ignorant of what a
BSTR is! It is a data structure for strings consisting of size
prefix for the character data (4 bytes), the character data as
wchars and a terminating zero wchar.

So your first approach was correct:

  string url = …;
  BSTR* bstrUrl = enforce(SysAllocString(toUTFz!(const(wchar)*)(url)),
                          "Out of memory or url is null");
  myURL.bstrVal = bstrUrl;

  …

  SysFreeString(bstrUrl);

-- 
Marco



More information about the Digitalmars-d-learn mailing list