Recent

Author Topic: ActiveX for WinCE (WM 6.5)  (Read 11334 times)

bambamns

  • Full Member
  • ***
  • Posts: 223
ActiveX for WinCE (WM 6.5)
« on: May 27, 2012, 02:58:18 pm »
Hi,

Is it possible to use this method http://wiki.freepascal.org/LazActiveX#TActiveXContainer_early_binding for WinCE to make WebBrowser (WM 6.5) ?

If not, how can it be done ?

Thx

« Last Edit: May 27, 2012, 08:18:48 pm by bambamns »
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: ActiveX for WinCE (WM 6.5)
« Reply #1 on: May 28, 2012, 04:38:10 pm »
Not yet.
There are some problems with cross-compiling the lazactivex package which I have solved. The Webbrowser runs but I have some problems with attaching the event sink. Don't know if this a problem linked to the WM6 emulator I'm using or something else. I'll have to try with other ActiveX components. Unfortunately I don't have a real device (other than an old PocketPC 2002).

Extracted the typelibs from browser.dll and webview.ddl and that seems to work fine. Note that a lot of the interfaces are different compared to the desktop.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: ActiveX for WinCE (WM 6.5)
« Reply #2 on: May 31, 2012, 08:41:05 pm »
Patches to lazarus and fpc have been made to make lazactivex work on WinCE. They can be found here:
http://bugs.freepascal.org/view.php?id=22152
http://bugs.freepascal.org/view.php?id=22156
http://bugs.freepascal.org/view.php?id=22157

You need to get the dll's from your WM device on your computer to create the typelib units. 

It also appears that the WM COM implementation has dropped some of the features found on the desktop. For example the use of onull Olevariant that is initialised to NULL in the Navigate2 call isn't working on WM. The function requires a var parameter but WM accepts or a nil address or a real value. So instead of the onull solution you have to use the ugly 'POleVariant(nil)^' as parameter for Navigate2.

If interested I can create a small demo similar to the one on the wiki page and attach the typelib units I obtained from WM 6.1 dll's.

bambamns

  • Full Member
  • ***
  • Posts: 223
Re: ActiveX for WinCE (WM 6.5)
« Reply #3 on: June 01, 2012, 08:36:32 pm »
Thx,

I have a few utilities written in Lazarus (win32) for access to web an read some PHP data, analyze it, and present to user only the most important information from page (content from page is always the same, there are only a few changes every day).

It will be very helpful to have an WinCE version and to do it I had to use activex like I use it on win32.
Application use Events OnNavigateComplete2 and OnDocumentComplete.

Quote
If interested I can create a small demo similar to the one on the wiki page and attach the typelib units I obtained from WM 6.1 dll's.

I'll like it a lot - it will be very helpful  ::)
If it is not a trouble, it will be helpful to write a few steps how to copy dll from WinCE and which one (couse I use WM 6.5).

Are those patches only for FPC 2.7.1 (a had a few problems when I'd used latest SVN and FPC 2.7.1 for WinCE - best result I'd reached ware with latest SVN and FPC 2.6.1) ?

Thank you.


« Last Edit: June 02, 2012, 06:02:31 am by bambamns »
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: ActiveX for WinCE (WM 6.5)
« Reply #4 on: June 02, 2012, 04:42:38 pm »
Quote
Are those patches only for FPC 2.7.1 (a had a few problems when I'd used latest SVN and FPC 2.7.1 for WinCE - best result I'd reached ware with latest SVN and FPC 2.6.1) ?
IIRC all patches so far related to ActiveX where back-ported to 2.6.1. So, yes, the patches should also work on 2.6.1.
For the missing stdole2 and eventsink units, you can just copy the source files from the fpc packages\winunits-base\src directory in your project directory. Make sure you apply the patch for eventsink though.

A small sample program to illustrate the use of the webbrowser on wince is attached. It navigates to a page stored in the file system and writes the urls received in OnNavigateComplete2 and OnDocumentComplete to a TMemo. Note the use of POleVariant(nil)^ to pass NULL values as var parameter. Using a variant initialised to NULL causes a 'invalid parameter error' which isn't a very useful message. Also the PIEWebBrowser class has IWebBrowser as the default interface and IWebBrowser2 as a hidden interface (IWebBrowser.Navigate versus IWebBrowser2.Navigate2). If you need to access  the IWebBrowser2 methods  or properties use something like this:
Code: [Select]
var
  ourl:Olevariant;
  Browser2:IWebBrowser2;
...
ourl:=Utf8decode('file://\Storage%20Card\readme.htm');
Browser2:=(Browser.ComServer as IWebBrowser2);
Browser2.Navigate2(ourl,polevariant(nil)^,polevariant(nil)^,polevariant(nil)^,polevariant(nil)^);

The zip file also contains PIEBrowser_1_0_TLB and WEBVIEWLib_2_0_TLB that correspond to the wm 6.1 browser.dll and webview.dll I got hold of. They'll probably work fine on wm6.5.

There is no easy way to get to the rom dll's. There are some utilities that allow you to extract files from ROM. Google is your best friend ;)


bambamns

  • Full Member
  • ***
  • Posts: 223
Re: ActiveX for WinCE (WM 6.5)
« Reply #5 on: June 02, 2012, 10:02:14 pm »
Thx,

It's working on WM 6.5, but ....

If I wont to read content of html on win32 I use :

Code: [Select]
Var Doc: IHTMLDocument2; <- this is from MSHTML_4_0_TLB - does WinCE has it ?

begin
  doc := Browser.ComServer.Document as IHTMLDocument2;
  memo2.lines.add(Doc.parentWindow.document.Get_body.innerText);

But on WinCE it's not working - on compile I get error - Identifier not found.

