Thread overview | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
December 16, 2013 Embed Windows Internet Explorer | ||||
---|---|---|---|---|
| ||||
Attachments: | 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é |
December 17, 2013 Re: Embed Windows Internet Explorer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | 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... |
December 17, 2013 Re: Embed Windows Internet Explorer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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.
|
December 18, 2013 Re: Embed Windows Internet Explorer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | 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"; |
December 19, 2013 Re: Embed Windows Internet Explorer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | 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? > > > > => 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"; Did you mean this?: myURL.bstrVal = "http://www.google.de"w.ptr; -- Marco |
December 19, 2013 Re: Embed Windows Internet Explorer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marco Leise | 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?
|
December 19, 2013 Re: Embed Windows Internet Explorer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | 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. |
December 19, 2013 Re: Embed Windows Internet Explorer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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
|
December 19, 2013 Re: Embed Windows Internet Explorer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | 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. |
December 19, 2013 Re: Embed Windows Internet Explorer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard Webb | Am Thu, 19 Dec 2013 17:36:57 +0000 schrieb Richard Webb <richard.webb@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 |
Copyright © 1999-2021 by the D Language Foundation