Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-11

Reading files in a Windows Mobile device.

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Arí Ricardo Ody

I need to copy a SQLite database from a iPAQ running Windows Mobile. I did this once using the RAPI.DLL but I was programming in C# under .NET Framework.

I would like to know if someone of you have did this even via RAPI.DLL or in another way and can give me an example.

In fact I have no idea of how to use RAPI.DLL(if it is the only way) in Lazarus since Lazarus is a pascal environment and RAPI.DLL tun in .NET Framework. Additionally I souppose that RAPI.DLL was write in C or C++.

Thanks in advance

Greetings from Sao Paulo - Brazil

Ricardo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111110/7cc0d61a/attachment.html>

Reply by email

Zaher Dirkey
to Arí Ricardo Ody

2011/11/10 "Ar? Ricardo Ody"

Show quoted text 12 lines
I need to copy a SQLite database from a iPAQ running Windows Mobile. I did this once using the RAPI.DLL but I was programming in C# under .NET Framework. I would like to know if someone of you have did this even via RAPI.DLL or in another way and can give me an example. In fact I have no idea of how to use RAPI.DLL(if it is the only way) in Lazarus since Lazarus is a pascal environment and RAPI.DLL tun in .NET Framework. Additionally I souppose that RAPI.DLL was write in C or C++.

I am not tested it yet, RAPI have functions on PC similar to the original functions, you can open and read files over ActiveSync from PC to WINCE

You need to cal the CeRapiInit once before use this functions

  function CeCloseHandle(hObject: THandle): bool; stdcall external
'rapi.dll';
  function CeCreateFile(lpFileName: LPCWSTR; dwDesiredAccess: dword;
dwShareMode: dword; lpSecurityAttributes: PSecurityAttributes;
dwCreationDistribution: dword; dwFlagsAndAttributes: dword; hTemplateFile:
THandle): THandle; stdcall external 'rapi.dll';
  function CeGetFileSize(hFile: THandle; lpFileSizeHigh: PDWORD): dword;
stdcall external 'rapi.dll';
  function CeGetLastError: dword; stdcall external 'rapi.dll';
  function CeRapiInitEx(var RapiInit: RapiInitRec): longint; stdcall
external 'rapi.dll';
  function CeRapiUninit: longint; external 'rapi.dll';
  function CeReadFile(hFile: THandle; const lpBuffer; nNumberOfBytesToRead:
dword; var NumberOfBytesRead :dword; Overlapped: POVERLAPPED): bool;
stdcall external 'rapi.dll';
procedure CeCopyDesktopToRemoteFile(FromFile, ToFile:string);
var
    BytesRead: DWord;
    BytesToRead: DWord;
    BytesWritten: DWord;
    FileBuffer: Pointer;
    FileSize: LongInt;
    HDes: THandle;
    HSrc: THandle;
begin
    HDes := CeCreateFile(PWideChar(ToFile), GENERIC_WRITE,
FILE_SHARE_WRITE, nil, CREATE_NEW, 0, 0);
    if (CeGetLastError = INVALID_HANDLE_VALUE) then
    begin
      ShowMessage('Error: Could not create local file.');
      Exit;
    end
    else if (CeGetLastError = ERROR_ALREADY_EXISTS) then
    begin
    end;
    HSrc := CreateFile(PChar(FromFile), GENERIC_READ, FILE_SHARE_READ, nil,
OPEN_EXISTING, 0, 0);
    if (GetLastError = INVALID_HANDLE_VALUE) then
    begin
      ShowMessage('Error: Could not open remote file.');
      Exit;
    end
    else if (GetLastError = ERROR_ALREADY_EXISTS) then begin
    end;
    FileSize := GetFileSize(HSrc, nil);
    if (FileSize = 4294967295) then
    begin
      ShowMessage('Error #' + IntToStr(CeGetLastError) + ': Could not
allocate file buffer.');
      Exit;
    end;
    BytesToRead := FileSize;
    FileBuffer := nil;
    GetMem(FileBuffer, 1000);
    BytesRead := 0;
    if not ReadFile(HSrc, FileBuffer^, 1000, BytesRead, nil) then
    begin
      ShowMessage('Error #' + IntToStr(GetLastError) + ': Could not read
local file.');
      Exit;
    end;
    BytesWritten := 0;
    if not CeWriteFile(HDes, FileBuffer, BytesRead, BytesWritten, nil) then
    begin
      ShowMessage('Error #' + IntToStr(CeGetLastError) + ': Could not write
the remote file.');
      Exit;
    end;
    CeCloseHandle(HDes);
    CloseHandle(HSrc);
    FreeMem(FileBuffer);
end;

Best Regards
Zaher Dirkey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111111/eb76f3fd/attachment.html>

Reply by email

Sven Barth
to Zaher Dirkey
Zaher Dirkey wrote
In fact I have no idea of how to use RAPI.DLL(if it is the only way) in Lazarus since Lazarus is a pascal environment and RAPI.DLL tun in .NET Framework. Additionally I souppose that RAPI.DLL was write in C or C++.

The RAPI DLL is a C DLL and for C DLLs you simply need to import the functions correctly, so that you can use it (see the example by Zaher). Otherwise you wouldn't be able to interface with other Windows DLLs like kernel32 as well. ;)

Show quoted text 5 lines
I am not tested it yet, RAPI have functions on PC similar to the original functions, you can open and read files over ActiveSync from PC to WINCE

At work we are using RAPI (with Free Pascal) extensively to copy a SQLite database from and to the device. I'm also using a little "cp" like tool to copy the freshly compiled program directly onto the device after compilation :)

Show quoted text 19 lines
You need to cal the CeRapiInit once before use this functions function CeCloseHandle(hObject: THandle): bool; stdcall external 'rapi.dll'; function CeCreateFile(lpFileName: LPCWSTR; dwDesiredAccess: dword; dwShareMode: dword; lpSecurityAttributes: PSecurityAttributes; dwCreationDistribution: dword; dwFlagsAndAttributes: dword; hTemplateFile: THandle): THandle; stdcall external 'rapi.dll'; function CeGetFileSize(hFile: THandle; lpFileSizeHigh: PDWORD): dword; stdcall external 'rapi.dll'; function CeGetLastError: dword; stdcall external 'rapi.dll'; function CeRapiInitEx(var RapiInit: RapiInitRec): longint; stdcall external 'rapi.dll'; function CeRapiUninit: longint; external 'rapi.dll'; function CeReadFile(hFile: THandle; const lpBuffer; nNumberOfBytesToRead: dword; var NumberOfBytesRead :dword; Overlapped: POVERLAPPED): bool; stdcall external 'rapi.dll';

[snip]

Please note that all RAPI functions are already available in the unit "rapi" which is normally compiled for Windows.

Regards,
Sven

Reply by email