Thank you again, a lot.
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: ActiveX for WinCE (WM 6.5)
« Reply #6 on: June 03, 2012, 09:22:21 am »
Quote
Var Doc: IHTMLDocument2; <- this is from MSHTML_4_0_TLB - does WinCE has it ?
No. But I gave you also WEBVIEWLib_2_0_TLB which is the equivalent of MSHTML_4_0_TLB. As I noted before the interfaces are quite different on wince.
IHTMLDocument2 becomes IPIEHTMLDocument2
Get_body is not available in IPIEHTMLDocument2 but added in IPIEHTMLDocument4 so some runtime interface querying is needed (the 'as' operator). Runtime queries can fail. So good practice is to check if the interface exists before continuing.
Your code becomes:
Code: [Select]
var
  doc:IPIEHTMLDocument2;
begin
  doc := Browser.ComServer.Document as IPIEHTMLDocument2;
  Memo2.Lines.Add((doc.parentWindow.document as IPIEHTMLDocument4).body.innerText);
Note that on the WM6 emulator the call to 'body' (or Get_body) raises an Ole Exception. I also tried to get 'body' using variants (late binding) and the object doesn't seem to implement it. I did a quick Google on this problem and it seems there are dlls/roms around where 'body' indeed fails (http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesnative/thread/bef6dc38-0dd9-4f97-8813-efbcc7b16414)
Let me know if this works for you.

bambamns

  • Full Member
  • ***
  • Posts: 223
Re: ActiveX for WinCE (WM 6.5)
« Reply #7 on: June 04, 2012, 06:24:14 am »
Yes, thank you - it is working.

I had to copy oleserver.pp in project folder, because stdole2.pas is using it.
There is one duplicated property in line 1921 of VEBVIEW (I'd comment out it)
Code: [Select]
// property title:WideString writeonly dispid 4238;

Sometimes it reads text, sometimes it crash (like you wrote).

If you find way to fix reason for crashing, write it.

I noticed that
Code: [Select]
procedure TForm1.OnNavigateComplete2(Sender: TObject; pDisp: IDispatch;
  var pvtURL: OleVariant);
begin
  Memo1.Lines.Add('NavigateComplete2');
  label1.Caption := Browser.ComServer.LocationURL;
end;
is working and it gives some strange ascii strings beside url, but
Code: [Select]
procedure TForm1.OnStatusTextChange(Sender: TObject;Text_:WideString);
begin
  Label2.Caption := Text_;
end;
is not working at all.

I'll try to find browser.dll and webview.dll for WM 6.5 - maybe it will fix some things.
« Last Edit: June 04, 2012, 06:31:58 am by bambamns »
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: ActiveX for WinCE (WM 6.5)
« Reply #8 on: June 04, 2012, 08:35:44 am »
Quote
If you find way to fix reason for crashing, write it.
I did some further testing since the late binding crashing also is very suspect. Called the IDispatch functions directly (GetIDsOfNames and Invoke) for the body property. GetIDsOfNames returns the correct dispid but Invoke with the id and DISPATCH_PROPERTYGET is causing an unexepexted error. So I'm afraid there isn't very much else that can be done.
Quote
OnStatusTextChange ... is not working at all.
Yes. I traced all dispid's sent to the eventsink and none corresponds with OnStatusTextChange. There where a few unknown dispid's received but they don't correspond with OnStatusTextChange. OnStatusTextChange is triggered on a desktop when hovering over a link. On wince no event is received when doing so. Have you already seen a working status bar in the wince IE? Possibly the status message has to be enabled (similar to address bar).
Quote
I had to copy oleserver.pp in project folder, because stdole2.pas is using it.
There is one duplicated property in line 1921 of VEBVIEW (I'd comment out it)
OK. I'll look into that.
Quote
I'll try to find browser.dll and webview.dll for WM 6.5 - maybe it will fix some things.
One of the rules for COM is that interfaces can't change. So whatever is declared in the binding is correct. Possibly 6.5 defines new interfaces. I created also the tlb for 6.0 and in comparison with the 6.1 there are a few hundred new lines in 6.1 but I have found no changes in the existing ones.

bambamns

  • Full Member
  • ***
  • Posts: 223
Re: ActiveX for WinCE (WM 6.5)
« Reply #9 on: June 05, 2012, 05:56:13 am »
Quote
So I'm afraid there isn't very much else that can be done.
I hope there is - do you need some examples or anything that can help to solve this puzzle ?

Quote
Have you already seen a working status bar in the wince IE?
Your are write - there is no status bar.

Quote
Possibly the status message has to be enabled (similar to address bar).
No , there is not such a setting.

Quote
One of the rules for COM is that interfaces can't change.
Yes , I know ....

If you find any further fix/option for ActiveX on WinCE, please inform us.

Thank you.
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: ActiveX for WinCE (WM 6.5)
« Reply #10 on: June 05, 2012, 04:27:49 pm »
Finally got it working. The main problem was that I tried several things in OnNavigateComplete2 but the dom isn't completely parsed yet. The 'unspecified error' didn't help a lot there :(
In OnDocumentComplete the following works perfectly:
Code: [Select]
Memo2.Lines.Add((doc.parentWindow.document as IPIEHTMLDocument4).body.innerText);
or if you want the complete html
Code: [Select]
Memo2.Lines.Add((doc as IPIEHTMLDocument3).documentElement.innerHTML);

bambamns

  • Full Member
  • ***
  • Posts: 223
Re: ActiveX for WinCE (WM 6.5)
« Reply #11 on: June 05, 2012, 07:21:25 pm »
Yea, you are write.

I made button for reading inner text , but I didn't waited OnDocumetComplete to be fired.

It is ok Now, THX a lot

Keep good work
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified