summaryrefslogtreecommitdiff
path: root/packages/winceunits/src
diff options
context:
space:
mode:
authoryury <yury@3ad0048d-3df7-0310-abae-a5850022a9f2>2008-05-09 15:25:28 +0000
committeryury <yury@3ad0048d-3df7-0310-abae-a5850022a9f2>2008-05-09 15:25:28 +0000
commit1e0b05f9ae7ceced22f75ea89a8b8c3bbd54b098 (patch)
tree1aafd14edcebbbe4e53a8ce8afb25f81fa847d7d /packages/winceunits/src
parente047317dafeafc0527b1c9d85d8113e5140e9c3f (diff)
downloadfpc-1e0b05f9ae7ceced22f75ea89a8b8c3bbd54b098.tar.gz
* Windows unit additions by Vasil.
+ msgqueue, pm, service, winioctl header translations by Vasil. git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@10914 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/winceunits/src')
-rw-r--r--packages/winceunits/src/buildwinceunits.pp2
-rw-r--r--packages/winceunits/src/msgqueue.pp83
-rw-r--r--packages/winceunits/src/pm.pp363
-rw-r--r--packages/winceunits/src/service.pp298
-rw-r--r--packages/winceunits/src/winioctl.pp153
5 files changed, 898 insertions, 1 deletions
diff --git a/packages/winceunits/src/buildwinceunits.pp b/packages/winceunits/src/buildwinceunits.pp
index a81050ddac..74ba226c9c 100644
--- a/packages/winceunits/src/buildwinceunits.pp
+++ b/packages/winceunits/src/buildwinceunits.pp
@@ -22,7 +22,7 @@ interface
uses
aygshell,commctrl,commdlg,iphlpapi,notify,oleaut32,power,shellapi,simmgr,tapi,
- gpsapi,todaycmn,windbase,cesync,gx;
+ gpsapi,todaycmn,windbase,cesync,gx,winioctl,msgqueue,pm,service;
implementation
diff --git a/packages/winceunits/src/msgqueue.pp b/packages/winceunits/src/msgqueue.pp
new file mode 100644
index 0000000000..8819d37763
--- /dev/null
+++ b/packages/winceunits/src/msgqueue.pp
@@ -0,0 +1,83 @@
+{
+ This file is part of the Free Pascal run time library.
+ Copyright (c) 2008 Free Pascal development team.
+
+ See the file COPYING.FPC, included in this distribution,
+ for details about the copyright.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ ********************************************************************** }
+//
+// msgqueue.h - Message queue point-to-point.
+//
+
+//
+// Microsoft Windows Mobile 6.0 for PocketPC SDK.
+//
+
+unit MsgQueue;
+
+{$CALLING cdecl}
+
+interface
+
+uses Windows;
+
+// Declarations of constants and structures transferred from winbase.h.
+
+const
+ MSGQUEUE_NOPRECOMMIT = $00000001;
+ MSGQUEUE_ALLOW_BROKEN = $00000002;
+
+ MSGQUEUE_MSGALERT = $00000001;
+
+
+type
+ MSGQUEUEOPTIONS_OS = record
+ dwSize:DWORD; // size of the structure
+ dwFlags:DWORD; // behavior of message queue
+ dwMaxMessages:DWORD; // max # of msgs in queue
+ cbMaxMessage:DWORD; // max size of msg
+ bReadAccess:BOOL; // read access requested
+ end;
+ MSGQUEUEOPTIONS = MSGQUEUEOPTIONS_OS;
+ LPMSGQUEUEOPTIONS = ^MSGQUEUEOPTIONS_OS;
+ PMSGQUEUEOPTIONS = ^MSGQUEUEOPTIONS_OS;
+
+type
+ MSGQUEUEINFO = record
+ dwSize:DWORD; // size of structure
+ dwFlags:DWORD; // behavior of message queue
+ dwMaxMessages:DWORD; // max # of msgs in queue
+ cbMaxMessage:DWORD; // max size of msg
+ dwCurrentMessages:DWORD; // # of message in queue currently
+ dwMaxQueueMessages:DWORD; // high water mark of queue
+ wNumReaders:word; // # of readers
+ wNumWriters:word; // # of writes
+ end;
+ PMSGQUEUEINFO = ^MSGQUEUEINFO;
+ LPMSGQUEUEINFO = ^MSGQUEUEINFO;
+
+
+function CreateMsgQueue(lpName:LPCWSTR; lpOptions:LPMSGQUEUEOPTIONS):HANDLE; external KernelDLL name 'CreateMsgQueue'; // index 111
+function OpenMsgQueue(hSrcProc:HANDLE; hMsgQ:HANDLE; lpOptions:LPMSGQUEUEOPTIONS):HANDLE; external KernelDLL name 'OpenMsgQueue'; // index 116
+function ReadMsgQueue(hMsgQ:HANDLE;
+ lpBuffer:LPVOID;
+ cbBufferSize:DWORD;
+ lpNumberOfBytesRead:LPDWORD;
+ dwTimeout:DWORD;
+ pdwFlags:LPDWORD):BOOL; external KernelDLL name 'ReadMsgQueue'; // index 112
+function WriteMsgQueue(hMsgQ:HANDLE;
+ lpBuffer:LPVOID;
+ cbDataSize:DWORD;
+ dwTimeout:DWORD;
+ dwFlags:DWORD):BOOL; external KernelDLL name 'WriteMsgQueue'; // index 113
+function GetMsgQueueInfo(hMsgQ:HANDLE; lpInfo:LPMSGQUEUEINFO):BOOL; external KernelDLL name 'GetMsgQueueInfo'; // index 114
+function CloseMsgQueue(hMsgQ:HANDLE):BOOL; external KernelDLL name 'CloseMsgQueue'; // index 115
+
+implementation
+
+end. \ No newline at end of file
diff --git a/packages/winceunits/src/pm.pp b/packages/winceunits/src/pm.pp
new file mode 100644
index 0000000000..7659c91f9e
--- /dev/null
+++ b/packages/winceunits/src/pm.pp
@@ -0,0 +1,363 @@
+{
+ This file is part of the Free Pascal run time library.
+ Copyright (c) 2008 Free Pascal development team.
+
+ See the file COPYING.FPC, included in this distribution,
+ for details about the copyright.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ ********************************************************************** }
+//
+// Module Name:
+//
+// pm.h
+//
+// Abstract:
+//
+// Definitions and API for the WCE Power Manager component.
+//
+
+//
+// Microsoft Windows Mobile 6.0 for PocketPC SDK.
+//
+
+unit PM;
+
+{$CALLING cdecl}
+
+interface
+
+uses Windows, WinIOCtl;
+
+//**********************************************************************
+// WinCE Device Interface GUIDs for Power Manager controlled devices.
+// NEVER CHANGE THESE VALUES! They indicate that a device is
+// power manageable. The device MUST expose an appropriate class
+// via the IClass registry key or the AdvertiseInterface() API to
+// receive power management IOCTLs. For example,
+// "IClass"=multi_sz:"{A32942B7-920C-486b-B0E6-92A702A99B35}"
+// OEMs may define other classes in addition to the ones listed here.
+//**********************************************************************
+const
+ PMCLASS_GENERIC_DEVICE = '{A32942B7-920C-486B-B0E6-92A702A99B35}';
+ PMCLASS_NDIS_MINIPORT = '{98C5250D-C29A-4985-AE5F-AFE5367E5006}';
+ PMCLASS_BLOCK_DEVICE = '{8DD679CE-8AB4-43C8-A14A-EA4963FAA715}';
+ PMCLASS_DISPLAY = '{EB91C7C9-8BF6-4A2D-9AB8-69724EED97D1}';
+
+// backwards compatibility definitions from the PM's CE .NET release
+ DEVCLASS_POWER_MANAGER_STRING = PMCLASS_GENERIC_DEVICE;
+ DEVCLASS_POWER_MANAGER_GUID:GUID = (D1: $A32942B7; D2: $920C; D3: $486B; D4: ($B0, $E6, $92, $A7, $02, $A9, $9B, $35));
+// DEVCLASS_POWER_MANAGER_GUID:GUID = '{A32942B7-920C-486B-B0E6-92A702A99B35));
+
+
+//*****************************************************************************
+// D E F I N E S
+//*****************************************************************************
+
+// Power Manager's System Power key
+const
+ PWRMGR_REG_KEY = 'SYSTEM\CurrentControlSet\Control\Power';
+ PM_SUPPORT_PB_RELEASE = 'SupportPowerButtonRelease';
+
+//
+// System Power (Source/State/Option) Flags
+//
+
+// upper bytes: common power state bits
+function POWER_STATE(f:DWORD):DWORD; // power state mask
+
+const
+
+
+ POWER_STATE_ON = $00010000; // on state
+ POWER_STATE_OFF = $00020000; // no power, full off
+ POWER_STATE_CRITICAL = $00040000; // critical off
+ POWER_STATE_BOOT = $00080000; // boot state
+ POWER_STATE_IDLE = $00100000; // idle state
+ POWER_STATE_SUSPEND = $00200000; // suspend state
+ POWER_STATE_UNATTENDED = $00400000; // Unattended state.
+ POWER_STATE_RESET = $00800000; // reset state
+ POWER_STATE_USERIDLE = $01000000; // user idle state
+ POWER_STATE_BACKLIGHTON = $02000000; // device scree backlight on
+ POWER_STATE_PASSWORD = $10000000; // This state is password protected.
+
+ PM_DEFAULT_SZ = 'Default';
+ PM_FLAGS_SZ = 'Flags';
+ MAX_STATE_NAMEL = MAX_PATH; // max system power state name length
+
+//
+// Power Requirement Flags
+//
+const
+ POWER_NAME = $00000001; // default
+ POWER_FORCE = $00001000;
+ POWER_DUMPDW = $00002000;// Calling CaptureDumpFileOnDevice() before entering this state.
+
+//
+// POWER IOCTLS
+//
+// We are NOT APCI, we just borrow this unused code from winioctl.h
+const
+ FILE_DEVICE_POWER = FILE_DEVICE_ACPI;
+
+{
+Required
+InBuf: PPOWER_RELATIONSHIP - defines the target device for parent/bus drivers, else NULL
+OutBuf: PPOWER_CAPABILITIES - defines the devices power caps
+
+If a driver fails this ioctl the PM assumes the target driver does not support power ioctls.
+}
+const
+ IOCTL_POWER_CAPABILITIES = (FILE_DEVICE_POWER shl 16) or ($400 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+{ ++
+Required
+InBuf: PPOWER_RELATIONSHIP - defines the target device for parent/bus drivers, else NULL
+OutBuf: PCEDEVICE_POWER_STATE - returns the device's current state (Dx).
+
+PM will only send this ioctl to drivers that support the power ioctls.
+-- }
+const
+ IOCTL_POWER_GET = (FILE_DEVICE_POWER shl 16) or ($401 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+{ ++
+Required
+InBuf: PPOWER_RELATIONSHIP - defines the target device for parent/bus drivers, else NULL
+OutBuf: PCEDEVICE_POWER_STATE - device state (Dx) in which to put the device.
+
+If the driver does not support the proposed Dx then it should write it's adjusted Dx
+into the OutBuf (Dx).
+
+PM will only send this ioctl to drivers that support the power ioctls.
+-- }
+const
+ IOCTL_POWER_SET = (FILE_DEVICE_POWER shl 16) or ($402 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+{++
+Required
+InBuf: PPOWER_RELATIONSHIP - defines the target device for parent/bus drivers, else NULL
+OutBuf: PCEDEVICE_POWER_STATE - device state (Dx) that the system is querying for a
+ pending IOCTL_POWER_SET operation.
+
+To veto the query the driver should write PwrDeviceUnspecified (-1)
+into the OutBuf (Dx), else PM assumes the driver accepted.
+
+PM will only send this ioctl to drivers that support the power ioctls.
+-- }
+const
+ IOCTL_POWER_QUERY = (FILE_DEVICE_POWER shl 16) or ($403 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+{
+Required
+InBuf: NULL
+OutBuf: NULL
+
+PM does not care the return value from this IOCTL. It's there to let the Parent device
+to register all devices it controls.
+}
+const
+ IOCTL_REGISTER_POWER_RELATIONSHIP = (FILE_DEVICE_POWER shl 16) or ($406 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//*****************************************************************************
+// T Y P E D E F S
+//*****************************************************************************
+
+//
+// Device Power States
+//
+type
+ _CEDEVICE_POWER_STATE = (PwrDeviceUnspecified := -1,
+ D0 := 0, // Full On: full power, full functionality
+ D1, // Low Power On: fully functional at low power/performance
+ D2, // Standby: partially powered with automatic wake
+ D3, // Sleep: partially powered with device initiated wake
+ D4, // Off: unpowered
+ PwrDeviceMaximum
+ );
+ CEDEVICE_POWER_STATE = _CEDEVICE_POWER_STATE;
+ PCEDEVICE_POWER_STATE = ^_CEDEVICE_POWER_STATE;
+
+function DX_MASK(Dx:DWORD):DWORD;
+
+function VALID_DX(dx:DWORD):BOOL;
+
+//
+// Device or OAL Power Capabilities
+//
+type
+ _POWER_CAPABILITIES = record
+ DeviceDx:UCHAR;
+ WakeFromDx:UCHAR;
+ InrushDx:UCHAR;
+ Power:array[0..DWORD(PwrDeviceMaximum)-1] of DWORD;
+ Latency:array[0..DWORD(PwrDeviceMaximum)-1] of DWORD;
+ Flags:DWORD;
+ end;
+ POWER_CAPABILITIES = _POWER_CAPABILITIES;
+ PPOWER_CAPABILITIES = ^_POWER_CAPABILITIES;
+
+const
+ POWER_CAP_PARENT = $00000001; // parent/bus driver
+
+//
+// Defines the target of IOCTL_POWER_Xxx commands to parent/bus drivers
+// if there is a relationship established via RegisterPowerRelationship.
+//
+type
+ _POWER_RELATIONSHIP = record
+ hParent:HANDLE; // Handle to parent node
+ pwsParent:LPCWSTR; // Named parent node, e.g. "NDS0:"
+ hChild:HANDLE; // Handle to child node, returned from RegisterPowerRelationship
+ pwsChild:LPCWSTR; // Named child node, e.g. "NE20001"
+ end;
+ POWER_RELATIONSHIP = _POWER_RELATIONSHIP;
+ PPOWER_RELATIONSHIP = ^_POWER_RELATIONSHIP;
+
+
+//
+// Power Broadcast Types -- there are up to 32 of these
+//
+const
+ PBT_TRANSITION = $00000001; // broadcast specifying system power state transition
+ PBT_RESUME = $00000002; // broadcast notifying a resume, specifies previous state
+ PBT_POWERSTATUSCHANGE = $00000004; // power supply switched to/from AC/DC
+ PBT_POWERINFOCHANGE = $00000008; // some system power status field has changed
+
+ PBT_SUSPENDKEYPRESSED = $00000100; // Suspend Key has been pressed.
+
+// OEMS may define power notifications starting with this ID and
+// going up by powers of 2.
+ PBT_OEMBASE = $00010000;
+
+// This bitmask indicates that an application would like to receive all
+// types of power notifications.
+const
+ POWER_NOTIFY_ALL = $FFFFFFFF;
+
+//
+// Power Broadcast -- this is a variable length structure.
+//
+type
+ _POWER_BROADCAST = record
+ _Message:DWORD; // one of PBT_Xxx
+ Flags:DWORD; // one of POWER_STATE_Xxx
+ Length:DWORD; // byte count of data starting at SystemPowerStateName
+ SystemPowerState:array[0..0] of WideChar; // variable length field, must be smaller than MAX_PATH + 1
+ end;
+ POWER_BROADCAST = _POWER_BROADCAST;
+ PPOWER_BROADCAST = ^_POWER_BROADCAST;
+
+// This structure is used instead of a string name (SystemPowerState) in
+// the POWER_BROADCAST, if the broadcast is of type PBT_POWERINFOCHANGE.
+//
+// For example:
+// PPOWER_BROADCAST ppb;
+// PPOWER_BROADCAST_POWER_INFO ppbpi =
+// (PPOWER_BROADCAST_POWER_INFO) ppb->SystemPowerState;
+//
+type
+ _POWER_BROADCAST_POWER_INFO = record
+ // levels available in battery flag fields, see BatteryDrvrGetLevels()
+ dwNumLevels:DWORD;
+
+ // see GetSystemPowerStatusEx2()
+ dwBatteryLifeTime:DWORD;
+ dwBatteryFullLifeTime:DWORD;
+ dwBackupBatteryLifeTime:DWORD;
+ dwBackupBatteryFullLifeTime:DWORD;
+ bACLineStatus:byte;
+ bBatteryFlag:byte;
+ bBatteryLifePercent:byte;
+ bBackupBatteryFlag:byte;
+ bBackupBatteryLifePercent:byte;
+ end;
+ POWER_BROADCAST_POWER_INFO = _POWER_BROADCAST_POWER_INFO;
+ PPOWER_BROADCAST_POWER_INFO = ^_POWER_BROADCAST_POWER_INFO;
+
+//*****************************************************************************
+// P R O T O S
+//*****************************************************************************
+function GetSystemPowerState(pBuffer:LPWSTR; dwBufChars:DWORD; pdwFlags:PDWORD):DWORD; external KernelDLL name 'GetSystemPowerState'; // index 15E
+
+function SetSystemPowerState(pwsSystemState:LPCWSTR; StateFlags:DWORD; Options:DWORD):DWORD; external KernelDLL name 'SetSystemPowerState'; // index 15F
+
+function SetPowerRequirement(pvDevice:PVOID;
+ DeviceState:CEDEVICE_POWER_STATE;
+ DeviceFlags:ULONG;
+ pvSystemState:PVOID;
+ StateFlags:ULONG):HANDLE; external KernelDLL name 'SetPowerRequirement'; // index 160
+
+function ReleasePowerRequirement(hPowerReq:HANDLE):DWORD; external KernelDLL name 'ReleasePowerRequirement'; // index 161
+
+function RequestPowerNotifications(hMsgQ:HANDLE; Flags:DWORD):HANDLE; external KernelDLL name 'RequestPowerNotifications'; // index 162
+
+function StopPowerNotifications(h:HANDLE):DWORD; external KernelDLL name 'StopPowerNotifications'; // index 163
+
+function DevicePowerNotify(pvDevice:PVOID; DeviceState:CEDEVICE_POWER_STATE; Flags:DWORD):DWORD; external KernelDLL name 'DevicePowerNotify'; // index 164
+
+function RegisterPowerRelationship(pvParent:PVOID;
+ pvChild:PVOID;
+ pCaps:PPOWER_CAPABILITIES;
+ Flags:DWORD):HANDLE; external KernelDLL name 'RegisterPowerRelationship'; // index 165
+
+function ReleasePowerRelationship(hChild:HANDLE):DWORD; external KernelDLL name 'ReleasePowerRelationship'; // index 166
+
+function SetDevicePower(pvDevice:PVOID; dwDeviceFlags:DWORD; dwState:CEDEVICE_POWER_STATE):DWORD; external KernelDLL name 'SetDevicePower'; // index 167
+
+function GetDevicePower(pvDevice:PVOID; dwDeviceFlags:DWORD; pdwState:PCEDEVICE_POWER_STATE):DWORD; external KernelDLL name 'GetDevicePower'; // index 168
+
+//*** Begin of pmpolicy.h declarations
+
+//
+// pmpolicy.h
+//
+//
+// This routine contains definitions and APIs for communicating with a platform-specific
+// power policy manager.
+//
+
+// notification messages
+const
+ PPN_REEVALUATESTATE = $0001; // dwData is reserved, use 0
+ PPN_POWERCHANGE = $0002; // dwData is reserved, use 0
+ PPN_UNATTENDEDMODE = $0003; // dwData is TRUE or FALSE
+ PPN_SUSPENDKEYPRESSED = $0004; // dwData is reserved. use 0
+ PPN_SUSPENDKEYRELEASED = $0005; // dwData is reserved. use 0
+ PPN_APPBUTTONPRESSED = $0006; // dwData is reserved. use 0
+ PPN_POWERBUTTONPRESSED = PPN_SUSPENDKEYPRESSED;
+
+// OEMs can define values higher than this (as PPN_OEMBASE+0, +1, etc.)
+const
+ PPN_OEMBASE = $10000;
+
+// This routine notifies the power policy manager of events it needs in order to
+// implement the OEM's power policy. The dwMessage parameter is one of the PPN_
+// values (or an OEM-defined one). The dwData parameter is a 32-bit value whose
+// interpretation varies with the notification message. A return value of TRUE
+// indicates success.
+function PowerPolicyNotify(dwMessage:DWORD; dwData:DWORD):BOOL; external KernelDLL name 'PowerPolicyNotify'; // index 169
+
+//*** End of pmpolicy.h declarations
+
+implementation
+
+// upper bytes: common power state bits
+function POWER_STATE(f:DWORD):DWORD; inline;
+begin
+ POWER_STATE:=f and $FFFF0000;
+end;
+
+function DX_MASK(Dx:DWORD):DWORD; inline;
+begin
+ DX_MASK:=$00000001 shl Dx;
+end;
+
+function VALID_DX(dx:DWORD):BOOL; inline;
+begin
+ VALID_DX:=(dx>DWORD(PwrDeviceUnspecified)) and (dx<DWORD(PwrDeviceMaximum));
+end;
+
+end. \ No newline at end of file
diff --git a/packages/winceunits/src/service.pp b/packages/winceunits/src/service.pp
new file mode 100644
index 0000000000..4ce671826f
--- /dev/null
+++ b/packages/winceunits/src/service.pp
@@ -0,0 +1,298 @@
+{
+ This file is part of the Free Pascal run time library.
+ Copyright (c) 2008 Free Pascal development team.
+
+ See the file COPYING.FPC, included in this distribution,
+ for details about the copyright.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ ********************************************************************** }
+{
+service.h
+
+Abstract:
+ Defines programming model for Windows CE Services
+
+Notes:
+}
+
+//
+// Microsoft Windows Mobile 6.0 for PocketPC SDK.
+//
+
+unit service;
+
+{$CALLING cdecl}
+
+interface
+
+uses Windows, WinIOCtl;
+
+//
+// Return codes
+//
+const
+ SERVICE_SUCCESS = 0;
+
+//
+// Service states
+//
+const
+ SERVICE_STATE_OFF = 0;
+ SERVICE_STATE_ON = 1;
+ SERVICE_STATE_STARTING_UP = 2;
+ SERVICE_STATE_SHUTTING_DOWN = 3;
+ SERVICE_STATE_UNLOADING = 4;
+ SERVICE_STATE_UNINITIALIZED = 5;
+ SERVICE_STATE_UNKNOWN = $FFFFFFFF;
+
+const
+//
+// Service startup state (value passed on xxx_Init())
+//
+ SERVICE_INIT_STARTED = $00000000;
+// Service is a super-service, should not spin its own accept() threads.
+ SERVICE_INIT_STOPPED = $00000001;
+// Service is being run in an isolated services.exe. Interprocess communication
+// via IOCTLs or streaming interface is not supported in this configuration.
+ SERVICE_INIT_STANDALONE = $00000002;
+
+//
+// Service may need to know whether it was called from device.exe or services.exe or elsewhere.
+//
+const
+ SERVICE_CALLER_PROCESS_SERVICES_EXE = 1;
+ SERVICE_CALLER_PROCESS_DEVICE_EXE = 2;
+ SERVICE_CALLER_PROCESS_OTHER_EXE = 100;
+
+ SERVICE_SERVICES_EXE_PROCNAME = 'services.exe';
+ SERVICE_DEVICE_EXE_PROCNAME = 'device.exe';
+
+
+type
+ _ServiceEnumInfo = record
+ szPrefix:array[0..5] of WideChar;
+ szDllName:PWideChar;
+ hServiceHandle:HANDLE;
+ dwServiceState:DWORD; // one of SERVICE_STATE_XXX values above.
+ end;
+ ServiceEnumInfo = _ServiceEnumInfo;
+
+
+// Called from service on initialization to determine where it's running from
+procedure SERVICE_FIND_CALLER(var callerProc:DWORD);
+
+//
+// Service is interfaced via series of IOCTL calls that define service life cycle.
+// Actual implementation is service-specific.
+//
+
+//
+// Start the service that has been in inactive state. Return code: SERVICE_SUCCESS or error code.
+//
+const
+ IOCTL_SERVICE_START = (FILE_DEVICE_SERVICE shl 16) or (1 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Stop service, but do not unload service's DLL
+//
+ IOCTL_SERVICE_STOP = (FILE_DEVICE_SERVICE shl 16) or (2 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Refresh service's state from registry or other configuration storage
+//
+ IOCTL_SERVICE_REFRESH = (FILE_DEVICE_SERVICE shl 16) or (3 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Have service configure its registry for auto-load
+//
+ IOCTL_SERVICE_INSTALL = (FILE_DEVICE_SERVICE shl 16) or (4 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Remove registry configuration
+//
+ IOCTL_SERVICE_UNINSTALL = (FILE_DEVICE_SERVICE shl 16) or (5 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Unload the service which should be stopped.
+//
+ IOCTL_SERVICE_UNLOAD = (FILE_DEVICE_SERVICE shl 16) or (6 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Supply a configuration or command string and code to the service.
+//
+ IOCTL_SERVICE_CONTROL = (FILE_DEVICE_SERVICE shl 16) or (7 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Return service status.
+//
+ IOCTL_SERVICE_STATUS = (FILE_DEVICE_SERVICE shl 16) or (8 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Set service's debug zone mask (parameter is sizeof(DWORD) and contains the mask)
+//
+ IOCTL_SERVICE_DEBUG = (FILE_DEVICE_SERVICE shl 16) or (9 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Toggle service's console on/off (string "on" on no parameters is ON, "off" means off)
+//
+ IOCTL_SERVICE_CONSOLE = (FILE_DEVICE_SERVICE shl 16) or (10 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Notify service a service request has arrived. Input contains connected socket.
+//
+ IOCTL_SERVICE_REGISTER_SOCKADDR = (FILE_DEVICE_SERVICE shl 16) or (11 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Notify service a service request has arrived. For now all sockets associated with service will be closed at once.
+//
+ IOCTL_SERVICE_DEREGISTER_SOCKADDR = (FILE_DEVICE_SERVICE shl 16) or (12 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Notify service a another socket has bound to it. Input contains an accepted socket.
+//
+ IOCTL_SERVICE_CONNECTION = (FILE_DEVICE_SERVICE shl 16) or (13 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Service has finished initial control setup. Ready to start.
+//
+ IOCTL_SERVICE_STARTED = (FILE_DEVICE_SERVICE shl 16) or (14 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Service is called with IOCTL_SERVICE_CAN_DEINIT immediatly before xxx_Deinit is called during DeregisterService.
+// If xxx_IOControl returns TRUE and sets buffer in pBufOut to zero, service instance will remain loaded and
+// xxx_Deinit will not be called.
+//
+ IOCTL_SERVICE_QUERY_CAN_DEINIT = (FILE_DEVICE_SERVICE shl 16) or (15 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// If iphlpapi is present, services receive this notification when table that
+// maps IP addresses changes.
+// Input contains PIP_ADAPTER_ADDRESSES retrieved from a call to GetAdaptersAddresses().
+// As soon as the service returns from this call, this buffer is not valid. The buffer
+// must not be pointed to and it MUST NOT BE COPIED (because internally it has pointers
+// to other structures inside it). If this data is required after the service returns,
+// the service must make its own call to GetAdaptersAddresses().
+ IOCTL_SERVICE_NOTIFY_ADDR_CHANGE = (FILE_DEVICE_SERVICE shl 16) or (16 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// Services.exe supports a set of callbacks that can only be called from a running service (not API).
+// pBufIn data structure contains a pointer to ServiceCallbackFunctions data structure
+// IOCTL_SERVICE_CALLBACKS will sent to service during its initial load, and only if there
+// are supported callbacks for service's mode of operation.
+//
+ IOCTL_SERVICE_CALLBACK_FUNCTIONS = (FILE_DEVICE_SERVICE shl 16) or (17 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+
+//
+// Service returns a DWORD containing a set of flags that specify what options it supports.
+// The meaning of the flags is service specific.
+//
+ IOCTL_SERVICE_SUPPORTED_OPTIONS = (FILE_DEVICE_SERVICE shl 16) or (18 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+
+//
+// Service is called from services.exe cmd line with arguments passed into it.
+// (i.e. "services command HTP0: Arg1 Arg2 Arg3...")
+// Args will be passed to service as ServicesExeCommandLineParams struct as the pBufIn paramater.
+// In pBufOut paramater services may put a WCHAR* string, which will be displayed to command line user.
+//
+ IOCTL_SERVICE_COMMAND_LINE_PARAMS = (FILE_DEVICE_SERVICE shl 16) or (19 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+//
+// If a cmd line user of services.exe queries it for help on a particular service
+// (i.e. "services help HTP0:") then this IOCTL will be passed to the service. If
+// the service supports command line help, it should return a WCHAR* to be displayed
+// to the user in pBufOut.
+
+ IOCTL_SERVICE_COMMAND_LINE_HELP = (FILE_DEVICE_SERVICE shl 16) or (20 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14);
+
+
+
+// A service will be called with IOCTL_SERVICE_CALLBACKS and a pointer to this struct
+// on startup potentially. Note that only functions that are supported for a service's
+// mode of operation will be set. It is possible that function pointers will be NULL.
+type
+ PFN_SERVICE_SHUTDOWN = procedure; cdecl;
+
+type
+ _ServicesExeCallbackFunctions = record
+ // Only set when service is running in context SERVICE_INIT_STANDALONE, i.e.
+ // in its own copy of services.exe. Service calls this function to request itself
+ // to be unloaded and the services.exe process to exit. For typical scenario
+ // (no SERVICE_INIT_STANDALONE), use DeregisterService() API to cause service to be unloaded.
+ pfnServiceShutdown:PFN_SERVICE_SHUTDOWN;
+ end;
+ ServicesExeCallbackFunctions = _ServicesExeCallbackFunctions;
+
+const
+ SERVICES_EXE_MAX_CMD_LINE_OPTIONS = 16;
+
+type
+ _ServicesExeCommandLineParams = record
+ dwArgs:DWORD;
+ ppwszArgs:array[0..SERVICES_EXE_MAX_CMD_LINE_OPTIONS-1] of WideChar;
+ end;
+ ServicesExeCommandLineParams = _ServicesExeCommandLineParams;
+
+
+function ActivateService(lpszDevKey:LPCWSTR; dwClientInfo:DWORD):HANDLE; external KernelDLL name 'ActivateService'; // index 16A
+function RegisterService(lpszType:LPCWSTR; dwIndex:DWORD; lpszLib:LPCWSTR; dwInfo:DWORD):HANDLE; external KernelDLL name 'RegisterService'; // index 16B
+function DeregisterService(hService:HANDLE):BOOL; external KernelDLL name 'DeregisterService'; // index 16C
+// void CloseAllServiceHandles(HANDLE proc); // not supported
+function CreateServiceHandle(lpNew:LPCWSTR; dwAccess:DWORD; dwShareMode:DWORD; hProc:HANDLE):HANDLE; external KernelDLL name 'CreateServiceHandle'; // index 16E
+function GetServiceByIndex(dwIndex:DWORD; lpFindFileData:LPWIN32_FIND_DATA):BOOL; external KernelDLL name 'GetServiceByIndex'; // index 16F
+function ServiceIoControl(hService:HANDLE;
+ dwIoControlCode:DWORD;
+ lpInBuf:LPVOID;
+ nInBufSize:DWORD;
+ lpOutBuf:LPVOID;
+ nOutBufSize:DWORD;
+ lpBytesReturned:LPDWORD;
+ lpOverlapped:LPOVERLAPPED):BOOL; external KernelDLL name 'ServiceIoControl'; // index 170
+
+{$IF DEFINED(_WINSOCKAPI_) OR DEFINED(_WINSOCK2API_)}
+function ServiceAddPort(hService:HANDLE; pSockAddr:LPSOCKADDR; cbSockAddr:integer; iProtocol:integer; szRegWritePath:PWideChar):BOOL; external KernelDLL name 'ServiceAddPort'; // index 171
+function ServiceClosePort(hService:HANDLE; pSockAddr:LPSOCKADDR; cbSockAddr:integer; iProtocol:integer; fRemoveFromRegistry:BOOL):BOOL; external KernelDLL name 'ServiceClosePort'; // index 175
+{$ELSE}
+function ServiceAddPort(hService:HANDLE; pSockAddr:LPVOID{ref. to LPSOCKADDR}; cbSockAddr:integer; iProtocol:integer; szRegWritePath:PWideChar):BOOL; external KernelDLL name 'ServiceAddPort'; // index 171
+function ServiceClosePort(hService:HANDLE; pSockAddr:LPVOID{ref. to LPSOCKADDR}; cbSockAddr:integer; iProtocol:integer; fRemoveFromRegistry:BOOL):BOOL; external KernelDLL name 'ServiceClosePort'; // index 175
+{$ENDIF}
+
+function ServiceUnbindPorts(hService:HANDLE):BOOL; external KernelDLL name 'ServiceUnbindPorts'; // index 172
+function EnumServices(pBuffer:PBYTE; pdwServiceEntries:LPDWORD; pdwBufferLen:LPDWORD):BOOL; external KernelDLL name 'EnumServices'; // index 173
+function GetServiceHandle(szPrefix:LPWSTR; szDllName:LPWSTR; pdwDllBuf:LPDWORD):HANDLE; external KernelDLL name 'GetServiceHandle'; // index 174
+
+{
+#if defined(WINCEOEM) && defined(UNDER_CE)
+#ifdef WINCEMACRO
+#include <mservice.h>
+#endif
+#endif
+}
+implementation
+
+// Called from service on initialization to determine where it's running from
+procedure SERVICE_FIND_CALLER(var callerProc:DWORD); inline;
+var szCallerModName:array[0..MAX_PATH-1] of WideChar;
+begin
+ if GetModuleFileName(HINST(GetCurrentProcess),szCallerModName,SizeOf(szCallerModName))<>0
+ then begin
+ if wcsstr(szCallerModName,SERVICE_DEVICE_EXE_PROCNAME)<>nil then begin
+ callerProc:=SERVICE_CALLER_PROCESS_DEVICE_EXE;
+ end else begin
+ if wcsstr(szCallerModName,SERVICE_SERVICES_EXE_PROCNAME)<>nil then begin
+ callerProc:=SERVICE_CALLER_PROCESS_SERVICES_EXE;
+ end else begin
+ callerProc:=SERVICE_CALLER_PROCESS_OTHER_EXE;
+ end;
+ end;
+ end else begin
+ callerProc:=SERVICE_CALLER_PROCESS_OTHER_EXE;
+ end;
+end;
+
+end.
diff --git a/packages/winceunits/src/winioctl.pp b/packages/winceunits/src/winioctl.pp
new file mode 100644
index 0000000000..8b48fd3714
--- /dev/null
+++ b/packages/winceunits/src/winioctl.pp
@@ -0,0 +1,153 @@
+{
+ This file is part of the Free Pascal run time library.
+ Copyright (c) 2008 Free Pascal development team.
+
+ See the file COPYING.FPC, included in this distribution,
+ for details about the copyright.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ ********************************************************************** }
+// *
+// * Module Name: winioctl.h
+// * Abstract: this module defines device IO control codes.
+// *
+
+//
+// Microsoft Windows Mobile 6.0 for PocketPC SDK.
+//
+
+unit WinIOCtl;
+
+interface
+
+uses Windows;
+
+// The definition below is intentionally left SO FAR because some of useful
+// constants or macros declared here may be redeclared elsewhere by pure accident.
+{$IFNDEF _WINIOCTL_}
+ {$DEFINE _WINIOCTL_}
+{$ENDIF _WINIOCTL_}
+
+type
+ DEVICE_TYPE = ULONG;
+
+//
+// Macro definition for defining IOCTL and FSCTL function control codes. Note
+// that function codes 0-2047 are reserved for Microsoft Corporation, and
+// 2048-4095 are reserved for customers.
+//
+function CTL_CODE(_DeviceType:DEVICE_TYPE; _Function:DWORD; _Method:DWORD; _Access:DWORD):DWORD;
+{ This macro was declared as:
+#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
+ ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
+)
+}
+
+
+//
+// Define the method codes for how buffers are passed for I/O and FS controls
+//
+const
+ METHOD_BUFFERED = 0;
+ METHOD_IN_DIRECT = 1;
+ METHOD_OUT_DIRECT = 2;
+ METHOD_NEITHER = 3;
+
+//
+// Define the access check value for any access
+//
+//
+// The FILE_READ_ACCESS and FILE_WRITE_ACCESS constants are also defined in
+// ntioapi.h as FILE_READ_DATA and FILE_WRITE_DATA. The values for these
+// constants *MUST* always be in sync.
+//
+const
+ FILE_ANY_ACCESS = 0;
+ FILE_READ_ACCESS = $0001; // file & pipe
+ FILE_WRITE_ACCESS = $0002; // file & pipe
+
+//
+// Define the various device type values. Note that values used by Microsoft
+// Corporation are in the range 0-32767, and 32768-65535 are reserved for use
+// by customers.
+//
+const
+ FILE_DEVICE_BEEP = $00000001;
+ FILE_DEVICE_CD_ROM = $00000002;
+ FILE_DEVICE_CD_ROM_FILE_SYSTEM = $00000003;
+ FILE_DEVICE_CONTROLLER = $00000004;
+ FILE_DEVICE_DATALINK = $00000005;
+ FILE_DEVICE_DFS = $00000006;
+ FILE_DEVICE_DISK = $00000007;
+ FILE_DEVICE_DISK_FILE_SYSTEM = $00000008;
+ FILE_DEVICE_FILE_SYSTEM = $00000009;
+ FILE_DEVICE_INPORT_PORT = $0000000a;
+ FILE_DEVICE_KEYBOARD = $0000000b;
+ FILE_DEVICE_MAILSLOT = $0000000c;
+ FILE_DEVICE_MIDI_IN = $0000000d;
+ FILE_DEVICE_MIDI_OUT = $0000000e;
+ FILE_DEVICE_MOUSE = $0000000f;
+ FILE_DEVICE_MULTI_UNC_PROVIDER = $00000010;
+ FILE_DEVICE_NAMED_PIPE = $00000011;
+ FILE_DEVICE_NETWORK = $00000012;
+ FILE_DEVICE_NETWORK_BROWSER = $00000013;
+ FILE_DEVICE_NETWORK_FILE_SYSTEM = $00000014;
+ FILE_DEVICE_NULL = $00000015;
+ FILE_DEVICE_PARALLEL_PORT = $00000016;
+ FILE_DEVICE_PHYSICAL_NETCARD = $00000017;
+ FILE_DEVICE_PRINTER = $00000018;
+ FILE_DEVICE_SCANNER = $00000019;
+ FILE_DEVICE_SERIAL_MOUSE_PORT = $0000001a;
+ FILE_DEVICE_SERIAL_PORT = $0000001b;
+ FILE_DEVICE_SCREEN = $0000001c;
+ FILE_DEVICE_SOUND = $0000001d;
+ FILE_DEVICE_STREAMS = $0000001e;
+ FILE_DEVICE_TAPE = $0000001f;
+ FILE_DEVICE_TAPE_FILE_SYSTEM = $00000020;
+ FILE_DEVICE_TRANSPORT = $00000021;
+ FILE_DEVICE_UNKNOWN = $00000022;
+ FILE_DEVICE_VIDEO = $00000023;
+ FILE_DEVICE_VIRTUAL_DISK = $00000024;
+ FILE_DEVICE_WAVE_IN = $00000025;
+ FILE_DEVICE_WAVE_OUT = $00000026;
+ FILE_DEVICE_8042_PORT = $00000027;
+ FILE_DEVICE_NETWORK_REDIRECTOR = $00000028;
+ FILE_DEVICE_BATTERY = $00000029;
+ FILE_DEVICE_BUS_EXTENDER = $0000002a;
+ FILE_DEVICE_MODEM = $0000002b;
+ FILE_DEVICE_VDM = $0000002c;
+ FILE_DEVICE_MASS_STORAGE = $0000002d;
+ FILE_DEVICE_SMB = $0000002e;
+ FILE_DEVICE_KS = $0000002f;
+ FILE_DEVICE_CHANGER = $00000030;
+ FILE_DEVICE_SMARTCARD = $00000031;
+ FILE_DEVICE_ACPI = $00000032;
+ FILE_DEVICE_DVD = $00000033;
+ FILE_DEVICE_FULLSCREEN_VIDEO = $00000034;
+ FILE_DEVICE_DFS_FILE_SYSTEM = $00000035;
+ FILE_DEVICE_DFS_VOLUME = $00000036;
+
+//
+// Windows CE Specific Defines
+//
+const
+ FILE_DEVICE_HAL = $00000101;
+ FILE_DEVICE_CONSOLE = $00000102;
+ FILE_DEVICE_PSL = $00000103;
+ FILE_DEVICE_SERVICE = $00000104;
+ FILE_DEVICE_NLED = $00000105;
+ FILE_DEVICE_NOTIFY = $00000106;
+ FILE_DEVICE_GPS = $00000107;
+ FILE_DEVICE_SQM = $00000108;
+
+implementation
+
+function CTL_CODE(_DeviceType:DEVICE_TYPE; _Function:DWORD; _Method:DWORD; _Access:DWORD):DWORD; inline;
+begin
+ CTL_CODE:=(_DeviceType shl 16) or (_Access shl 14) or (_Function shl 2) or _Method;
+end;
+
+end. \ No newline at end of file