Copying files to pda: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
mNo edit summary
(new category for pda code)
Line 87: Line 87:
Basically it initialises RAPI, creates the file on the PDA, reads from the local file and writes the file on the PDA!
Basically it initialises RAPI, creates the file on the PDA, reads from the local file and writes the file on the PDA!


[[Category:Code Examples]]
[[Category:Code Examples:PDA]]

Revision as of 12:17, 26 October 2006

Description

This script shows you how to "copy" a file from a desktop machine to a PDA using RAPI. This can be used to copy files other than .cab files. There are better ways to install cab files on a PDA, using CeAppMgr. To use this function you require the rapi.dll, which is installed along with ActiveSync.

The Function

Function createSettingsFile
  ;Init RAPI
 
  ;----------------------
  ;Dll Call Structure
  ;
  ;HRESULT CeRapiInit(void);
  System::Call "rapi::CeRapiInit() i .r0"
 
  ;Create the file on the PDA
 
  ;----------------------
  ;Dll Call Structure
  ;
  ;HANDLE CeCreateFile(
  ;  LPCWSTR lpFileName,
  ;  DWORD dwDesiredAccess,
  ;  DWORD dwShareMode,
  ;  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  ;  DWORD dwCreationDisposition,
  ;  DWORD dwFlagsAndAttributes,
  ;  HANDLE hTemplateFile
  ;);
  ;
  ; Access Mode Values :
  ;       GENERIC_READ = 0x80000000;
  ;       GENERIC_WRITE = 0x40000000;
  ;
  ; Creation Disposition Value :
  ;	CREATE_NEW = 1;
  ;	CREATE_ALWAYS = 2;
  ;	OPEN_EXISTING = 3;	
  ;
  ; Flag and attribute values
  ;	FILE_ATTRIBUTE_NORMAL = 0x80;
  ;	FILE_ATTRIBUTE_DIRECTORY = 0x10;
  ;	FILE_ATTRIBUTE_TEMPORARY = 0x100;
 
  System::Call "rapi::CeCreateFile(w '\filename.txt', i 0x80000000|0x40000000, i 0, i 0, i 2, i 0x80, i 0) i .r10"
 
  ;Write your data across. Can be done in a loop etc.
  FileOpen $0 'FileName' r
  IfErrors done
 
  FileRead $0 $1
 
  ;Get the length of the string read
  StrLen $2 $1
 
  ;----------------------
  ;Dll Call Structure
  ;
  ;BOOL CeWriteFile(
  ;  HANDLE hFile,
  ;  LPCVOID lpBuffer,
  ;  DWORD nNumberOfBytesToWrite,
  ;  LPDWORD lpNumberOfBytesWritten,
  ;  LPOVERLAPPED lpOverlapped
  ;);
  System::Call "rapi::CeWriteFile(i r10., t r1, i r2, i 0, i 0) i .r11"
 
  ;----------------------
  ;Dll Call Structure
  ;
  ;BOOL CeCloseHandle( 
  ;  HANDLE hObject
  ;); 
 
  done:
 
  ;Close the file on the PDA
  System::Call "rapi::CeCloseHandle(i r10) i .r1"
 
  ;Close the local file
  FileClose $0
 
  System::Free 0
FunctionEnd

Basically it initialises RAPI, creates the file on the PDA, reads from the local file and writes the file on the PDA!