<div dir="ltr"><div class="gmail_quote">2011/11/10 "Arí Ricardo Ody" <span dir="ltr"><<a href="mailto:aro52@gmx.com">aro52@gmx.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<span style="font-family:Verdana"><span style="font-size:12px"><div> 
        <span style="font-family:Verdana"><span style="font-size:12px"><span style="font-family:verdana"><span style="font-size:12px">I need to copy a SQLite database</span></span> from a iPAQ running Windows Mobile. I did this once using the RAPI.DLL but I was programming in C# under .NET Framework.<br>
 
        <br> 
        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.<br> 
        <br> 
        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++.<br> 
        <br></span></span></div></span></span></blockquote><div><br>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<br><br>You need to cal the CeRapiInit once before use this functions<br>
<br>  function CeCloseHandle(hObject: THandle): bool; stdcall external 'rapi.dll';<br>  function CeCreateFile(lpFileName: LPCWSTR; dwDesiredAccess: dword; dwShareMode: dword; lpSecurityAttributes: PSecurityAttributes; dwCreationDistribution: dword; dwFlagsAndAttributes: dword; hTemplateFile: THandle): THandle; stdcall external 'rapi.dll';<br>
  function CeGetFileSize(hFile: THandle; lpFileSizeHigh: PDWORD): dword; stdcall external 'rapi.dll';<br>  function CeGetLastError: dword; stdcall external 'rapi.dll';<br>  function CeRapiInitEx(var RapiInit: RapiInitRec): longint; stdcall external 'rapi.dll';<br>
  function CeRapiUninit: longint; external 'rapi.dll';<br>  function CeReadFile(hFile: THandle; const lpBuffer; nNumberOfBytesToRead: dword; var NumberOfBytesRead :dword; Overlapped: POVERLAPPED): bool; stdcall external 'rapi.dll';<br>
<br>procedure CeCopyDesktopToRemoteFile(FromFile, ToFile:string);<br>var<br>    BytesRead: DWord;<br>    BytesToRead: DWord;<br>    BytesWritten: DWord;<br>    FileBuffer: Pointer;<br>    FileSize: LongInt;<br>    HDes: THandle;<br>
    HSrc: THandle;<br>begin<br>    HDes := CeCreateFile(PWideChar(ToFile), GENERIC_WRITE, FILE_SHARE_WRITE, nil, CREATE_NEW, 0, 0);<br>    if (CeGetLastError = INVALID_HANDLE_VALUE) then<br>    begin<br>      ShowMessage('Error: Could not create local file.');<br>
      Exit;<br>    end<br>    else if (CeGetLastError = ERROR_ALREADY_EXISTS) then<br>    begin<br>    end;<br><br>    HSrc := CreateFile(PChar(FromFile), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0);<br><br>    if (GetLastError = INVALID_HANDLE_VALUE) then<br>
    begin<br>      ShowMessage('Error: Could not open remote file.');<br>      Exit;<br>    end<br>    else if (GetLastError = ERROR_ALREADY_EXISTS) then begin<br>    end;<br><br>    FileSize := GetFileSize(HSrc, nil);<br>
    if (FileSize = 4294967295) then<br>    begin<br>      ShowMessage('Error #' + IntToStr(CeGetLastError) + ': Could not allocate file buffer.');<br>      Exit;<br>    end;<br><br>    BytesToRead := FileSize;<br>
<br>    FileBuffer := nil;<br><br>    GetMem(FileBuffer, 1000);<br><br>    BytesRead := 0;<br>    if not ReadFile(HSrc, FileBuffer^, 1000, BytesRead, nil) then<br>    begin<br>      ShowMessage('Error #' + IntToStr(GetLastError) + ': Could not read local file.');<br>
      Exit;<br>    end;<br><br>    BytesWritten := 0;<br>    if not CeWriteFile(HDes, FileBuffer, BytesRead, BytesWritten, nil) then<br>    begin<br>      ShowMessage('Error #' + IntToStr(CeGetLastError) + ': Could not write the remote file.');<br>
      Exit;<br>    end;<br><br>    CeCloseHandle(HDes);<br>    CloseHandle(HSrc);<br>    FreeMem(FileBuffer);<br>end;<br><br></div></div><div dir="ltr">Best Regards<br>Zaher Dirkey</div><br>
</div>