Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to interact with Windows CE/PocketPC?

Tips -N- Tricks

How to interact with Windows CE/PocketPC?

by  wgcs  Posted    (Edited  )
You can fully interact with Windows CE / PocketPC from within VFP, even beyond the capabilities of ActiveSync.

You can write files, read files, copy & delete files, create databases, read databases, access the registry, execute programs, manipulate windows, and more!!

All the functions (as far as I know) for dealing with Windows CE are stored in RAPI.DLL. It seems that most, if not all, start with "Ce" when being executes as an RPC from the desktop/host Windows OS: though they may be documented as "WriteFile", it would be called from VFP as "CeWriteFile".

Many of these Api functions require Structures... for one example of how to use structures, see: http://fox.wikis.com/wc.dll?Wiki~ApiStructureClass

Here is an example of how to Write a text file to a Windows CE device (PocketPC runs on Windows CE):
Code:
* Author: William GC Steinford
*   Date: June 26, 2003
* Code to write a text file on device:
hnd=CeCreateFile('Storage Card\My Documents\Text\test.txt')
?hnd  
if hnd<>-1
  ?cewritefile(hnd,"Hello Windows CE!!")
  ?ceCloseHandle(hnd)
endif

* Api function wrappers follow:
FUNCTION CeCreateFile( pcName )
  DECLARE LONG CeCreateFile IN RAPI.DLL AS _ceCreateFile ;
    STRING @ LPCTSTR_lpFileName, ;
    LONG DWORD_dwDesiredAccess,  ;
    LONG DWORD_dwShareMode,      ;
    LONG Ignored_LPSECURITY_ATTRIBUTES_lpSecurityAttributes, ;
    LONG DWORD_dwCreationDispostion,  ;
    LONG DWORD_dwFlagsAndAttributes,  ;
    LONG Ignored_HANDLE_hTemplateFile
  LOCAL lnHnd, lcStr
  lcStr = StringToUnicode(pcName)
  lnHnd = _ceCreateFile( @lcStr, BitOr(GENERIC_READ,GENERIC_WRITE), ;
    0,0,CREATE_ALWAYS,0,0 )
  RETURN lnHnd
ENDFUNC
FUNCTION CeCloseHandle( pnHnd )
  DECLARE LONG CeCloseHandle IN RAPI.DLL AS _ceCloseHandle ;
    LONG nHnd
  RETURN _ceCloseHandle(pnHnd)=1
ENDFUNC
FUNCTION CeWriteFile( pnHnd, pcStr )
  DECLARE LONG CeWriteFile IN RAPI.DLL AS _ceWriteFile ;
    LONG     HANDLE_hFile, ;
    STRING @ LPCVOID_lpBuffer, ;
    LONG     DWORD_nNumberOfBytesToWrite, ;
    LONG   @ LPDWORD_lpNumberOfBytesWritten, ;
    LONG     Ignored_LPOVERLAPPED_lpOverlapped
  LOCAL lnWritten
  lnWritten = 0
  _ceWriteFile( pnHnd, @pcStr, len(pcStr), @lnWritten, 0 )
  RETURN lnWritten
ENDFUNC
PROCEDURE UnicodeToString( pcStr )
  LOCAL lcSkel
  lcSkel = StrConv( pcStr,  6 ) && Double Byte <- Unicode
  lcSkel = StrConv( lcSkel, 2 ) && Single byte <- Double Byte
  RETURN LEFT(lcSkel, MAX(AT(chr(0),lcSkel)-1,0) )
ENDPROC
PROCEDURE StringToUnicode( pcStr )
  LOCAL lcSkel
  lcSkel = StrConv( pcStr,  1 ) && Single byte -> Double Byte
  lcSkel = StrConv( lcSkel, 5 ) && Double Byte -> Unicode
  RETURN lcSkel+chr(0)
ENDPROC
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top