Wiki Home

Pocket PCApi


Namespace: WIN_COM_API
Keywords: Remote Application Programming Interface (RAPI), Windows CE, Pocket PC.

Once a connection is established between a Windows CE-based device and the desktop computer, RAPI gives an application running on a desktop computer the ability to invoke function calls on a Windows CE–based platform. The desktop computer is the RAPI client and the Windows CE–based platform is the RAPI server.

Here is an example showing how to retrieve some system information from a Pocket PC connected to the local computer (connect it and run Active Sync first).
#DEFINE CSIDL_FAVORITES  0x0006
#DEFINE CSIDL_FONTS      0x0014
#DEFINE CSIDL_PERSONAL   0x0005
#DEFINE CSIDL_PROGRAMS   0x0002
#DEFINE CSIDL_RECENT     0x0008
#DEFINE CSIDL_STARTUP    0x0007
#DEFINE CSIDL_DRIVES     0x0011

WITH CREATEOBJECT("Trapi")
	IF NOT .connected
		= MESSAGEBOX("Mobile device is unavailable.     ",;
			48, "Error")
		RETURN
	ENDIF

	? "Version " + LTRIM(STR(.majorver)) + "." +;
		LTRIM(STR(.minorver)) + ". Build " + LTRIM(STR(.buildno))
	?
	? "*** Storage, bytes"
	? "Object Store:", TRANSFORM(.storesize, "999,999,999,999")
	? "Free Space:", TRANSFORM(.freesize, "999,999,999,999")
	?
	? "*** Physical Memory"
	? "Total:", TRANSFORM(.phmemtotal, "999,999,999,999")
	? "Available:", TRANSFORM(.phmemavail, "999,999,999,999")
	?
	? "*** CPU"
	? "Type:", .cputype
	? "Level:", .cpulevel
	? "Revision:", .cpurevision
	?
	? "*** Power Status"
	? "AC Power Status:", .aclinestatus
	? "Battery Flag:", .batteryflag
	? "Battery Life Percent:", .batterylifepercent
	?
	? "*** Some Special Folders"
	? .GetSpecialFolderPath(CSIDL_PROGRAMS)
	? .GetSpecialFolderPath(CSIDL_PERSONAL)
	? .GetSpecialFolderPath(CSIDL_FAVORITES)
ENDWITH
* end of main

DEFINE CLASS Trapi As Custom
#DEFINE ERROR_SUCCESS 0
	majorver=0
	minorver=0
	buildno=0
	aclinestatus=0
	batteryflag=0
	batterylifepercent=0
	storesize=0
	freesize=0
	phmemtotal=0
	phmemavail=0
	cputype=0
	cpulevel=0
	cpurevision=0
	connected=.F.

PROCEDURE Init
	THIS.decl
	IF THIS.InitRapi()
		THIS.GetPowerStatus
		THIS.GetStoreSize
		THIS.GetGlobalMemoryStatus
		THIS.GetCPUInfo
	ENDIF
	
PROCEDURE InitRapi
#DEFINE RAPIINIT_SIZE  12
#DEFINE WAIT_OBJECT_0  0
	THIS.UninitRapi

	LOCAL cBuffer, hEvent
	cBuffer = PADR(CHR(RAPIINIT_SIZE), RAPIINIT_SIZE, CHR(0))

	= CeRapiInitEx(@cBuffer)
	hEvent = buf2dword(SUBSTR(cBuffer,5,4))

	IF WaitForSingleObject(hEvent,2000) = WAIT_OBJECT_0
		THIS.connected = .T.
	ELSE
		THIS.UninitRapi
	ENDIF
RETURN THIS.connected

PROCEDURE UninitRapi
	= CeRapiUninit()
	THIS.connected = .F.

PROCEDURE Destroy
	THIS.UninitRapi

PROCEDURE GetVersion
#DEFINE CEOSVERSIONINFO_SIZE 276
	LOCAL cBuffer, hBuffer
	cBuffer = PADR(num2dword(CEOSVERSIONINFO_SIZE),;
		CEOSVERSIONINFO_SIZE, Chr(0))
	= CeGetVersionEx(@cBuffer)
	THIS.majorver = buf2dword(SUBSTR(cBuffer, 5,4))
	THIS.minorver = buf2dword(SUBSTR(cBuffer, 9,4))
	THIS.buildno = buf2dword(SUBSTR(cBuffer, 13,4))

