Copying files to pda: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
(→‎The Function: loop added)
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== Description ==
== Description ==
This script shows you how to "copy" a file from a desktop machine to a PDA using RAPI.
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 ==
== The Function ==
Line 6: Line 6:
<highlight-nsis>
<highlight-nsis>
Function createSettingsFile
Function createSettingsFile
;Init RAPI
  ;Init RAPI


;----------------------
  ;----------------------
;Dll Call Structure
  ;Dll Call Structure
;
  ;
;HRESULT CeRapiInit(void);
  ;HRESULT CeRapiInit(void);
System::Call "rapi::CeRapiInit() i .r0"
  System::Call "rapi::CeRapiInit() i .r0"


;Create the file on the PDA
  ;Create the file on the PDA


;----------------------
  ;----------------------
;Dll Call Structure
  ;Dll Call Structure
;
  ;
;HANDLE CeCreateFile(
  ;HANDLE CeCreateFile(
;  LPCWSTR lpFileName,
  ;  LPCWSTR lpFileName,
;  DWORD dwDesiredAccess,
  ;  DWORD dwDesiredAccess,
;  DWORD dwShareMode,
  ;  DWORD dwShareMode,
;  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  ;  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
;  DWORD dwCreationDisposition,
  ;  DWORD dwCreationDisposition,
;  DWORD dwFlagsAndAttributes,
  ;  DWORD dwFlagsAndAttributes,
;  HANDLE hTemplateFile
  ;  HANDLE hTemplateFile
;);
  ;);
;
  ;
; Access Mode Values :
  ; Access Mode Values :
;      GENERIC_READ = 0x80000000;
  ;      GENERIC_READ = 0x80000000;
;      GENERIC_WRITE = 0x40000000;
  ;      GENERIC_WRITE = 0x40000000;
;
  ;
; Creation Disposition Value :
  ; Creation Disposition Value :
; CREATE_NEW = 1;
  ; CREATE_NEW = 1;
; CREATE_ALWAYS = 2;
  ; CREATE_ALWAYS = 2;
; OPEN_EXISTING = 3;
  ; OPEN_EXISTING = 3;
;
  ;
; Flag and attribute values
  ; Flag and attribute values
; FILE_ATTRIBUTE_NORMAL = 0x80;
  ; FILE_ATTRIBUTE_NORMAL = 0x80;
; FILE_ATTRIBUTE_DIRECTORY = 0x10;
  ; FILE_ATTRIBUTE_DIRECTORY = 0x10;
; FILE_ATTRIBUTE_TEMPORARY = 0x100;
  ; 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"
  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.
  ;Write your data across. Can be done in a loop etc.
FileOpen $0 'FileName' r
  FileOpen $0 'FileName' r
IfErrors done
  IfErrors done


FileRead $0 $1
loop:
  FileRead $0 $1
  IfErrors done


;Get the lenght of the string read
  ;Get the length of the string read
StrLen $2 $1
  StrLen $2 $1


;----------------------
  ;----------------------
;Dll Call Structure
  ;Dll Call Structure
;
  ;
;BOOL CeWriteFile(
  ;BOOL CeWriteFile(
;  HANDLE hFile,
  ;  HANDLE hFile,
;  LPCVOID lpBuffer,
  ;  LPCVOID lpBuffer,
;  DWORD nNumberOfBytesToWrite,
  ;  DWORD nNumberOfBytesToWrite,
;  LPDWORD lpNumberOfBytesWritten,
  ;  LPDWORD lpNumberOfBytesWritten,
;  LPOVERLAPPED lpOverlapped
  ;  LPOVERLAPPED lpOverlapped
;);
  ;);
System::Call "rapi::CeWriteFile(i r10., t r1, i r2, i 0, i 0) i .r11"
  System::Call "rapi::CeWriteFile(i r10., t r1, i r2, *i r3, i 0) i .r11"
  Goto loop


;----------------------
  ;----------------------
;Dll Call Structure
  ;Dll Call Structure
;
  ;
;BOOL CeCloseHandle(  
  ;BOOL CeCloseHandle(  
;  HANDLE hObject
  ;  HANDLE hObject
;);  
  ;);  


done:
  done:


;Close the file on the PDA
  ;Close the file on the PDA
System::Call "rapi::CeCloseHandle(i r10) i .r1"
  System::Call "rapi::CeCloseHandle(i r10) i .r1"


;Close the local file
  ;Close the local file
FileClose $0
  FileClose $0


System::Free 0
  System::Free 0
FunctionEnd
FunctionEnd
</highlight-nsis>
</highlight-nsis>


Basically it initialises RAPI, creates the file on the PDA, reads from the local file and writes the the file on the PDA!
Basically it initialises RAPI, creates the file on the PDA, reads line by line from the local file and writes the file on the PDA!
 
[[Category:PDA Examples]]

Latest revision as of 15:10, 1 December 2008

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
 
loop:
  FileRead $0 $1
  IfErrors done
 
  ;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 r3, i 0) i .r11"
  Goto loop
 
  ;----------------------
  ;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 line by line from the local file and writes the file on the PDA!