[Lazarus] Reading files in a Windows Mobile device.
Zaher Dirkey
parmaja at gmail.com
Thu Nov 10 23:57:45 CET 2011
2011/11/10 "ArĂ Ricardo Ody" <aro52 at gmx.com>
> 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-ide.org/pipermail/lazarus/attachments/20111111/eb76f3fd/attachment-0003.html>
More information about the Lazarus
mailing list