FUNCTION GetSpecialFolderPath(nFolder)
	LOCAL nBufsize, cBuffer
	nBufsize = 250
	cBuffer = REPLICATE(CHR(0), nBufsize*2)
	nBufsize = CeGetSpecialFolderPath(nFolder, nBufsize, @cBuffer)
RETURN STRCONV(SUBSTR(cBuffer, 1,nBufsize*2),6)

PROCEDURE GetPowerStatus
#DEFINE SYSTEM_POWER_STATUS 24
	LOCAL cBuffer
	cBuffer = REPLICATE(CHR(0), SYSTEM_POWER_STATUS)
	= CeGetSystemPowerStatusEx(@cBuffer, 0)
	THIS.aclinestatus = ASC(SUBSTR(cBuffer,1,1))
	THIS.batteryflag = ASC(SUBSTR(cBuffer,2,1))
	THIS.batterylifepercent = ASC(SUBSTR(cBuffer,3,1))

PROCEDURE GetStoreSize
#DEFINE STORE_INFORMATION_SIZE 8
	LOCAL cBuffer
	cBuffer = Repli(Chr(0), STORE_INFORMATION_SIZE)
	= CeGetStoreInformation(@cBuffer)
	THIS.storesize = buf2dword(SUBSTR(cBuffer, 1,4))
	THIS.freesize = buf2dword(SUBSTR(cBuffer, 5,4))

PROCEDURE GetGlobalMemoryStatus
#DEFINE MEMORYSTATUS_SIZE 32
	LOCAL cBuffer
	cBuffer = PADR(CHR(MEMORYSTATUS_SIZE), MEMORYSTATUS_SIZE, CHR(0))
	= CeGlobalMemoryStatus(@cBuffer)
	THIS.phmemtotal = buf2dword(SUBSTR(cBuffer, 9,4))
	THIS.phmemavail = buf2dword(SUBSTR(cBuffer, 13,4))

PROCEDURE GetCPUInfo
#DEFINE SYSTEM_INFO_SIZE 36
	LOCAL cBuffer
	cBuffer = PADR(CHR(SYSTEM_INFO_SIZE), SYSTEM_INFO_SIZE, CHR(0))
	= CeGetSystemInfo(@cBuffer)
	THIS.cputype = buf2dword(SUBSTR(cBuffer, 25,4))
	THIS.cpulevel = buf2word(SUBSTR(cBuffer, 33,2))
	THIS.cpurevision = buf2word(SUBSTR(cBuffer, 35,2))

PROCEDURE decl
	DECLARE INTEGER CeRapiUninit IN rapi
	DECLARE INTEGER CeRapiInitEx IN rapi STRING @pRapiInit
	DECLARE INTEGER CeGetVersionEx IN rapi STRING @lpVersionInformation
	DECLARE INTEGER CeGetStoreInformation IN rapi STRING @lpsi
	DECLARE CeGlobalMemoryStatus IN rapi STRING @lpmst
	DECLARE CeGetSystemInfo IN rapi STRING @lpSystemInfo

	DECLARE INTEGER CeGetSystemPowerStatusEx IN rapi;
		STRING @pstatus, INTEGER fUpdate

	DECLARE INTEGER CeGetSpecialFolderPath IN rapi;
		INTEGER nFolder, INTEGER nBufferLength, STRING @lpBuffer

	DECLARE INTEGER WaitForSingleObject IN kernel32;
		INTEGER hHandle, INTEGER dwMilliseconds
ENDDEFINE

FUNCTION buf2dword(lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
	BitLShift(Asc(SUBSTR(lcBuffer, 2,1)),  8) +;
	BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +;
	BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)

FUNCTION buf2word(lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
       Asc(SUBSTR(lcBuffer, 2,1)) * 256

FUNCTION num2dword(lnValue)
#DEFINE m0  256
#DEFINE m1  65536
#DEFINE m2  16777216
	IF lnValue < 0
		lnValue = 0x100000000 + lnValue
	ENDIF
	LOCAL b0, b1, b2, b3
	b3 = Int(lnValue/m2)
	b2 = Int((lnValue - b3*m2)/m1)
	b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
	b0 = Mod(lnValue, m0)
RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)

Original link: http://www.news2news.com/vfp/?example=440
-- Anatoliy Mogylevets
Category PDA Active Sync
( Topic last updated: 2004.06.25 12:56:59 PM )