www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Embed Windows Internet Explorer

reply Andre <andre s-e-a-p.de> writes:
Hi,

I try to embed Windows Internet Explorer into my application.
Most of the coding should be availabe. During method navigate2
I get an empty white screen. No errors is thrown but also the
web page is not loaded. Do you have some ideas?

=> Is use the windows headers from DSource and the dgui forms library.
I attached the source code.

Kind regards
André
Dec 16 2013
next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
I'm not able to run your code but are you sure the web page 
control is sized in your window? One time I had a problem like 
this and it was because the control was a 1x1 pixel...
Dec 17 2013
parent Andre <andre s-e-a-p.de> writes:
Am 17.12.2013 17:34, schrieb Adam D. Ruppe:
 I'm not able to run your code but are you sure the web page control is
 sized in your window? One time I had a problem like this and it was
 because the control was a 1x1 pixel...
I just checked, the dimensions of the main form are passed correctly to the IWebBrowser2 instance. GetClientRect(hwnd) is used and dimensions are evaluated correctly.
Dec 17 2013
prev sibling parent reply Andre <andre s-e-a-p.de> writes:
Am 16.12.2013 19:44, schrieb Andre:
 Hi,

 I try to embed Windows Internet Explorer into my application.
 Most of the coding should be availabe. During method navigate2
 I get an empty white screen. No errors is thrown but also the
 web page is not loaded. Do you have some ideas?

 => Is use the windows headers from DSource and the dgui forms library.
 I attached the source code.

 Kind regards
 André
The issue was related to SysAllocString: VARIANT myURL; VariantInit(&myURL); myURL.vt = cast(VARTYPE)VARENUM.VT_BSTR; => myURL.bstrVal = SysAllocString(cast(const(wchar*))url); webBrowser2.Navigate2( &myURL, null, null, null, null); It only works with statement: myURL.bstrVal = cast(wchar*)"http://www.google.de";
Dec 18 2013
next sibling parent reply Marco Leise <Marco.Leise gmx.de> writes:
Am Wed, 18 Dec 2013 21:48:30 +0100
schrieb Andre <andre s-e-a-p.de>:

 Am 16.12.2013 19:44, schrieb Andre:
 Hi,

 I try to embed Windows Internet Explorer into my application.
 Most of the coding should be availabe. During method navigate2
 I get an empty white screen. No errors is thrown but also the
 web page is not loaded. Do you have some ideas?

 =3D> Is use the windows headers from DSource and the dgui forms library.
 I attached the source code.

 Kind regards
 Andr=C3=A9
=20 The issue was related to SysAllocString: =20 VARIANT myURL; VariantInit(&myURL); myURL.vt =3D cast(VARTYPE)VARENUM.VT_BSTR; =3D> myURL.bstrVal =3D SysAllocString(cast(const(wchar*))url); webBrowser2.Navigate2( &myURL, null, null, null, null); =20 It only works with statement: myURL.bstrVal =3D cast(wchar*)"http://www.google.de";
Did you mean this?: myURL.bstrVal =3D "http://www.google.de"w.ptr; --=20 Marco
Dec 19 2013
parent reply Andre <andre s-e-a-p.de> writes:
Am 19.12.2013 10:58, schrieb Marco Leise:

 Did you mean this?:
    myURL.bstrVal = "http://www.google.de"w.ptr;
Exacactly. But if I have my url in a string variable, how can I get the wchar[].ptr from my string variable, to fill bstrVal?
Dec 19 2013
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Thursday, 19 December 2013 at 15:45:49 UTC, Andre wrote:
 Exacactly. But if I have my url in a string variable,
 how can I get the wchar[].ptr from my string variable,
 to fill bstrVal?
You can use wstring variables and convert them with import std.utf; wchar* str = toUTFz!(wchar*)(another_string_variable); then you can fill it. Or you can also do import std.conv; wstring ws = to!wstring(another_string_variable); The difference is the first one has a zero terminator, so you can easily pass it to C functions. The second one doesn't, but it is a D array so you can use .ptr and .length.
Dec 19 2013
parent Andre <andre s-e-a-p.de> writes:
Am 19.12.2013 16:54, schrieb Adam D. Ruppe:
 On Thursday, 19 December 2013 at 15:45:49 UTC, Andre wrote:
 Exacactly. But if I have my url in a string variable,
 how can I get the wchar[].ptr from my string variable,
 to fill bstrVal?
You can use wstring variables and convert them with import std.utf; wchar* str = toUTFz!(wchar*)(another_string_variable); then you can fill it. Or you can also do import std.conv; wstring ws = to!wstring(another_string_variable); The difference is the first one has a zero terminator, so you can easily pass it to C functions. The second one doesn't, but it is a D array so you can use .ptr and .length.
Thanks a lot! thats the solution
Dec 19 2013
prev sibling parent reply Richard Webb <richard.webb boldonjames.com> writes:
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.
Dec 19 2013
parent Marco Leise <Marco.Leise gmx.de> writes:
Am Thu, 19 Dec 2013 17:36:57 +0000
schrieb Richard Webb <richard.webb boldonjames.com>:

 On 18/12/2013 20:48, Andre wrote:
  > =3D> myURL.bstrVal =3D SysAllocString(cast(const(wchar*))url);
=20
=20
 Looks like the problem there is casting a string to a wchar* - I guess=20
 the resulting BSTR will contain garbage instead of the intended value.
=20
=20
  >
  > It only works with statement:
  > myURL.bstrVal =3D cast(wchar*)"http://www.google.de";
  >
=20
=20
 Treating a wchar* as a BSTR might cause unexpected things to happen -=20
 converting the string to a wchar* and then passing that to=20
 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 =3D =E2=80=A6; BSTR* bstrUrl =3D enforce(SysAllocString(toUTFz!(const(wchar)*)(url)), "Out of memory or url is null"); myURL.bstrVal =3D bstrUrl; =E2=80=A6 SysFreeString(bstrUrl); --=20 Marco
Dec 19 2013