diff --git a/cpp/wiipair/.cproject b/cpp/wiipair/.cproject deleted file mode 100644 index 61ae46b..0000000 --- a/cpp/wiipair/.cproject +++ /dev/null @@ -1,151 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/wiipair/.project b/cpp/wiipair/.project deleted file mode 100644 index 2949259..0000000 --- a/cpp/wiipair/.project +++ /dev/null @@ -1,71 +0,0 @@ - - - cpp.wiipair - - - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - clean,full,incremental, - - - ?name? - - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.buildArguments - - - - org.eclipse.cdt.make.core.buildCommand - make - - - org.eclipse.cdt.make.core.buildLocation - ${workspace_loc:/Wiiscan/Release} - - - org.eclipse.cdt.make.core.contents - org.eclipse.cdt.make.core.activeConfigSettings - - - org.eclipse.cdt.make.core.enableAutoBuild - false - - - org.eclipse.cdt.make.core.enableCleanBuild - true - - - org.eclipse.cdt.make.core.enableFullBuild - true - - - org.eclipse.cdt.make.core.stopOnError - true - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - true - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - org.eclipse.cdt.core.cnature - org.eclipse.cdt.core.ccnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - diff --git a/cpp/wiipair/Release/wiipair.exe b/cpp/wiipair/Release/wiipair.exe deleted file mode 100644 index b749c3e..0000000 Binary files a/cpp/wiipair/Release/wiipair.exe and /dev/null differ diff --git a/cpp/wiipair/include/BluetoothAPIs.h b/cpp/wiipair/include/BluetoothAPIs.h deleted file mode 100644 index 39ef8eb..0000000 --- a/cpp/wiipair/include/BluetoothAPIs.h +++ /dev/null @@ -1,1540 +0,0 @@ - -// -// Copyright 2002 - Microsoft Corporation -// -// Created By: -// Geoff Pease (GPease) 12-JAN-2002 -// -////////////////////////////////////////////////////////////////////////////// - -#pragma once - -#define BLUETOOTH_MAX_NAME_SIZE (248) -#define BLUETOOTH_MAX_PASSKEY_SIZE (16) -#define BLUETOOTH_MAX_PASSKEY_BUFFER_SIZE (BLUETOOTH_MAX_PASSKEY_SIZE + 1) - -#ifdef __cplusplus -extern "C" { -#endif - -// *************************************************************************** -// -// Bluetooth Address -// -// *************************************************************************** - -typedef ULONGLONG BTH_ADDR; - -typedef struct _BLUETOOTH_ADDRESS { - union { - BTH_ADDR ullLong; // easier to compare again BLUETOOTH_NULL_ADDRESS - BYTE rgBytes[ 6 ]; // easier to format when broken out - }; - -} BLUETOOTH_ADDRESS_STRUCT; - -#define BLUETOOTH_ADDRESS BLUETOOTH_ADDRESS_STRUCT - -#define BLUETOOTH_NULL_ADDRESS ( (ULONGLONG) 0x0 ) - -// *************************************************************************** -// -// Radio Enumeration -// -// Description: -// This group of APIs enumerates the installed Bluetooth radios. -// -// Sample Usage: -// HANDLE hRadio; -// BLUETOOTH_FIND_RADIO_PARAMS btfrp = { sizeof(btfrp) }; -// -// HBLUETOOTH_RADIO_FIND hFind = BluetoothFindFirstRadio( &btfrp, &hRadio ); -// if ( NULL != hFind ) -// { -// do -// { -// // -// // TODO: Do something with the radio handle. -// // -// -// CloseHandle( hRadio ); -// -// } while( BluetoothFindNextRadio( hFind, &hRadio ) ); -// -// BluetoothFindRadioClose( hFind ); -// } -// -// *************************************************************************** - -typedef struct _BLUETOOTH_FIND_RADIO_PARAMS { - DWORD dwSize; // IN sizeof this structure - -} BLUETOOTH_FIND_RADIO_PARAMS; - -typedef HANDLE HBLUETOOTH_RADIO_FIND; - -// -// Description: -// Begins the enumeration of local Bluetooth radios. -// -// Parameters: -// pbtfrp -// A pointer to a BLUETOOTH_FIND_RADIO_PARAMS structure. The dwSize -// member of this structure must match the sizeof the of the structure. -// -// phRadio -// A pointer where the first radio HANDLE enumerated will be returned. -// -// Return Values: -// NULL -// Error opening radios or no devices found. Use GetLastError() for -// more info. -// -// ERROR_INVALID_PARAMETER -// pbtfrp parameter is NULL. -// -// ERROR_REVISION_MISMATCH -// The pbtfrp structure is not the right length. -// -// ERROR_OUTOFMEMORY -// Out of memory. -// -// other Win32 errors. -// -// any other -// Success. The return handle is valid and phRadio points to a valid handle. -// -HBLUETOOTH_RADIO_FIND -WINAPI -BluetoothFindFirstRadio( - BLUETOOTH_FIND_RADIO_PARAMS * pbtfrp, - HANDLE * phRadio - ); - -// -// Description: -// Finds the next installed Bluetooth radio. -// -// Parameters: -// hFind -// The handle returned by BluetoothFindFirstRadio(). -// -// phRadio -// A pointer where the next radio HANDLE enumerated will be returned. -// -// Return Values: -// TRUE -// Next device succesfully found. pHandleOut points to valid handle. -// -// FALSE -// No device found. pHandleOut points to an invalid handle. Call -// GetLastError() for more details. -// -// ERROR_INVALID_HANDLE -// The handle is NULL. -// -// ERROR_NO_MORE_ITEMS -// No more radios found. -// -// ERROR_OUTOFMEMORY -// Out of memory. -// -// other Win32 errors -// -BOOL -WINAPI -BluetoothFindNextRadio( - HBLUETOOTH_RADIO_FIND hFind, - HANDLE * phRadio - ); - -// -// Description: -// Closes the enumeration handle. -// -// Parameters -// hFind -// The handle returned by BluetoothFindFirstRadio(). -// -// Return Values: -// TRUE -// Handle succesfully closed. -// -// FALSE -// Failure. Check GetLastError() for details. -// -// ERROR_INVALID_HANDLE -// The handle is NULL. -// -BOOL -WINAPI -BluetoothFindRadioClose( - HBLUETOOTH_RADIO_FIND hFind - ); - -// *************************************************************************** -// -// Radio Information -// -// *************************************************************************** - -typedef struct _BLUETOOTH_RADIO_INFO { - DWORD dwSize; // Size, in bytes, of this entire data structure - - BLUETOOTH_ADDRESS address; // Address of the local radio - - WCHAR szName[ BLUETOOTH_MAX_NAME_SIZE ]; // Name of the local radio - - ULONG ulClassofDevice; // Class of device for the local radio - - USHORT lmpSubversion; // lmpSubversion, manufacturer specifc. - USHORT manufacturer; // Manufacturer of the radio, BTH_MFG_Xxx value. For the most up to date - // list, goto the Bluetooth specification website and get the Bluetooth - // assigned numbers document. -} BLUETOOTH_RADIO_INFO, *PBLUETOOTH_RADIO_INFO; - -// -// Description: -// Retrieves the information about the radio represented by the handle. -// -// Parameters: -// hRadio -// Handle to a local radio retrieved through BluetoothFindFirstRadio() -// et al or SetupDiEnumerateDeviceInterfaces() -// -// pRadioInfo -// Radio information to be filled in. The dwSize member must match the -// size of the structure. -// -// Return Values: -// ERROR_SUCCESS -// The information was retrieved successfully. -// -// ERROR_INVALID_PARAMETER -// pRadioInfo or hRadio is NULL. -// -// ERROR_REVISION_MISMATCH -// pRadioInfo->dwSize is invalid. -// -// other Win32 error codes. -// -DWORD -WINAPI -BluetoothGetRadioInfo( - HANDLE hRadio, - PBLUETOOTH_RADIO_INFO pRadioInfo - ); - -// *************************************************************************** -// -// Device Information Stuctures -// -// *************************************************************************** - -typedef struct _BLUETOOTH_DEVICE_INFO { - DWORD dwSize; // size, in bytes, of this structure - must be the sizeof(BLUETOOTH_DEVICE_INFO) - - BLUETOOTH_ADDRESS Address; // Bluetooth address - - ULONG ulClassofDevice; // Bluetooth "Class of Device" - - BOOL fConnected; // Device connected/in use - BOOL fRemembered; // Device remembered - BOOL fAuthenticated; // Device authenticated/paired/bonded - - SYSTEMTIME stLastSeen; // Last time the device was seen - SYSTEMTIME stLastUsed; // Last time the device was used for other than RNR, inquiry, or SDP - - WCHAR szName[ BLUETOOTH_MAX_NAME_SIZE ]; // Name of the device - -} BLUETOOTH_DEVICE_INFO_STRUCT; - -#define BLUETOOTH_DEVICE_INFO BLUETOOTH_DEVICE_INFO_STRUCT - -typedef BLUETOOTH_DEVICE_INFO * PBLUETOOTH_DEVICE_INFO; - -// *************************************************************************** -// -// Device Enumeration -// -// Description: -// Enumerates the Bluetooth devices. The types of returned device depends -// on the flags set in the BLUETOOTH_DEVICE_SEARCH_PARAMS (see structure -// definition for details). -// -// Sample Usage: -// HBLUETOOTH_DEVICE_FIND hFind; -// BLUETOOTH_DEVICE_SEARCH_PARAMS btsp = { sizeof(btsp) }; -// BLUETOOTH_DEVICE_INFO btdi = { sizeof(btdi) }; -// -// btsp.fReturnAuthenticated = TRUE; -// btsp.fReturnRemembered = TRUE; -// -// hFind = BluetoothFindFirstDevice( &btsp, &btdi ); -// if ( NULL != hFind ) -// { -// do -// { -// // -// // TODO: Do something useful with the device info. -// // -// -// } while( BluetoothFindNextDevice( hFind, &btdi ) ); -// -// BluetoothFindDeviceClose( hFind ); -// } -// -// *************************************************************************** - -typedef struct _BLUETOOTH_DEVICE_SEARCH_PARAMS { - DWORD dwSize; // IN sizeof this structure - - BOOL fReturnAuthenticated; // IN return authenticated devices - BOOL fReturnRemembered; // IN return remembered devices - BOOL fReturnUnknown; // IN return unknown devices - BOOL fReturnConnected; // IN return connected devices - - BOOL fIssueInquiry; // IN issue a new inquiry - UCHAR cTimeoutMultiplier; // IN timeout for the inquiry - - HANDLE hRadio; // IN handle to radio to enumerate - NULL == all radios will be searched - -} BLUETOOTH_DEVICE_SEARCH_PARAMS; - -typedef HANDLE HBLUETOOTH_DEVICE_FIND; - -// -// Description: -// Begins the enumeration of Bluetooth devices. -// -// Parameters: -// pbtsp -// A pointer to a BLUETOOTH_DEVICE_SEARCH_PARAMS structure. This -// structure contains the flags and inputs used to conduct the search. -// See BLUETOOTH_DEVICE_SEARCH_PARAMS for details. -// -// pbtdi -// A pointer to a BLUETOOTH_DEVICE_INFO structure to return information -// about the first Bluetooth device found. Note that the dwSize member -// of the structure must be the sizeof(BLUETOOTH_DEVICE_INFO) before -// calling because the APIs hast to know the size of the buffer being -// past in. The dwSize member must also match the exact -// sizeof(BLUETOOTH_DEVICE_INFO) or the call will fail. -// -// Return Values: -// NULL -// Error opening radios or not devices found. Use GetLastError for more info. -// -// ERROR_INVALID_PARAMETER -// pbtsp parameter or pbtdi parameter is NULL. -// -// ERROR_REVISION_MISMATCH -// The pbtfrp structure is not the right length. -// -// other Win32 errors -// -// any other value -// Success. The return handle is valid and pbtdi points to valid data. -// -HBLUETOOTH_DEVICE_FIND -WINAPI -BluetoothFindFirstDevice( - BLUETOOTH_DEVICE_SEARCH_PARAMS * pbtsp, - BLUETOOTH_DEVICE_INFO * pbtdi - ); - -// -// Description: -// Finds the next Bluetooth device in the enumeration. -// -// Parameters: -// hFind -// The handle returned from BluetoothFindFirstDevice(). -// -// pbtdi -// A pointer to a BLUETOOTH_DEVICE_INFO structure to return information -// about the first Bluetooth device found. Note that the dwSize member -// of the structure must be the sizeof(BLUETOOTH_DEVICE_INFO) before -// calling because the APIs hast to know the size of the buffer being -// past in. The dwSize member must also match the exact -// sizeof(BLUETOOTH_DEVICE_INFO) or the call will fail. -// -// Return Values: -// TRUE -// Next device succesfully found. pHandleOut points to valid handle. -// -// FALSE -// No device found. pHandleOut points to an invalid handle. Call -// GetLastError() for more details. -// -// ERROR_INVALID_HANDLE -// The handle is NULL. -// -// ERROR_NO_MORE_ITEMS -// No more radios found. -// -// ERROR_OUTOFMEMORY -// Out of memory. -// -// other Win32 errors -// -BOOL -WINAPI -BluetoothFindNextDevice( - HBLUETOOTH_DEVICE_FIND hFind, - BLUETOOTH_DEVICE_INFO * pbtdi - ); - -// -// Description: -// Closes the enumeration handle. -// -// Parameters: -// hFind -// The handle returned from BluetoothFindFirstDevice(). -// -// Return Values: -// TRUE -// Handle succesfully closed. -// -// FALSE -// Failure. Check GetLastError() for details. -// -// ERROR_INVALID_HANDLE -// The handle is NULL. -// -BOOL -WINAPI -BluetoothFindDeviceClose( - HBLUETOOTH_DEVICE_FIND hFind - ); - -// -// Description: -// Retrieves information about a remote device. -// -// Fill in the dwSize and the Address members of the pbtdi structure -// being passed in. On success, the rest of the members will be filled -// out with the information that the system knows. -// -// Parameters: -// hRadio -// Handle to a local radio retrieved through BluetoothFindFirstRadio() -// et al or SetupDiEnumerateDeviceInterfaces() -// -// pbtdi -// A pointer to a BLUETOOTH_DEVICE_INFO structure to return information -// about the first Bluetooth device found. The dwSize member of the -// structure must be the sizeof the structure in bytes. The Address -// member must be filled out with the Bluetooth address of the remote -// device. -// -// Return Values: -// ERROR_SUCCESS -// Success. Information returned. -// -// ERROR_REVISION_MISMATCH -// The size of the BLUETOOTH_DEVICE_INFO isn't compatible. Check -// the dwSize member of the BLUETOOTH_DEVICE_INFO structure you -// passed in. -// -// ERROR_NOT_FOUND -// The radio is not known by the system or the Address field of -// the BLUETOOTH_DEVICE_INFO structure is all zeros. -// -// ERROR_INVALID_PARAMETER -// pbtdi is NULL. -// -// other error codes -// -DWORD -WINAPI -BluetoothGetDeviceInfo( - HANDLE hRadio, - BLUETOOTH_DEVICE_INFO * pbtdi - ); - -// -// Description: -// Updates the computer local cache about the device. -// -// Parameters: -// pbtdi -// A pointer to the BLUETOOTH_DEVICE_INFO structure to be updated. -// The following members must be valid: -// dwSize -// Must match the size of the structure. -// Address -// Must be a previously found radio address. -// szName -// New name to be stored. -// -// Return Values: -// ERROR_SUCCESS -// The device information was updated successfully. -// -// ERROR_INVALID_PARAMETER -// pbtdi is NULL. -// -// ERROR_REVISION_MISMATCH -// pbtdi->dwSize is invalid. -// -// other Win32 error codes. -// -DWORD -WINAPI -BluetoothUpdateDeviceRecord( - BLUETOOTH_DEVICE_INFO * pbtdi - ); - -// -// Description: -// Delete the authentication (aka "bond") between the computer and the -// device. Also purges any cached information about the device. -// -// Return Values: -// ERROR_SUCCESS -// The device was removed successfully. -// -// ERROR_NOT_FOUND -// The device was not found. If no Bluetooth radio is installed, -// the devices could not be enumerated or removed. -// -DWORD -WINAPI -BluetoothRemoveDevice( - BLUETOOTH_ADDRESS * pAddress - ); - -// *************************************************************************** -// -// Device Picker Dialog -// -// Description: -// Invokes a common dialog for selecting Bluetooth devices. The list -// of devices displayed to the user is determined by the flags and -// settings the caller specifies in the BLUETOOTH_SELECT_DEVICE_PARAMS -// (see structure definition for more details). -// -// If BluetoothSelectDevices() returns TRUE, the caller must call -// BluetoothSelectDevicesFree() or memory will be leaked within the -// process. -// -// Sample Usage: -// -// BLUETOOTH_SELECT_DEVICE_PARAMS btsdp = { sizeof(btsdp) }; -// -// btsdp.hwndParent = hDlg; -// btsdp.fShowUnknown = TRUE; -// btsdp.fAddNewDeviceWizard = TRUE; -// -// BOOL b = BluetoothSelectDevices( &btsdp ); -// if ( b ) -// { -// BLUETOOTH_DEVICE_INFO * pbtdi = btsdp.pDevices; -// for ( ULONG cDevice = 0; cDevice < btsdp.cNumDevices; cDevice ++ ) -// { -// if ( pbtdi->fAuthenticated || pbtdi->fRemembered ) -// { -// // -// // TODO: Do something usefull with the device info -// // -// } -// -// pbtdi = (BLUETOOTH_DEVICE_INFO *) ((LPBYTE)pbtdi + pbtdi->dwSize); -// } -// -// BluetoothSelectDevicesFree( &btsdp ); -// } -// -// *************************************************************************** - - -typedef struct _BLUETOOTH_COD_PAIRS { - ULONG ulCODMask; // ClassOfDevice mask to compare - LPCWSTR pcszDescription; // Descriptive string of mask - -} BLUETOOTH_COD_PAIRS; - -typedef BOOL (WINAPI *PFN_DEVICE_CALLBACK)(LPVOID pvParam, PBLUETOOTH_DEVICE_INFO pDevice); - -typedef struct _BLUETOOTH_SELECT_DEVICE_PARAMS { - DWORD dwSize; // IN sizeof this structure - - ULONG cNumOfClasses; // IN Number in prgClassOfDevice - if ZERO search for all devices - BLUETOOTH_COD_PAIRS * prgClassOfDevices; // IN Array of CODs to find. - - LPWSTR pszInfo; // IN If not NULL, sets the "information" text - - HWND hwndParent; // IN parent window - NULL == no parent - - BOOL fForceAuthentication; // IN If TRUE, authenication will be forced before returning - BOOL fShowAuthenticated; // IN If TRUE, authenticated devices will be shown in the picker - BOOL fShowRemembered; // IN If TRUE, remembered devices will be shown in the picker - BOOL fShowUnknown; // IN If TRUE, unknown devices that are not authenticated or "remember" will be shown. - - BOOL fAddNewDeviceWizard; // IN If TRUE, invokes the add new device wizard. - BOOL fSkipServicesPage; // IN If TRUE, skips the "Services" page in the wizard. - - PFN_DEVICE_CALLBACK pfnDeviceCallback; // IN If non-NULL, a callback that will be called for each device. If the - // the callback returns TRUE, the item will be added. If the callback is - // is FALSE, the item will not be shown. - LPVOID pvParam; // IN Parameter to be passed to pfnDeviceCallback as the pvParam. - - DWORD cNumDevices; // IN number calles wants - ZERO == no limit. - // OUT the number of devices returned. - - PBLUETOOTH_DEVICE_INFO pDevices; // OUT pointer to an array for BLUETOOTH_DEVICE_INFOs. - // call BluetoothSelectDevicesFree() to free - -} BLUETOOTH_SELECT_DEVICE_PARAMS; - -// -// Description: -// (See header above) -// -// Return Values: -// TRUE -// User selected a device. pbtsdp->pDevices points to valid data. -// Caller should check the fAuthenticated && fRemembered flags to -// determine which devices we successfuly authenticated or valid -// selections by the user. -// -// Use BluetoothSelectDevicesFree() to free the nessecary data -// such as pDevices only if this function returns TRUE. -// -// FALSE -// No valid data returned. Call GetLastError() for possible details -// of the failure. If GLE() is: -// -// ERROR_CANCELLED -// The user cancelled the request. -// -// ERROR_INVALID_PARAMETER -// The pbtsdp is NULL. -// -// ERROR_REVISION_MISMATCH -// The structure passed in as pbtsdp is of an unknown size. -// -// other WIN32 errors -// -BOOL -WINAPI -BluetoothSelectDevices( - BLUETOOTH_SELECT_DEVICE_PARAMS * pbtsdp - ); - -// -// Description: -// This function should only be called if BluetoothSelectDevices() returns -// TRUE. This function will free any memory and resource returned by the -// BluetoothSelectDevices() in the BLUETOOTH_SELECT_DEVICE_PARAMS -// structure. -// -// Return Values: -// TRUE -// Success. -// -// FALSE -// Nothing to free. -// -BOOL -WINAPI -BluetoothSelectDevicesFree( - BLUETOOTH_SELECT_DEVICE_PARAMS * pbtsdp - ); - -// *************************************************************************** -// -// Device Property Sheet -// -// *************************************************************************** - -// -// Description: -// Invokes the CPLs device info property sheet. -// -// Parameters: -// hwndParent -// HWND to parent the property sheet. -// -// pbtdi -// A pointer to a BLUETOOTH_DEVICE_INFO structure of the device -// to be displayed. -// -// Return Values: -// TRUE -// The property page was successfully displayed. -// -// FALSE -// Failure. The property page was not displayed. Check GetLastError -// for more details. -// -BOOL -WINAPI -BluetoothDisplayDeviceProperties( - HWND hwndParent, - BLUETOOTH_DEVICE_INFO * pbtdi - ); - - -// *************************************************************************** -// -// Radio Authentication -// -// *************************************************************************** - -// -// Description: -// Sends an authentication request to a remote device. -// -// There are two modes of operation. "Wizard mode" and "Blind mode." -// -// "Wizard mode" is invoked when the pszPasskey is NULL. This will cause -// the "Bluetooth Connection Wizard" to be invoked. The user will be -// prompted to enter a passkey during the wizard after which the -// authentication request will be sent. The user will see the success -// or failure of the authentication attempt. The user will also be -// given the oppurtunity to try to fix a failed authentication. -// -// "Blind mode" is invoked when the pszPasskey is non-NULL. This will -// cause the computer to send a authentication request to the remote -// device. No UI is ever displayed. The Bluetooth status code will be -// mapped to a Win32 Error code. -// -// Parameters: -// -// hwndParent -// The window to parent the authentication wizard. If NULL, the -// wizard will be parented off the desktop. -// -// hRadio -// A valid local radio handle or NULL. If NULL, then all radios will -// be tired. If any of the radios succeed, then the call will -// succeed. -// -// pbtdi -// BLUETOOTH_DEVICE_INFO record of the device to be authenticated. -// -// pszPasskey -// PIN to be used to authenticate the device. If NULL, then UI is -// displayed and the user steps through the authentication process. -// If not NULL, no UI is shown. The passkey is NOT NULL terminated. -// -// ulPasskeyLength -// Length of szPassKey in bytes. The length must be less than or -// equal to BLUETOOTH_MAX_PASSKEY_SIZE * sizeof(WCHAR). -// -// Return Values: -// -// ERROR_SUCCESS -// Success. -// -// ERROR_CANCELLED -// User aborted the operation. -// -// ERROR_INVALID_PARAMETER -// The device structure in pbtdi is invalid. -// -// ERROR_NO_MORE_ITEMS -// The device in pbtdi is already been marked as authenticated. -// -// other WIN32 error -// Failure. Return value is the error code. -// -// For "Blind mode," here is the current mapping of Bluetooth status -// code to Win32 error codes: -// -// { BTH_ERROR_SUCCESS, ERROR_SUCCESS }, -// { BTH_ERROR_NO_CONNECTION, ERROR_DEVICE_NOT_CONNECTED }, -// { BTH_ERROR_PAGE_TIMEOUT, WAIT_TIMEOUT }, -// { BTH_ERROR_HARDWARE_FAILURE, ERROR_GEN_FAILURE }, -// { BTH_ERROR_AUTHENTICATION_FAILURE, ERROR_NOT_AUTHENTICATED }, -// { BTH_ERROR_MEMORY_FULL, ERROR_NOT_ENOUGH_MEMORY }, -// { BTH_ERROR_CONNECTION_TIMEOUT, WAIT_TIMEOUT }, -// { BTH_ERROR_LMP_RESPONSE_TIMEOUT, WAIT_TIMEOUT }, -// { BTH_ERROR_MAX_NUMBER_OF_CONNECTIONS, ERROR_REQ_NOT_ACCEP }, -// { BTH_ERROR_PAIRING_NOT_ALLOWED, ERROR_ACCESS_DENIED }, -// { BTH_ERROR_UNSPECIFIED_ERROR, ERROR_NOT_READY }, -// { BTH_ERROR_LOCAL_HOST_TERMINATED_CONNECTION, ERROR_VC_DISCONNECTED }, -// -DWORD -WINAPI -BluetoothAuthenticateDevice( - HWND hwndParent, - HANDLE hRadio, - BLUETOOTH_DEVICE_INFO * pbtbi, - PWCHAR pszPasskey, - ULONG ulPasskeyLength - ); - -// -// Description: -// Allows the caller to prompt for multiple devices to be authenticated -// within a single instance of the "Bluetooth Connection Wizard." -// -// Parameters: -// -// hwndParent -// The window to parent the authentication wizard. If NULL, the -// wizard will be parented off the desktop. -// -// hRadio -// A valid local radio handle or NULL. If NULL, then all radios will -// be tired. If any of the radios succeed, then the call will -// succeed. -// -// cDevices -// Number of devices in the rgbtdi array. -// -// rgbtdi -// An array BLUETOOTH_DEVICE_INFO records of the devices to be -// authenticated. -// -// Return Values: -// -// ERROR_SUCCESS -// Success. Check the fAuthenticate flag on each of the devices. -// -// ERROR_CANCELLED -// User aborted the operation. Check the fAuthenticate flags on -// each device to determine if any of the devices were authenticated -// before the user cancelled the operation. -// -// ERROR_INVALID_PARAMETER -// One of the items in the array of devices is invalid. -// -// ERROR_NO_MORE_ITEMS -// All the devices in the array of devices are already been marked as -// being authenticated. -// -// other WIN32 error -// Failure. Return value is the error code. -// -DWORD -WINAPI -BluetoothAuthenticateMultipleDevices( - HWND hwndParent, - HANDLE hRadio, - DWORD cDevices, - BLUETOOTH_DEVICE_INFO * pbtdi - ); - -// *************************************************************************** -// -// Bluetooth Services -// -// *************************************************************************** - -#define BLUETOOTH_SERVICE_DISABLE 0x00 -#define BLUETOOTH_SERVICE_ENABLE 0x01 -#define BLUETOOTH_SERVICE_MASK ( BLUETOOTH_ENABLE_SERVICE | BLUETOOTH_DISABLE_SERVICE ) - -// -// Description: -// Enables/disables the services for a particular device. -// -// The system maintains a mapping of service guids to supported drivers for -// Bluetooth-enabled devices. Enabling a service installs the corresponding -// device driver. Disabling a service removes the corresponding device driver. -// -// If a non-supported service is enabled, a driver will not be installed. -// -// Parameters -// hRadio -// Handle of the local Bluetooth radio device. -// -// pbtdi -// Pointer to a BLUETOOTH_DEVICE_INFO record. -// -// pGuidService -// The service GUID on the remote device. -// -// dwServiceFlags -// Flags to adjust the service. -// BLUETOOTH_SERVICE_DISABLE - disable the service -// BLUETOOTH_SERVICE_ENABLE - enables the service -// -// Return Values: -// ERROR_SUCCESS -// The call was successful. -// -// ERROR_INVALID_PARAMETER -// dwServiceFlags are invalid. -// -// ERROR_SERVICE_DOES_NOT_EXIST -// The GUID in pGuidService is not supported. -// -// other WIN32 error -// The call failed. -// -DWORD -WINAPI -BluetoothSetServiceState( - HANDLE hRadio, - BLUETOOTH_DEVICE_INFO * pbtdi, - GUID * pGuidService, - DWORD dwServiceFlags - ); - -// -// Description: -// Enumerates the services guids enabled on a particular device. If hRadio -// is NULL, all device will be searched for the device and all the services -// enabled will be returned. -// -// Parameters: -// hRadio -// Handle of the local Bluetooth radio device. If NULL, it will search -// all the radios for the address in the pbtdi. -// -// pbtdi -// Pointer to a BLUETOOTH_DEVICE_INFO record. -// -// pcService -// On input, the number of records pointed to by pGuidServices. -// On output, the number of valid records return in pGuidServices. -// -// pGuidServices -// Pointer to memory that is at least *pcService in length. -// -// Return Values: -// ERROR_SUCCESS -// The call succeeded. pGuidServices is valid. -// -// ERROR_MORE_DATA -// The call succeeded. pGuidService contains an incomplete list of -// enabled service GUIDs. -// -// other WIN32 errors -// The call failed. -// -DWORD -WINAPI -BluetoothEnumerateInstalledServices( - HANDLE hRadio, - BLUETOOTH_DEVICE_INFO * pbtdi, - DWORD * pcServices, - GUID * pGuidServices - ); - -// -// Description: -// Change the discovery state of the local radio(s). -// If hRadio is NULL, all the radios will be set. -// -// Use BluetoothIsDiscoverable() to determine the radios current state. -// -// The system ensures that a discoverable system is connectable, thus -// the radio must allow incoming connections (see -// BluetoothEnableIncomingConnections) prior to making a radio -// discoverable. Failure to do so will result in this call failing -// (returns FALSE). -// -// Parameters: -// hRadio -// If not NULL, changes the state of a specific radio. -// If NULL, the API will interate through all the radios. -// -// fEnabled -// If FALSE, discovery will be disabled. -// -// Return Values -// TRUE -// State was successfully changed. If the caller specified NULL for -// hRadio, at least of the radios accepted the state change. -// -// FALSE -// State was not changed. If the caller specified NULL for hRadio, all -// of the radios did not accept the state change. -// -BOOL -WINAPI -BluetoothEnableDiscovery( - HANDLE hRadio, - BOOL fEnabled - ); - -// -// Description: -// Determines if the Bluetooth radios are discoverable. If there are -// multiple radios, the first one to say it is discoverable will cause -// this function to return TRUE. -// -// Parameters: -// hRadio -// Handle of the radio to check. If NULL, it will check all local -// radios. -// -// Return Values: -// TRUE -// A least one radio is discoverable. -// -// FALSE -// No radios are discoverable. -// -BOOL -WINAPI -BluetoothIsDiscoverable( - HANDLE hRadio - ); - -// -// Description: -// Enables/disables the state of a radio to accept incoming connections. -// If hRadio is NULL, all the radios will be set. -// -// Use BluetoothIsConnectable() to determine the radios current state. -// -// The system enforces that a radio that is not connectable is not -// discoverable too. The radio must be made non-discoverable (see -// BluetoothEnableDiscovery) prior to making a radio non-connectionable. -// Failure to do so will result in this call failing (returns FALSE). -// -// Parameters: -// hRadio -// If not NULL, changes the state of a specific radio. -// If NULL, the API will interate through all the radios. -// -// fEnabled -// If FALSE, incoming connection will be disabled. -// -// Return Values -// TRUE -// State was successfully changed. If the caller specified NULL for -// hRadio, at least of the radios accepted the state change. -// -// FALSE -// State was not changed. If the caller specified NULL for hRadio, all -// of the radios did not accept the state change. -// -BOOL -WINAPI -BluetoothEnableIncomingConnections( - HANDLE hRadio, - BOOL fEnabled - ); - -// -// Description: -// Determines if the Bluetooth radios are connectable. If there are -// multiple radios, the first one to say it is connectable will cause -// this function to return TRUE. -// -// Parameters: -// hRadio -// Handle of the radio to check. If NULL, it will check all local -// radios. -// -// Return Values: -// TRUE -// A least one radio is allowing incoming connections. -// -// FALSE -// No radios are allowing incoming connections. -// -BOOL -WINAPI -BluetoothIsConnectable( - HANDLE hRadio - ); - -// *************************************************************************** -// -// Authentication Registration -// -// *************************************************************************** - -typedef HANDLE HBLUETOOTH_AUTHENTICATION_REGISTRATION; - -typedef BOOL (*PFN_AUTHENTICATION_CALLBACK)(LPVOID pvParam, PBLUETOOTH_DEVICE_INFO pDevice); - -// -// Description: -// Registers a callback function to be called when a particular device -// requests authentication. The request is sent to the last application -// that requested authentication for a particular device. -// -// Parameters: -// pbtdi -// A pointer to a BLUETOOTH_DEVICE_INFO structure. The Bluetooth -// address will be used for comparision. -// -// phRegHandle -// A pointer to where the registration HANDLE value will be -// stored. Call BluetoothUnregisterAuthentication() to close -// the handle. -// -// pfnCallback -// The function that will be called when the authentication event -// occurs. This function should match PFN_AUTHENTICATION_CALLBACK's -// prototype. -// -// pvParam -// Optional parameter to be past through to the callback function. -// This can be anything the application was to define. -// -// Return Values: -// ERROR_SUCCESS -// Success. A valid registration handle was returned. -// -// ERROR_OUTOFMEMORY -// Out of memory. -// -// other Win32 error. -// Failure. The registration handle is invalid. -// -DWORD -WINAPI -BluetoothRegisterForAuthentication( - BLUETOOTH_DEVICE_INFO * pbtdi, - HBLUETOOTH_AUTHENTICATION_REGISTRATION * phRegHandle, - PFN_AUTHENTICATION_CALLBACK pfnCallback, - PVOID pvParam - ); - -// -// Description: -// Unregisters an authentication callback and closes the handle. See -// BluetoothRegisterForAuthentication() for more information about -// authentication registration. -// -// Parameters: -// hRegHandle -// Handle returned by BluetoothRegisterForAuthentication(). -// -// Return Value: -// TRUE -// The handle was successfully closed. -// -// FALSE -// The handle was not successfully closed. Check GetLastError for -// more details. -// -// ERROR_INVALID_HANDLE -// The handle is NULL. -// -// other Win32 errors. -// -BOOL -WINAPI -BluetoothUnregisterAuthentication( - HBLUETOOTH_AUTHENTICATION_REGISTRATION hRegHandle - ); - -// -// Description: -// This function should be called after receiving an authentication request -// to send the passkey response. -// -// Parameters: -// -// hRadio -// Optional handle to the local radio. If NULL, the function will try -// each radio until one succeeds. -// -// pbtdi -// A pointer to a BLUETOOTH_DEVICE_INFO structure describing the device -// being authenticated. This can be the same structure passed to the -// callback function. -// -// pszPasskey -// A pointer to UNICODE zero-terminated string of the passkey response -// that should be sent back to the authenticating device. -// -// Return Values: -// ERROR_SUCESS -// The device accepted the passkey response. The device is authenticated. -// -// ERROR_CANCELED -// The device denied the passkey reponse. This also will returned if there -// is a communications problem with the local radio. -// -// E_FAIL -// The device returned a failure code during authentication. -// -// other Win32 error codes -// -DWORD -WINAPI -BluetoothSendAuthenticationResponse( - HANDLE hRadio, - BLUETOOTH_DEVICE_INFO * pbtdi, - LPWSTR pszPasskey - ); - -// *************************************************************************** -// -// SDP Parsing Functions -// -// *************************************************************************** - -typedef struct _SDP_ELEMENT_DATA { - // - // Enumeration of SDP element types. Generic element types will have a - // specificType value other then SDP_ST_NONE. The generic types are: - // o SDP_TYPE_UINT - // o SDP_TYPE_INT - // o SDP_TYPE_UUID - // - SDP_TYPE type; - - // - // Specific types for the generic SDP element types. - // - SDP_SPECIFICTYPE specificType; - - // - // Union of all possible data types. type and specificType will indicate - // which field is valid. For types which do not have a valid specificType, - // specific type will be SDP_ST_NONE. - // - union { - // type == SDP_TYPE_INT - SDP_LARGE_INTEGER_16 int128; // specificType == SDP_ST_INT128 - LONGLONG int64; // specificType == SDP_ST_INT64 - LONG int32; // specificType == SDP_ST_INT32 - SHORT int16; // specificType == SDP_ST_INT16 - CHAR int8; // specificType == SDP_ST_INT8 - - // type == SDP_TYPE_UINT - SDP_ULARGE_INTEGER_16 uint128; // specificType == SDP_ST_UINT128 - ULONGLONG uint64; // specificType == SDP_ST_UINT64 - ULONG uint32; // specificType == SDP_ST_UINT32 - USHORT uint16; // specificType == SDP_ST_UINT16 - UCHAR uint8; // specificType == SDP_ST_UINT8 - - // type == SDP_TYPE_BOOLEAN - UCHAR booleanVal; - - // type == SDP_TYPE_UUID - GUID uuid128; // specificType == SDP_ST_UUID128 - ULONG uuid32; // specificType == SDP_ST_UUID32 - USHORT uuid16; // specificType == SDP_ST_UUID32 - - // type == SDP_TYPE_STRING - struct { - // raw string buffer, may not be encoded as ANSI, use - // BluetoothSdpGetString to convert the value if it is described - // by the base language attribute ID list - LPBYTE value; - - // raw length of the string, may not be NULL terminuated - ULONG length; - } string; - - // type == SDP_TYPE_URL - struct { - LPBYTE value; - ULONG length; - } url; - - // type == SDP_TYPE_SEQUENCE - struct { - // raw sequence, starts at sequence element header - LPBYTE value; - - // raw sequence length - ULONG length; - } sequence; - - // type == SDP_TYPE_ALTERNATIVE - struct { - // raw alternative, starts at alternative element header - LPBYTE value; - - // raw alternative length - ULONG length; - } alternative; - - } data; - -} SDP_ELEMENT_DATA, *PSDP_ELEMENT_DATA; - -// -// Description: -// Retrieves and parses the element found at pSdpStream -// -// Parameters: -// IN pSdpStream -// pointer to valid SDP stream -// -// IN cbSdpStreamLength -// length of pSdpStream in bytes -// -// OUT pData -// pointer to be filled in with the data of the SDP element at the -// beginning of pSdpStream -// -// Return Values: -// ERROR_INVALID_PARAMETER -// one of required parameters is NULL or the pSdpStream is invalid -// -// ERROR_SUCCESS -// the sdp element was parsed correctly -// -DWORD -WINAPI -BluetoothSdpGetElementData( - LPBYTE pSdpStream, - ULONG cbSdpStreamLength, - PSDP_ELEMENT_DATA pData - ); - -typedef HANDLE HBLUETOOTH_CONTAINER_ELEMENT; - -// -// Description: -// Iterates over a container stream, returning each elemetn contained with -// in the container element at the beginning of pContainerStream -// -// Parameters: -// IN pContainerStream -// pointer to valid SDP stream whose first element is either a sequence -// or alternative -// -// IN cbContainerlength -// length in bytes of pContainerStream -// -// IN OUT pElement -// Value used to keep track of location within the stream. The first -// time this function is called for a particular container, *pElement -// should equal NULL. Upon subsequent calls, the value should be -// unmodified. -// -// OUT pData -// pointer to be filled in with the data of the SDP element at the -// current element of pContainerStream -// -// Return Values: -// ERROR_SUCCESS -// The call succeeded, pData contains the data -// -// ERROR_NO_MORE_ITEMS -// There are no more items in the list, the caller should cease calling -// BluetoothSdpGetContainerElementData for this container. -// -// ERROR_INVALID_PARAMETER -// A required pointer is NULL or the container is not a valid SDP -// stream -// -// Usage example: -// -// HBLUETOOTH_CONTAINER_ELEMENT element; -// SDP_ELEMENT_DATA data; -// ULONG result; -// -// element = NULL; -// -// while (TRUE) { -// result = BluetoothSdpGetContainerElementData( -// pContainer, ulContainerLength, &element, &data); -// -// if (result == ERROR_NO_MORE_ITEMS) { -// // We are done -// break; -// } -// else if (result != ERROR_SUCCESS) { -// // error -// } -// -// // do something with data ... -// } -// -// -DWORD -WINAPI -BluetoothSdpGetContainerElementData( - LPBYTE pContainerStream, - ULONG cbContainerLength, - HBLUETOOTH_CONTAINER_ELEMENT* pElement, - PSDP_ELEMENT_DATA pData - ); - -// -// Description: -// Retrieves the attribute value for the given attribute ID. pRecordStream -// must be an SDP stream that is formatted as an SDP record, a SEQUENCE -// containing UINT16 + element pairs. -// -// Parameters: -// IN pRecordStream -// pointer to a valid SDP stream which is formatted as a singl SDP -// record -// -// IN cbRecordlnegh -// length of pRecordStream in bytes -// -// IN usAttributeId -// the attribute ID to search for. see bthdef.h for SDP_ATTRIB_Xxx -// values. -// -// OUT pAttributeData -// pointer that will contain the attribute ID's value -// -// Return Values: -// ERRROR_SUCCESS -// Call succeeded, pAttributeData contains the attribute value -// -// ERROR_INVALID_PARAMETER -// One of the required pointers was NULL, pRecordStream was not a valid -// SDP stream, or pRecordStream was not a properly formatted SDP record -// -// ERROR_FILE_NOT_FOUND -// usAttributeId was not found in the record -// -// Usage: -// -// ULONG result; -// SDP_DATA_ELEMENT data; -// -// result = BluetoothSdpGetAttributeValue( -// pRecordStream, cbRecordLength, SDP_ATTRIB_RECORD_HANDLE, &data); -// if (result == ERROR_SUCCESS) { -// printf("record handle is 0x%x\n", data.data.uint32); -// } -// -DWORD -WINAPI -BluetoothSdpGetAttributeValue( - LPBYTE pRecordStream, - ULONG cbRecordLength, - USHORT usAttributeId, - PSDP_ELEMENT_DATA pAttributeData - ); - -// -// These three fields correspond one to one with the triplets defined in the -// SDP specification for the language base attribute ID list. -// -typedef struct _SDP_STRING_TYPE_DATA { - // - // How the string is encoded according to ISO 639:1988 (E/F): "Code - // for the representation of names of languages". - // - USHORT encoding; - - // - // MIBE number from IANA database - // - USHORT mibeNum; - - // - // The base attribute where the string is to be found in the record - // - USHORT attributeId; - -} SDP_STRING_TYPE_DATA, *PSDP_STRING_TYPE_DATA; - -// -// Description: -// Converts a raw string embedded in the SDP record into a UNICODE string -// -// Parameters: -// IN pRecordStream -// a valid SDP stream which is formatted as an SDP record -// -// IN cbRecordLength -// length of pRecordStream in bytes -// -// IN pStringData -// if NULL, then the calling thread's locale will be used to search -// for a matching string in the SDP record. If not NUL, the mibeNum -// and attributeId will be used to find the string to convert. -// -// IN usStringOffset -// the SDP string type offset to convert. usStringOffset is added to -// the base attribute id of the string. SDP specification defined -// offsets are: STRING_NAME_OFFSET, STRING_DESCRIPTION_OFFSET, and -// STRING_PROVIDER_NAME_OFFSET (found in bthdef.h). -// -// OUT pszString -// if NULL, pcchStringLength will be filled in with the required number -// of characters (not bytes) to retrieve the converted string. -// -// IN OUT pcchStringLength -// Upon input, if pszString is not NULL, will contain the length of -// pszString in characters. Upon output, it will contain either the -// number of required characters including NULL if an error is returned -// or the number of characters written to pszString (including NULL). -// -// Return Values: -// ERROR_SUCCES -// Call was successful and pszString contains the converted string -// -// ERROR_MORE_DATA -// pszString was NULL or too small to contain the converted string, -// pccxhStringLength contains the required length in characters -// -// ERROR_INVALID_DATA -// Could not perform the conversion -// -// ERROR_NO_SYSTEM_RESOURCES -// Could not allocate memory internally to perform the conversion -// -// ERROR_INVALID_PARAMETER -// One of the rquired pointers was NULL, pRecordStream was not a valid -// SDP stream, pRecordStream was not a properly formatted record, or -// the desired attribute + offset was not a string. -// -// Other HRESULTs returned by COM -// -DWORD -WINAPI -BluetoothSdpGetString( - LPBYTE pRecordStream, - ULONG cbRecordLength, - PSDP_STRING_TYPE_DATA pStringData, - USHORT usStringOffset, - PWCHAR pszString, - PULONG pcchStringLength - ); - -// *************************************************************************** -// -// Raw Attribute Enumeration -// -// *************************************************************************** - -typedef BOOL (CALLBACK *PFN_BLUETOOTH_ENUM_ATTRIBUTES_CALLBACK)( - ULONG uAttribId, - LPBYTE pValueStream, - ULONG cbStreamSize, - LPVOID pvParam - ); - -// -// Description: -// Enumerates through the SDP record stream calling the Callback function -// for each attribute in the record. If the Callback function returns -// FALSE, the enumeration is stopped. -// -// Return Values: -// TRUE -// Success! Something was enumerated. -// -// FALSE -// Failure. GetLastError() could be one of the following: -// -// ERROR_INVALID_PARAMETER -// pSDPStream or pfnCallback is NULL. -// -// ERROR_INVALID_DATA -// The SDP stream is corrupt. -// -// other Win32 errors. -// -#define BluetoothEnumAttributes BluetoothSdpEnumAttributes - -BOOL -WINAPI -BluetoothSdpEnumAttributes( - LPBYTE pSDPStream, - ULONG cbStreamSize, - PFN_BLUETOOTH_ENUM_ATTRIBUTES_CALLBACK pfnCallback, - LPVOID pvParam - ); - -#ifdef __cplusplus -} -#endif diff --git a/cpp/wiipair/include/bthdef.h b/cpp/wiipair/include/bthdef.h deleted file mode 100644 index 2dd26aa..0000000 --- a/cpp/wiipair/include/bthdef.h +++ /dev/null @@ -1,858 +0,0 @@ -/*++ - -Copyright (c) 2000 Microsoft Corporation - -Module Name: - - bthdef.h - -Abstract: - - This module contains the Bluetooth common structures and definitions - -Author: - -Notes: - -Environment: - - Kernel mode only - - -Revision History: - - --*/ - -#ifndef __BTHDEF_H__ -#define __BTHDEF_H__ - -#ifndef GUID_DEFS_ONLY - #ifndef NO_BTHSDPDEF_INC - #include "bthsdpdef.h" - #endif // NO_BTHSDPDEF_INC -#endif // GUID_DEFS_ONLY - -#ifndef NO_GUID_DEFS - -// {0850302A-B344-4fda-9BE9-90576B8D46F0} -DEFINE_GUID(GUID_BTHPORT_DEVICE_INTERFACE, 0x850302a, 0xb344, 0x4fda, 0x9b, 0xe9, 0x90, 0x57, 0x6b, 0x8d, 0x46, 0xf0); - -// {EA3B5B82-26EE-450E-B0D8-D26FE30A3869} -DEFINE_GUID(GUID_BLUETOOTH_RADIO_IN_RANGE, 0xea3b5b82, 0x26ee, 0x450e, 0xb0, 0xd8, 0xd2, 0x6f, 0xe3, 0x0a, 0x38, 0x69); - -// {E28867C9-C2AA-4CED-B969-4570866037C4} -DEFINE_GUID(GUID_BLUETOOTH_RADIO_OUT_OF_RANGE, 0xe28867c9, 0xc2aa, 0x4ced, 0xb9, 0x69, 0x45, 0x70, 0x86, 0x60, 0x37, 0xc4); - -// BD198B7C-24AB-4B9A-8C0D-A8EA8349AA16 -DEFINE_GUID(GUID_BLUETOOTH_PIN_REQUEST, 0xbd198b7c, 0x24ab, 0x4b9a, 0x8c, 0x0d, 0xa8, 0xea, 0x83, 0x49, 0xaa, 0x16); - -// {7EAE4030-B709-4AA8-AC55-E953829C9DAA} -DEFINE_GUID(GUID_BLUETOOTH_L2CAP_EVENT, 0x7eae4030, 0xb709, 0x4aa8, 0xac, 0x55, 0xe9, 0x53, 0x82, 0x9c, 0x9d, 0xaa); - -// {FC240062-1541-49BE-B463-84C4DCD7BF7F} -DEFINE_GUID(GUID_BLUETOOTH_HCI_EVENT, 0xfc240062, 0x1541, 0x49be, 0xb4, 0x63, 0x84, 0xc4, 0xdc, 0xd7, 0xbf, 0x7f); - -// -// Bluetooth base UUID for service discovery -// -DEFINE_GUID(Bluetooth_Base_UUID, 0x00000000, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); - -// -// UUID for the root of the browse group list -// - -DEFINE_GUID(SDP_PROTOCOL_UUID, 0x00000001, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(UDP_PROTOCOL_UUID, 0x00000002, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(RFCOMM_PROTOCOL_UUID, 0x00000003, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(TCP_PROTOCOL_UUID, 0x00000004, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(TCSBIN_PROTOCOL_UUID, 0x00000005, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(TCSAT_PROTOCOL_UUID, 0x00000006, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(OBEX_PROTOCOL_UUID, 0x00000008, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(IP_PROTOCOL_UUID, 0x00000009, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(FTP_PROTOCOL_UUID, 0x0000000A, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(HTTP_PROTOCOL_UUID, 0x0000000C, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(WSP_PROTOCOL_UUID, 0x0000000E, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(BNEP_PROTOCOL_UUID, 0x0000000F, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(UPNP_PROTOCOL_UUID, 0x00000010, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(HID_PROTOCOL_UUID, 0x00000011, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(HCCC_PROTOCOL_UUID, 0x00000012, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(HCDC_PROTOCOL_UUID, 0x00000014, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(HN_PROTOCOL_UUID, 0x00000016, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(AVCTP_PROTOCOL_UUID, 0x00000017, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(AVDTP_PROTOCOL_UUID, 0x00000019, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(CMPT_PROTOCOL_UUID, 0x0000001B, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(UDI_C_PLANE_PROTOCOL_UUID, 0x0000001D, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(L2CAP_PROTOCOL_UUID, 0x00000100, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); - -#define SDP_PROTOCOL_UUID16 (0x0001) -#define UDP_PROTOCOL_UUID16 (0x0002) -#define RFCOMM_PROTOCOL_UUID16 (0x0003) -#define TCP_PROTOCOL_UUID16 (0x0004) -#define TCSBIN_PROTOCOL_UUID16 (0x0005) -#define TCSAT_PROTOCOL_UUID16 (0x0006) -#define OBEX_PROTOCOL_UUID16 (0x0008) -#define IP_PROTOCOL_UUID16 (0x0009) -#define FTP_PROTOCOL_UUID16 (0x000A) -#define HTTP_PROTOCOL_UUID16 (0x000C) -#define WSP_PROTOCOL_UUID16 (0x000E) -#define BNEP_PROTOCOL_UUID16 (0x000F) -#define UPNP_PROTOCOL_UUID16 (0x0010) -#define HID_PROTOCOL_UUID16 (0x0011) -#define HCCC_PROTOCOL_UUID16 (0x0012) -#define HCDC_PROTOCOL_UUID16 (0x0014) -#define HCN_PROTOCOL_UUID16 (0x0016) -#define AVCTP_PROTOCOL_UUID16 (0x0017) -#define AVDTP_PROTOCOL_UUID16 (0x0019) -#define CMPT_PROTOCOL_UUID16 (0x001B) -#define UDI_C_PLANE_PROTOCOL_UUID16 (0x001D) -#define L2CAP_PROTOCOL_UUID16 (0x0100) - -DEFINE_GUID(ServiceDiscoveryServerServiceClassID_UUID, 0x00001000, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(BrowseGroupDescriptorServiceClassID_UUID, 0x00001001, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(PublicBrowseGroupServiceClass_UUID, 0x00001002, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(SerialPortServiceClass_UUID, 0x00001101, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(LANAccessUsingPPPServiceClass_UUID, 0x00001102, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(DialupNetworkingServiceClass_UUID, 0x00001103, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(IrMCSyncServiceClass_UUID, 0x00001104, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(OBEXObjectPushServiceClass_UUID, 0x00001105, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(OBEXFileTransferServiceClass_UUID, 0x00001106, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(IrMCSyncCommandServiceClass_UUID, 0x00001107, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(HeadsetServiceClass_UUID, 0x00001108, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(CordlessTelephonyServiceClass_UUID, 0x00001109, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(AudioSourceServiceClass_UUID, 0x0000110A, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(AudioSinkServiceClass_UUID, 0x0000110B, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(AVRemoteControlTargetServiceClass_UUID, 0x0000110C, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(AdvancedAudioDistributionServiceClass_UUID,0x0000110D, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(AVRemoteControlServiceClass_UUID, 0x0000110E, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(VideoConferencingServiceClass_UUID, 0x0000110F, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(IntercomServiceClass_UUID, 0x00001110, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(FaxServiceClass_UUID, 0x00001111, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(HeadsetAudioGatewayServiceClass_UUID, 0x00001112, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(WAPServiceClass_UUID, 0x00001113, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(WAPClientServiceClass_UUID, 0x00001114, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(PANUServiceClass_UUID, 0x00001115, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(NAPServiceClass_UUID, 0x00001116, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(GNServiceClass_UUID, 0x00001117, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(DirectPrintingServiceClass_UUID, 0x00001118, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(ReferencePrintingServiceClass_UUID, 0x00001119, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(ImagingServiceClass_UUID, 0x0000111A, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(ImagingResponderServiceClass_UUID, 0x0000111B, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(ImagingAutomaticArchiveServiceClass_UUID, 0x0000111C, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(ImagingReferenceObjectsServiceClass_UUID, 0x0000111D, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(HandsfreeServiceClass_UUID, 0x0000111E, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(HandsfreeAudioGatewayServiceClass_UUID, 0x0000111F, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(DirectPrintingReferenceObjectsServiceClass_UUID, - 0x00001120, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(ReflectedUIServiceClass_UUID, 0x00001121, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(BasicPringingServiceClass_UUID, 0x00001122, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(PrintingStatusServiceClass_UUID, 0x00001123, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(HumanInterfaceDeviceServiceClass_UUID, 0x00001124, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(HardcopyCableReplacementServiceClass_UUID, 0x00001125, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(HCRPrintServiceClass_UUID, 0x00001126, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(HCRScanServiceClass_UUID, 0x00001127, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(CommonISDNAccessServiceClass_UUID, 0x00001128, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(VideoConferencingGWServiceClass_UUID, 0x00001129, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(UDIMTServiceClass_UUID, 0x0000112A, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(UDITAServiceClass_UUID, 0x0000112B, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(AudioVideoServiceClass_UUID, 0x0000112C, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(PnPInformationServiceClass_UUID, 0x00001200, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(GenericNetworkingServiceClass_UUID, 0x00001201, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(GenericFileTransferServiceClass_UUID, 0x00001202, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(GenericAudioServiceClass_UUID, 0x00001203, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); -DEFINE_GUID(GenericTelephonyServiceClass_UUID, 0x00001204, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB); - -#define ServiceDiscoveryServerServiceClassID_UUID16 (0x1000) -#define BrowseGroupDescriptorServiceClassID_UUID16 (0x1001) -#define PublicBrowseGroupServiceClassID_UUID16 (0x1002) -#define SerialPortServiceClassID_UUID16 (0x1101) -#define LANAccessUsingPPPServiceClassID_UUID16 (0x1102) -#define DialupNetworkingServiceClassID_UUID16 (0x1103) -#define IrMCSyncServiceClassID_UUID16 (0x1104) -#define OBEXObjectPushServiceClassID_UUID16 (0x1105) -#define OBEXFileTransferServiceClassID_UUID16 (0x1106) -#define IrMcSyncCommandServiceClassID_UUID16 (0x1107) -#define HeadsetServiceClassID_UUID16 (0x1108) -#define CordlessServiceClassID_UUID16 (0x1109) -#define AudioSourceServiceClassID_UUID16 (0x110A) -#define AudioSinkSourceServiceClassID_UUID16 (0x110B) -#define AVRemoteControlTargetServiceClassID_UUID16 (0x110C) -#define AdvancedAudioDistributionServiceClassID_UUID16 (0x110D) -#define AVRemoteControlServiceClassID_UUID16 (0x110E) -#define VideoConferencingServiceClassID_UUID16 (0x110F) -#define IntercomServiceClassID_UUID16 (0x1110) -#define FaxServiceClassID_UUID16 (0x1111) -#define HeadsetAudioGatewayServiceClassID_UUID16 (0x1112) -#define WAPServiceClassID_UUID16 (0x1113) -#define WAPClientServiceClassID_UUID16 (0x1114) -#define PANUServiceClassID_UUID16 (0x1115) -#define NAPServiceClassID_UUID16 (0x1116) -#define GNServiceClassID_UUID16 (0x1117) -#define DirectPrintingServiceClassID_UUID16 (0x1118) -#define ReferencePrintingServiceClassID_UUID16 (0x1119) -#define ImagingServiceClassID_UUID16 (0x111A) -#define ImagingResponderServiceClassID_UUID16 (0x111B) -#define ImagingAutomaticArchiveServiceClassID_UUID16 (0x111C) -#define ImagingReferenceObjectsServiceClassID_UUID16 (0x111D) -#define HandsfreeServiceClassID_UUID16 (0x111E) -#define HandsfreeAudioGatewayServiceClassID_UUID16 (0x111F) -#define DirectPrintingReferenceObjectsServiceClassID_UUID16 \ - (0x1120) -#define ReflectsUIServiceClassID_UUID16 (0x1121) -#define BasicPrintingServiceClassID_UUID16 (0x1122) -#define PrintingStatusServiceClassID_UUID16 (0x1123) -#define HumanInterfaceDeviceServiceClassID_UUID16 (0x1124) -#define HardcopyCableReplacementServiceClassID_UUID16 (0x1125) -#define HCRPrintServiceClassID_UUID16 (0x1126) -#define HCRScanServiceClassID_UUID16 (0x1127) -#define CommonISDNAccessServiceClass_UUID16 (0x1128) -#define VideoConferencingGWServiceClass_UUID16 (0x1129) -#define UDIMTServiceClass_UUID16 (0x112A) -#define UDITAServiceClass_UUID16 (0x112B) -#define AudioVideoServiceClass_UUID16 (0x112C) - -#define PnPInformationServiceClassID_UUID16 (0x1200) -#define GenericNetworkingServiceClassID_UUID16 (0x1201) -#define GenericFileTransferServiceClassID_UUID16 (0x1202) -#define GenericAudioServiceClassID_UUID16 (0x1203) -#define GenericTelephonyServiceClassID_UUID16 (0x1204) - -#endif // NO_GUID_DEFS - -#ifndef GUID_DEFS_ONLY - -// -// max length of device friendly name. -// -#define BTH_MAX_NAME_SIZE (248) - -#define BTH_MAX_PIN_SIZE (16) -#define BTH_LINK_KEY_LENGTH (16) - -#define BTH_MFG_ERICSSON (0) -#define BTH_MFG_NOKIA (1) -#define BTH_MFG_INTEL (2) -#define BTH_MFG_IBM (3) -#define BTH_MFG_TOSHIBA (4) -#define BTH_MFG_3COM (5) -#define BTH_MFG_MICROSOFT (6) -#define BTH_MFG_LUCENT (7) -#define BTH_MFG_MOTOROLA (8) -#define BTH_MFG_INFINEON (9) -#define BTH_MFG_CSR (10) -#define BTH_MFG_SILICONWAVE (11) -#define BTH_MFG_DIGIANSWER (12) -#define BTH_MFG_TI (13) -#define BTH_MFG_PARTHUS (14) -#define BTH_MFG_BROADCOM (15) -#define BTH_MFG_MITEL (16) -#define BTH_MFG_WIDCOMM (17) -#define BTH_MFG_ZEEVO (18) -#define BTH_MFG_ATMEL (19) -#define BTH_MFG_MITSIBUSHI (20) -#define BTH_MFG_RTX_TELECOM (21) -#define BTH_MFG_KC_TECHNOLOGY (22) -#define BTH_MFG_NEWLOGIC (23) -#define BTH_MFG_TRANSILICA (24) -#define BTH_MFG_ROHDE_SCHWARZ (25) -#define BTH_MFG_TTPCOM (26) -#define BTH_MFG_SIGNIA (27) -#define BTH_MFG_CONEXANT (28) -#define BTH_MFG_QUALCOMM (29) -#define BTH_MFG_INVENTEL (30) -#define BTH_MFG_AVM_BERLIN (31) -#define BTH_MFG_BANDSPEED (32) -#define BTH_MFG_MANSELLA (33) -#define BTH_MFG_NEC (34) -#define BTH_MFG_WAVEPLUS_TECHNOLOGY_CO (35) -#define BTH_MFG_ALCATEL (36) -#define BTH_MFG_PHILIPS_SEMICONDUCTOR (37) -#define BTH_MFG_C_TECHNOLOGIES (38) -#define BTH_MFG_OPEN_INTERFACE (39) -#define BTH_MFG_RF_MICRO_DEVICES (40) -#define BTH_MFG_HITACHI (41) -#define BTH_MFG_SYMBOL_TECHNOLOGIES (42) -#define BTH_MFG_TENOVIS (43) -#define BTH_MFG_MACRONIX_INTERNATIONAL (44) -#define BTH_MFG_INTERNAL_USE (65535) - -typedef ULONGLONG BTH_ADDR, *PBTH_ADDR; -typedef ULONG BTH_COD, *PBTH_COD; -typedef ULONG BTH_LAP, *PBTH_LAP; - -#define BTH_ADDR_NULL ((ULONGLONG) 0x0000000000000000) - -#define NAP_MASK ((ULONGLONG) 0xFFFF00000000) -#define SAP_MASK ((ULONGLONG) 0x0000FFFFFFFF) - -#define NAP_BIT_OFFSET (8 * 4) -#define SAP_BIT_OFFSET (0) - -#define GET_NAP(_bth_addr) ((USHORT) (((_bth_addr) & NAP_MASK) >> NAP_BIT_OFFSET)) -#define GET_SAP(_bth_addr) ((ULONG) (((_bth_addr) & SAP_MASK) >> SAP_BIT_OFFSET)) - -#define SET_NAP(_nap) (((ULONGLONG) ((USHORT) (_nap))) << NAP_BIT_OFFSET) -#define SET_SAP(_sap) (((ULONGLONG) ((ULONG) (_sap))) << SAP_BIT_OFFSET) - -#define SET_NAP_SAP(_nap, _sap) (SET_NAP(_nap) | SET_SAP(_sap)) - -#define COD_FORMAT_BIT_OFFSET (0) -#define COD_MINOR_BIT_OFFSET (2) -#define COD_MAJOR_BIT_OFFSET (8 * 1) -#define COD_SERVICE_BIT_OFFSET (8 * 1 + 5) - -#define COD_FORMAT_MASK (0x000003) -#define COD_MINOR_MASK (0x0000FC) -#define COD_MAJOR_MASK (0x001F00) -#define COD_SERVICE_MASK (0xFFE000) - - -#define GET_COD_FORMAT(_cod) ( (_cod) & COD_FORMAT_MASK >> COD_FORMAT_BIT_OFFSET) -#define GET_COD_MINOR(_cod) (((_cod) & COD_MINOR_MASK) >> COD_MINOR_BIT_OFFSET) -#define GET_COD_MAJOR(_cod) (((_cod) & COD_MAJOR_MASK) >> COD_MAJOR_BIT_OFFSET) -#define GET_COD_SERVICE(_cod) (((_cod) & COD_SERVICE_MASK) >> COD_SERVICE_BIT_OFFSET) - -#define SET_COD_MINOR(_cod, _minor) (_cod) = ((_cod) & ~COD_MINOR_MASK) | ((_minor) << COD_MINOR_BIT_OFFSET) -#define SET_COD_MAJOR(_cod, _major) (_cod) = ((_cod) & ~COD_MAJOR_MASK) | ((_major) << COD_MAJOR_BIT_OFFSET) -#define SET_COD_SERVICE(_cod, _service) (_cod) = ((_cod) & ~COD_SERVICE_MASK) | ((_service) << COD_SERVICE_BIT_OFFSET) - -#define COD_VERSION (0x0) - -#define COD_SERVICE_LIMITED (0x0001) -#define COD_SERVICE_POSITIONING (0x0008) -#define COD_SERVICE_NETWORKING (0x0010) -#define COD_SERVICE_RENDERING (0x0020) -#define COD_SERVICE_CAPTURING (0x0040) -#define COD_SERVICE_OBJECT_XFER (0x0080) -#define COD_SERVICE_AUDIO (0x0100) -#define COD_SERVICE_TELEPHONY (0x0200) -#define COD_SERVICE_INFORMATION (0x0400) - -#define COD_SERVICE_VALID_MASK (COD_SERVICE_LIMITED | \ - COD_SERVICE_POSITIONING | \ - COD_SERVICE_NETWORKING | \ - COD_SERVICE_RENDERING | \ - COD_SERVICE_CAPTURING | \ - COD_SERVICE_OBJECT_XFER |\ - COD_SERVICE_AUDIO |\ - COD_SERVICE_TELEPHONY |\ - COD_SERVICE_INFORMATION) - -#define COD_SERVICE_MAX_COUNT (9) - -// -// Major class codes -// -#define COD_MAJOR_MISCELLANEOUS (0x00) -#define COD_MAJOR_COMPUTER (0x01) -#define COD_MAJOR_PHONE (0x02) -#define COD_MAJOR_LAN_ACCESS (0x03) -#define COD_MAJOR_AUDIO (0x04) -#define COD_MAJOR_PERIPHERAL (0x05) -#define COD_MAJOR_IMAGING (0x06) -#define COD_MAJOR_UNCLASSIFIED (0x1F) - -// -// Minor class codes specific to each major class -// -#define COD_COMPUTER_MINOR_UNCLASSIFIED (0x00) -#define COD_COMPUTER_MINOR_DESKTOP (0x01) -#define COD_COMPUTER_MINOR_SERVER (0x02) -#define COD_COMPUTER_MINOR_LAPTOP (0x03) -#define COD_COMPUTER_MINOR_HANDHELD (0x04) -#define COD_COMPUTER_MINOR_PALM (0x05) -#define COD_COMPUTER_MINOR_WEARABLE (0x06) - -#define COD_PHONE_MINOR_UNCLASSIFIED (0x00) -#define COD_PHONE_MINOR_CELLULAR (0x01) -#define COD_PHONE_MINOR_CORDLESS (0x02) -#define COD_PHONE_MINOR_SMART (0x03) -#define COD_PHONE_MINOR_WIRED_MODEM (0x04) - -#define COD_AUDIO_MINOR_UNCLASSIFIED (0x00) -#define COD_AUDIO_MINOR_HEADSET (0x01) -#define COD_AUDIO_MINOR_HANDS_FREE (0x02) -#define COD_AUDIO_MINOR_HEADSET_HANDS_FREE (0x03) -#define COD_AUDIO_MINOR_MICROPHONE (0x04) -#define COD_AUDIO_MINOR_LOUDSPEAKER (0x05) -#define COD_AUDIO_MINOR_HEADPHONES (0x06) -#define COD_AUDIO_MINOR_PORTABLE_AUDIO (0x07) -#define COD_AUDIO_MINOR_CAR_AUDIO (0x08) -#define COD_AUDIO_MINOR_SET_TOP_BOX (0x09) -#define COD_AUDIO_MINOR_HIFI_AUDIO (0x0A) -#define COD_AUDIO_MINOR_VCR (0x0B) -#define COD_AUDIO_MINOR_VIDEO_CAMERA (0x0C) -#define COD_AUDIO_MINOR_CAMCORDER (0x0D) -#define COD_AUDIO_MINOR_VIDEO_MONITOR (0x0E) -#define COD_AUDIO_MINOR_VIDEO_DISPLAY_LOUDSPEAKER \ - (0x0F) -#define COD_AUDIO_MINOR_VIDEO_DISPLAY_CONFERENCING \ - (0x10) -// #define COD_AUDIO_MINOR_RESERVED (0x11) -#define COD_AUDIO_MINOR_GAMING_TOY (0x12) - -#define COD_PERIPHERAL_MINOR_KEYBOARD_MASK (0x10) -#define COD_PERIPHERAL_MINOR_POINTER_MASK (0x20) - -#define COD_PERIPHERAL_MINOR_NO_CATEGORY (0x00) -#define COD_PERIPHERAL_MINOR_JOYSTICK (0x01) -#define COD_PERIPHERAL_MINOR_GAMEPAD (0x02) -#define COD_PERIPHERAL_MINOR_REMOTE_CONTROL (0x03) -#define COD_PERIPHERAL_MINOR_SENSING (0x04) - -#define COD_IMAGING_MINOR_DISPLAY_MASK (0x04) -#define COD_IMAGING_MINOR_CAMERA_MASK (0x08) -#define COD_IMAGING_MINOR_SCANNER_MASK (0x10) -#define COD_IMAGING_MINOR_PRINTER_MASK (0x20) - -// -// Cannot use GET_COD_MINOR for this b/c it is embedded in a different manner -// than the rest of the major classes -// - -#define COD_LAN_ACCESS_BIT_OFFSET (5) - -#define COD_LAN_MINOR_MASK (0x00001C) -#define COD_LAN_ACCESS_MASK (0x0000E0) - -#define GET_COD_LAN_MINOR(_cod) (((_cod) & COD_LAN_MINOR_MASK) >> COD_MINOR_BIT_OFFSET) -#define GET_COD_LAN_ACCESS(_cod) (((_cod) & COD_LAN_ACCESS_MASK) >> COD_LAN_ACCESS_BIT_OFFSET) - -// -// LAN access percent usage subcodes -// -#define COD_LAN_MINOR_UNCLASSIFIED (0x00) - -#define COD_LAN_ACCESS_0_USED (0x00) -#define COD_LAN_ACCESS_17_USED (0x01) -#define COD_LAN_ACCESS_33_USED (0x02) -#define COD_LAN_ACCESS_50_USED (0x03) -#define COD_LAN_ACCESS_67_USED (0x04) -#define COD_LAN_ACCESS_83_USED (0x05) -#define COD_LAN_ACCESS_99_USED (0x06) -#define COD_LAN_ACCESS_FULL (0x07) - -// -// Used as an initializer of LAP_DATA -// -#define LAP_GIAC_INIT { 0x33, 0x8B, 0x9E } -#define LAP_LIAC_INIT { 0x00, 0x8B, 0x9E } - -// -// General Inquiry Access Code. -// -#define LAP_GIAC_VALUE (0x009E8B33) - -// -// Limited Inquiry Access Code. -// -#define LAP_LIAC_VALUE (0x009E8B00) - -#define BTH_ADDR_IAC_FIRST (0x9E8B00) -#define BTH_ADDR_IAC_LAST (0x9E8B3f) -#define BTH_ADDR_LIAC (0x9E8B00) -#define BTH_ADDR_GIAC (0x9E8B33) - -typedef UCHAR BTHSTATUS, *PBTHSTATUS; - -#define BTH_ERROR(_btStatus) ((_btStatus) != BTH_ERROR_SUCCESS) -#define BTH_SUCCESS(_btStatus) ((_btStatus) == BTH_ERROR_SUCCESS) - -#define BTH_ERROR_SUCCESS (0x00) -#define BTH_ERROR_UNKNOWN_HCI_COMMAND (0x01) -#define BTH_ERROR_NO_CONNECTION (0x02) -#define BTH_ERROR_HARDWARE_FAILURE (0x03) -#define BTH_ERROR_PAGE_TIMEOUT (0x04) -#define BTH_ERROR_AUTHENTICATION_FAILURE (0x05) -#define BTH_ERROR_KEY_MISSING (0x06) -#define BTH_ERROR_MEMORY_FULL (0x07) -#define BTH_ERROR_CONNECTION_TIMEOUT (0x08) -#define BTH_ERROR_MAX_NUMBER_OF_CONNECTIONS (0x09) -#define BTH_ERROR_MAX_NUMBER_OF_SCO_CONNECTIONS (0x0a) -#define BTH_ERROR_ACL_CONNECTION_ALREADY_EXISTS (0x0b) -#define BTH_ERROR_COMMAND_DISALLOWED (0x0c) -#define BTH_ERROR_HOST_REJECTED_LIMITED_RESOURCES (0x0d) -#define BTH_ERROR_HOST_REJECTED_SECURITY_REASONS (0x0e) -#define BTH_ERROR_HOST_REJECTED_PERSONAL_DEVICE (0x0f) -#define BTH_ERROR_HOST_TIMEOUT (0x10) -#define BTH_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER (0x11) -#define BTH_ERROR_INVALID_HCI_PARAMETER (0x12) -#define BTH_ERROR_REMOTE_USER_ENDED_CONNECTION (0x13) -#define BTH_ERROR_REMOTE_LOW_RESOURCES (0x14) -#define BTH_ERROR_REMOTE_POWERING_OFF (0x15) -#define BTH_ERROR_LOCAL_HOST_TERMINATED_CONNECTION (0x16) -#define BTH_ERROR_REPEATED_ATTEMPTS (0x17) -#define BTH_ERROR_PAIRING_NOT_ALLOWED (0x18) -#define BTH_ERROR_UKNOWN_LMP_PDU (0x19) -#define BTH_ERROR_UNSUPPORTED_REMOTE_FEATURE (0x1a) -#define BTH_ERROR_SCO_OFFSET_REJECTED (0x1b) -#define BTH_ERROR_SCO_INTERVAL_REJECTED (0x1c) -#define BTH_ERROR_SCO_AIRMODE_REJECTED (0x1d) -#define BTH_ERROR_INVALID_LMP_PARAMETERS (0x1e) -#define BTH_ERROR_UNSPECIFIED_ERROR (0x1f) -#define BTH_ERROR_UNSUPPORTED_LMP_PARM_VALUE (0x20) -#define BTH_ERROR_ROLE_CHANGE_NOT_ALLOWED (0x21) -#define BTH_ERROR_LMP_RESPONSE_TIMEOUT (0x22) -#define BTH_ERROR_LMP_TRANSACTION_COLLISION (0x23) -#define BTH_ERROR_LMP_PDU_NOT_ALLOWED (0x24) -#define BTH_ERROR_ENCRYPTION_MODE_NOT_ACCEPTABLE (0x25) -#define BTH_ERROR_UNIT_KEY_NOT_USED (0x26) -#define BTH_ERROR_QOS_IS_NOT_SUPPORTED (0x27) -#define BTH_ERROR_INSTANT_PASSED (0x28) -#define BTH_ERROR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED (0x29) - -#define BTH_ERROR_UNSPECIFIED (0xFF) - -// -// Min, max, and default L2cap MTU. -// -#define L2CAP_MIN_MTU (48) -#define L2CAP_MAX_MTU (0xFFFF) -#define L2CAP_DEFAULT_MTU (672) - -// -// Max l2cap signal size (48) - size of signal header (4) -// -#define MAX_L2CAP_PING_DATA_LENGTH (44) -#define MAX_L2CAP_INFO_DATA_LENGTH (44) - -// -// the following two structures provides information about -// disocvered remote radios. -// - -#define BDIF_ADDRESS (0x00000001) -#define BDIF_COD (0x00000002) -#define BDIF_NAME (0x00000004) -#define BDIF_PAIRED (0x00000008) -#define BDIF_PERSONAL (0x00000010) -#define BDIF_CONNECTED (0x00000020) - -#define BDIF_VALID_FLAGS \ - (BDIF_ADDRESS | BDIF_COD | BDIF_NAME | BDIF_PAIRED | BDIF_PERSONAL | \ - BDIF_CONNECTED) - -typedef struct _BTH_DEVICE_INFO { - // - // Combination BDIF_Xxx flags - // - ULONG flags; - - // - // Address of remote device. - // - BTH_ADDR address; - - // - // Class Of Device. - // - BTH_COD classOfDevice; - - // - // name of the device - // - CHAR name[BTH_MAX_NAME_SIZE]; - -} BTH_DEVICE_INFO, *PBTH_DEVICE_INFO; - -// -// Buffer associated with GUID_BLUETOOTH_RADIO_IN_RANGE -// -typedef struct _BTH_RADIO_IN_RANGE { - // - // Information about the remote radio - // - BTH_DEVICE_INFO deviceInfo; - - // - // The previous flags value for the BTH_DEVICE_INFO. The receiver of this - // notification can compare the deviceInfo.flags and previousDeviceFlags - // to determine what has changed about this remote radio. - // - // For instance, if BDIF_NAME is set in deviceInfo.flags and not in - // previousDeviceFlags, the remote radio's has just been retrieved. - // - ULONG previousDeviceFlags; - -} BTH_RADIO_IN_RANGE, *PBTH_RADIO_IN_RANGE; - -// -// Buffer associated with GUID_BLUETOOTH_L2CAP_EVENT -// -typedef struct _BTH_L2CAP_EVENT_INFO { - // - // Remote radio address which the L2CAP event is associated with - // - BTH_ADDR bthAddress; - - // - // The PSM that is either being connected to or disconnected from - // - USHORT psm; - - // - // If != 0, then the channel has just been established. If == 0, then the - // channel has been destroyed. Notifications for a destroyed channel will - // only be sent for channels successfully established. - // - UCHAR connected; - - // - // If != 0, then the local host iniated the l2cap connection. If == 0, then - // the remote host initated the connection. This field is only valid if - // connect is != 0. - // - UCHAR initiated; - -} BTH_L2CAP_EVENT_INFO, *PBTH_L2CAP_EVENT_INFO; - -#define HCI_CONNNECTION_TYPE_ACL (1) -#define HCI_CONNNECTION_TYPE_SCO (2) - -// -// Buffer associated with GUID_BLUETOOTH_HCI_EVENT -// -typedef struct _BTH_HCI_EVENT_INFO { - // - // Remote radio address which the HCI event is associated with - // - BTH_ADDR bthAddress; - - // - // HCI_CONNNECTION_TYPE_XXX value - // - UCHAR connectionType; - - // - // If != 0, then the underlying connection to the remote radio has just - // been estrablished. If == 0, then the underlying conneciton has just been - // destroyed. - // - UCHAR connected; - -} BTH_HCI_EVENT_INFO, *PBTH_HCI_EVENT_INFO; - -#define MAX_UUIDS_IN_QUERY (12) - -#define BTH_VID_DEFAULT_VALUE (0xFFFF) - -#define SDP_ERROR_INVALID_SDP_VERSION (0x0001) -#define SDP_ERROR_INVALID_RECORD_HANDLE (0x0002) -#define SDP_ERROR_INVALID_REQUEST_SYNTAX (0x0003) -#define SDP_ERROR_INVALID_PDU_SIZE (0x0004) -#define SDP_ERROR_INVALID_CONTINUATION_STATE (0x0005) -#define SDP_ERROR_INSUFFICIENT_RESOURCES (0x0006) - -// -// Defined by windows to handle server errors that are not described by the -// above errors. Start at 0x0100 so we don't go anywhere near the spec -// defined values. -// - -// -// Success, nothing went wrong -// -#define SDP_ERROR_SUCCESS ((SDP_ERROR) 0x0000) - -// -// The SDP PDU or parameters other than the SDP stream response was not correct -// -#define SDP_ERROR_SERVER_INVALID_RESPONSE ((SDP_ERROR) 0x0100) - -// -// The SDP response stream did not parse correctly. -// -#define SDP_ERROR_SERVER_RESPONSE_DID_NOT_PARSE ((SDP_ERROR) 0x0200) - -// -// The SDP response stream was successfully parsed, but did not match the -// required format for the query. -// -#define SDP_ERROR_SERVER_BAD_FORMAT ((SDP_ERROR) 0x0300) - -// -// SDP was unable to send a continued query back to the server -// -#define SDP_ERROR_COULD_NOT_SEND_CONTINUE ((SDP_ERROR) 0x0400) - -// -// Server sent a response that was too large to fit in the caller's buffer. -// -#define SDP_ERROR_RESPONSE_TOO_LARGE ((SDP_ERROR) 0x0500) - - -#define SDP_ATTRIB_RECORD_HANDLE (0x0000) -#define SDP_ATTRIB_CLASS_ID_LIST (0x0001) -#define SDP_ATTRIB_RECORD_STATE (0x0002) -#define SDP_ATTRIB_SERVICE_ID (0x0003) -#define SDP_ATTRIB_PROTOCOL_DESCRIPTOR_LIST (0x0004) -#define SDP_ATTRIB_BROWSE_GROUP_LIST (0x0005) -#define SDP_ATTRIB_LANG_BASE_ATTRIB_ID_LIST (0x0006) -#define SDP_ATTRIB_INFO_TIME_TO_LIVE (0x0007) -#define SDP_ATTRIB_AVAILABILITY (0x0008) -#define SDP_ATTRIB_PROFILE_DESCRIPTOR_LIST (0x0009) -#define SDP_ATTRIB_DOCUMENTATION_URL (0x000A) -#define SDP_ATTRIB_CLIENT_EXECUTABLE_URL (0x000B) -#define SDP_ATTRIB_ICON_URL (0x000C) -#define SDP_ATTRIB_ADDITIONAL_PROTOCOL_DESCRIPTOR_LIST \ - (0x000D) - -// -// Attribute IDs in the range of 0x000D - 0x01FF are reserved for future use -// -#define SDP_ATTRIB_PROFILE_SPECIFIC (0x0200) - -#define LANG_BASE_LANGUAGE_INDEX (0x0000) -#define LANG_BASE_ENCODING_INDEX (0x0001) -#define LANG_BASE_OFFSET_INDEX (0x0002) -#define LANG_DEFAULT_ID (0x0100) - -#define STRING_NAME_OFFSET (0x0000) -#define STRING_DESCRIPTION_OFFSET (0x0001) -#define STRING_PROVIDER_NAME_OFFSET (0x0002) - -#define SDP_ATTRIB_SDP_VERSION_NUMBER_LIST (0x0200) -#define SDP_ATTRIB_SDP_DATABASE_STATE (0x0201) - -#define SDP_ATTRIB_BROWSE_GROUP_ID (0x0200) - -#define SDP_ATTRIB_CORDLESS_EXTERNAL_NETWORK (0x0301) - -#define SDP_ATTRIB_FAX_CLASS_1_SUPPORT (0x0302) -#define SDP_ATTRIB_FAX_CLASS_2_0_SUPPORT (0x0303) -#define SDP_ATTRIB_FAX_CLASS_2_SUPPORT (0x0304) -#define SDP_ATTRIB_FAX_AUDIO_FEEDBACK_SUPPORT (0x0305) - -#define SDP_ATTRIB_HEADSET_REMOTE_AUDIO_VOLUME_CONTROL (0x0302) - -#define SDP_ATTRIB_LAN_LPSUBNET (0x0200) - -#define SDP_ATTRIB_OBJECT_PUSH_SUPPORTED_FORMATS_LIST (0x0303) - -#define SDP_ATTRIB_SYNCH_SUPPORTED_DATA_STORES_LIST (0x0301) - -// this is in the assigned numbers doc, but it does not show up in any profile -#define SDP_ATTRIB_SERVICE_VERSION (0x0300) - -#define SDP_ATTRIB_PAN_NETWORK_ADDRESS (0x0306) -#define SDP_ATTRIB_PAN_WAP_GATEWAY (0x0307) -#define SDP_ATTRIB_PAN_HOME_PAGE_URL (0x0308) -#define SDP_ATTRIB_PAN_WAP_STACK_TYPE (0x0309) -#define SDP_ATTRIB_PAN_SECURITY_DESCRIPTION (0x030A) -#define SDP_ATTRIB_PAN_NET_ACCESS_TYPE (0x030B) -#define SDP_ATTRIB_PAN_MAX_NET_ACCESS_RATE (0x030C) - -#define SDP_ATTRIB_IMAGING_SUPPORTED_CAPABILITIES (0x0310) -#define SDP_ATTRIB_IMAGING_SUPPORTED_FEATURES (0x0311) -#define SDP_ATTRIB_IMAGING_SUPPORTED_FUNCTIONS (0x0312) -#define SDP_ATTRIB_IMAGING_TOTAL_DATA_CAPACITY (0x0313) - -#define SDP_ATTRIB_DI_SPECIFICATION_ID (0x0200) -#define SDP_ATTRIB_DI_VENDOR_ID (0x0201) -#define SDP_ATTRIB_DI_PRODUCT_ID (0x0202) -#define SDP_ATTRIB_DI_VERSION (0x0203) -#define SDP_ATTRIB_DI_PRIMARY_RECORD (0x0204) -#define SDP_ATTRIB_DI_VENDOR_ID_SOURCE (0x0205) - -#define SDP_ATTRIB_HID_DEVICE_RELEASE_NUMBER (0x0200) -#define SDP_ATTRIB_HID_PARSER_VERSION (0x0201) -#define SDP_ATTRIB_HID_DEVICE_SUBCLASS (0x0202) -#define SDP_ATTRIB_HID_COUNTRY_CODE (0x0203) -#define SDP_ATTRIB_HID_VIRTUAL_CABLE (0x0204) -#define SDP_ATTRIB_HID_RECONNECT_INITIATE (0x0205) -#define SDP_ATTRIB_HID_DESCRIPTOR_LIST (0x0206) -#define SDP_ATTRIB_HID_LANG_ID_BASE_LIST (0x0207) -#define SDP_ATTRIB_HID_SDP_DISABLE (0x0208) -#define SDP_ATTRIB_HID_BATTERY_POWER (0x0209) -#define SDP_ATTRIB_HID_REMOTE_WAKE (0x020A) -#define SDP_ATTRIB_HID_REPORT_LIST (0x020B) -#define SDP_ATTRIB_HID_SUPERVISION_TIMEOUT (0x020C) -#define SDP_ATTRIB_HID_NORMALLY_CONNECTABLE (0x020D) -#define SDP_ATTRIB_HID_BOOT_DEVICE (0x020E) - -// -// Profile specific values -// -#define CORDLESS_EXTERNAL_NETWORK_PSTN (0x01) -#define CORDLESS_EXTERNAL_NETWORK_ISDN (0x02) -#define CORDLESS_EXTERNAL_NETWORK_GSM (0x03) -#define CORDLESS_EXTERNAL_NETWORK_CDMA (0x04) -#define CORDLESS_EXTERNAL_NETWORK_ANALOG_CELLULAR (0x05) -#define CORDLESS_EXTERNAL_NETWORK_PACKET_SWITCHED (0x06) -#define CORDLESS_EXTERNAL_NETWORK_OTHER (0x07) - -#define OBJECT_PUSH_FORMAT_VCARD_2_1 (0x01) -#define OBJECT_PUSH_FORMAT_VCARD_3_0 (0x02) -#define OBJECT_PUSH_FORMAT_VCAL_1_0 (0x03) -#define OBJECT_PUSH_FORMAT_ICAL_2_0 (0x04) -#define OBJECT_PUSH_FORMAT_VNOTE (0x05) -#define OBJECT_PUSH_FORMAT_VMESSAGE (0x06) -#define OBJECT_PUSH_FORMAT_ANY (0xFF) - -#define SYNCH_DATA_STORE_PHONEBOOK (0x01) -#define SYNCH_DATA_STORE_CALENDAR (0x03) -#define SYNCH_DATA_STORE_NOTES (0x05) -#define SYNCH_DATA_STORE_MESSAGES (0x06) - -#define DI_VENDOR_ID_SOURCE_BLUETOOTH_SIG (0x0001) -#define DI_VENDOR_ID_SOURCE_USB_IF (0x0002) - -#define PSM_SDP (0x0001) -#define PSM_RFCOMM (0x0003) -#define PSM_TCS_BIN (0x0005) -#define PSM_TCS_BIN_CORDLESS (0x0007) -#define PSM_BNEP (0x000F) -#define PSM_HID_CONTROL (0x0011) -#define PSM_HID_INTERRUPT (0x0013) -#define PSM_AVCTP (0x0017) -#define PSM_AVDTP (0x0019) -#define PSM_UDI_C_PLANE (0x001D) - -// -// Strings -// -#define STR_ADDR_FMTA "(%02x:%02x:%02x:%02x:%02x:%02x)" -#define STR_ADDR_FMTW L"(%02x:%02x:%02x:%02x:%02x:%02x)" - -#define STR_ADDR_SHORT_FMTA "%04x%08x" -#define STR_ADDR_SHORT_FMTW L"%04x%08x" - -#if defined(UNICODE) || defined(BTH_KERN) - -#define STR_ADDR_FMT STR_ADDR_FMTW -#define STR_ADDR_SHORT_FMT STR_ADDR_SHORT_FMTW - -#else // UNICODE - -#define STR_ADDR_FMT STR_ADDR_FMTA -#define STR_ADDR_SHORT_FMT STR_ADDR_SHORT_FMTA - -#endif // UNICODE - -#define GET_BITS(field,offset,mask) ( ( (field) >> (offset) ) & (mask) ) -#define GET_BIT(field,offset) ( GET_BITS(field,offset,0x1) ) - -#define LMP_3_SLOT_PACKETS(x) (GET_BIT(x, 0)) -#define LMP_5_SLOT_PACKETS(x) (GET_BIT(x, 1)) -#define LMP_ENCRYPTION(x) (GET_BIT(x, 2)) -#define LMP_SLOT_OFFSET(x) (GET_BIT(x, 3)) -#define LMP_TIMING_ACCURACY(x) (GET_BIT(x, 4)) -#define LMP_SWITCH(x) (GET_BIT(x, 5)) -#define LMP_HOLD_MODE(x) (GET_BIT(x, 6)) -#define LMP_SNIFF_MODE(x) (GET_BIT(x, 7)) -#define LMP_PARK_MODE(x) (GET_BIT(x, 8)) -#define LMP_RSSI(x) (GET_BIT(x, 9)) -#define LMP_CHANNEL_QUALITY_DRIVEN_MODE(x) (GET_BIT(x,10)) -#define LMP_SCO_LINK(x) (GET_BIT(x,11)) -#define LMP_HV2_PACKETS(x) (GET_BIT(x,12)) -#define LMP_HV3_PACKETS(x) (GET_BIT(x,13)) -#define LMP_MU_LAW_LOG(x) (GET_BIT(x,14)) -#define LMP_A_LAW_LOG(x) (GET_BIT(x,15)) -#define LMP_CVSD(x) (GET_BIT(x,16)) -#define LMP_PAGING_SCHEME(x) (GET_BIT(x,17)) -#define LMP_POWER_CONTROL(x) (GET_BIT(x,18)) -#define LMP_TRANSPARENT_SCO_DATA(x) (GET_BIT(x,19)) -#define LMP_FLOW_CONTROL_LAG(x) (GET_BITS(x,20,0x3)) - -#endif // GUID_DEFS_ONLY - -#endif // __BTHDEF_H__ diff --git a/cpp/wiipair/include/bthsdpdef.h b/cpp/wiipair/include/bthsdpdef.h deleted file mode 100644 index d4027f1..0000000 --- a/cpp/wiipair/include/bthsdpdef.h +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef __BTHSDPDEF_H__ -#define __BTHSDPDEF_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -struct SDP_LARGE_INTEGER_16 { - ULONGLONG LowPart; - LONGLONG HighPart; -}; - - -struct SDP_ULARGE_INTEGER_16 { - ULONGLONG LowPart; - ULONGLONG HighPart; -}; - -typedef struct SDP_ULARGE_INTEGER_16 SDP_ULARGE_INTEGER_16, *PSDP_ULARGE_INTEGER_16, *LPSDP_ULARGE_INTEGER_16; -typedef struct SDP_LARGE_INTEGER_16 SDP_LARGE_INTEGER_16, *PSDP_LARGE_INTEGER_16, *LPSDP_LARGE_INTEGER_16; - -enum NodeContainerType { - NodeContainerTypeSequence, - NodeContainerTypeAlternative -}; - -typedef enum NodeContainerType NodeContainerType; - -typedef USHORT SDP_ERROR, *PSDP_ERROR; - -enum SDP_TYPE { - SDP_TYPE_NIL = 0x00, - SDP_TYPE_UINT = 0x01, - SDP_TYPE_INT = 0x02, - SDP_TYPE_UUID = 0x03, - SDP_TYPE_STRING = 0x04, - SDP_TYPE_BOOLEAN = 0x05, - SDP_TYPE_SEQUENCE = 0x06, - SDP_TYPE_ALTERNATIVE = 0x07, - SDP_TYPE_URL = 0x08, - SDP_TYPE_CONTAINER = 0x20 -}; -// 9 - 31 are reserved -typedef enum SDP_TYPE SDP_TYPE; - -// allow for a little easier type checking / sizing for integers and UUIDs -// ((SDP_ST_XXX & 0xF0) >> 4) == SDP_TYPE_XXX -// size of the data (in bytes) is encoded as ((SDP_ST_XXX & 0xF0) >> 8) -enum SDP_SPECIFICTYPE { - SDP_ST_NONE = 0x0000, - - SDP_ST_UINT8 = 0x0010, - SDP_ST_UINT16 = 0x0110, - SDP_ST_UINT32 = 0x0210, - SDP_ST_UINT64 = 0x0310, - SDP_ST_UINT128 = 0x0410, - - SDP_ST_INT8 = 0x0020, - SDP_ST_INT16 = 0x0120, - SDP_ST_INT32 = 0x0220, - SDP_ST_INT64 = 0x0320, - SDP_ST_INT128 = 0x0420, - - SDP_ST_UUID16 = 0x0130, - SDP_ST_UUID32 = 0x0220, - SDP_ST_UUID128 = 0x0430 -}; -typedef enum SDP_SPECIFICTYPE SDP_SPECIFICTYPE; - -typedef struct _SdpAttributeRange { - USHORT minAttribute; - USHORT maxAttribute; -} SdpAttributeRange; - - -typedef -#ifdef USE_MIDL_SYNTAX - [switch_type(unsigned short)] -#endif - union SdpQueryUuidUnion { -#ifdef USE_MIDL_SYNTAX - [case(SDP_ST_UUID128)] -#endif - GUID uuid128; - -#ifdef USE_MIDL_SYNTAX - [case(SDP_ST_UUID32)] -#endif _NTDDK_ - ULONG uuid32; - -#ifdef USE_MIDL_SYNTAX - [case(SDP_ST_UUID16)] -#endif _NTDDK_ - USHORT uuid16; -} SdpQueryUuidUnion; - -typedef struct _SdpQueryUuid { -#ifdef USE_MIDL_SYNTAX - [switch_is(uuidType)] -#endif - SdpQueryUuidUnion u; - - USHORT uuidType; -} SdpQueryUuid; - - -#ifdef __cplusplus -}; -#endif - -#endif // __BTHSDPDEF_H__ diff --git a/cpp/wiipair/include/strsafe.h b/cpp/wiipair/include/strsafe.h deleted file mode 100644 index f725eae..0000000 --- a/cpp/wiipair/include/strsafe.h +++ /dev/null @@ -1,6611 +0,0 @@ -/****************************************************************** -* * -* strsafe.h -- This module defines safer C library string * -* routine replacements. These are meant to make C * -* a bit more safe in reference to security and * -* robustness * -* * -* Copyright (c) Microsoft Corp. All rights reserved. * -* * -******************************************************************/ -#ifndef _STRSAFE_H_INCLUDED_ -#define _STRSAFE_H_INCLUDED_ -#pragma once - -#include // for _vsnprintf, _vsnwprintf, getc, getwc -#include // for memset -#include // for va_start, etc. - - -#ifndef _SIZE_T_DEFINED -#ifdef _WIN64 -typedef unsigned __int64 size_t; -#else -typedef __w64 unsigned int size_t; -#endif // !_WIN64 -#define _SIZE_T_DEFINED -#endif // !_SIZE_T_DEFINED - -#if !defined(_WCHAR_T_DEFINED) && !defined(_NATIVE_WCHAR_T_DEFINED) -typedef unsigned short wchar_t; -#define _WCHAR_T_DEFINED -#endif - -#ifndef _HRESULT_DEFINED -#define _HRESULT_DEFINED -typedef long HRESULT; -#endif // !_HRESULT_DEFINED - -#ifndef SUCCEEDED -#define SUCCEEDED(hr) ((HRESULT)(hr) >= 0) -#endif - -#ifndef FAILED -#define FAILED(hr) ((HRESULT)(hr) < 0) -#endif - -#ifndef S_OK -#define S_OK ((HRESULT)0x00000000L) -#endif - -#ifdef __cplusplus -#define _STRSAFE_EXTERN_C extern "C" -#else -#define _STRSAFE_EXTERN_C extern -#endif - -// If you do not want to use these functions inline (and instead want to link w/ strsafe.lib), then -// #define STRSAFE_LIB before including this header file. -#if defined(STRSAFE_LIB) -#define STRSAFEAPI _STRSAFE_EXTERN_C HRESULT __stdcall -#pragma comment(lib, "strsafe.lib") -#elif defined(STRSAFE_LIB_IMPL) -#define STRSAFEAPI _STRSAFE_EXTERN_C HRESULT __stdcall -#else -#define STRSAFEAPI __inline HRESULT __stdcall -#define STRSAFE_INLINE -#endif - -// Some functions always run inline because they use stdin and we want to avoid building multiple -// versions of strsafe lib depending on if you use msvcrt, libcmt, etc. -#define STRSAFE_INLINE_API __inline HRESULT __stdcall - -// The user can request no "Cb" or no "Cch" fuctions, but not both! -#if defined(STRSAFE_NO_CB_FUNCTIONS) && defined(STRSAFE_NO_CCH_FUNCTIONS) -#error cannot specify both STRSAFE_NO_CB_FUNCTIONS and STRSAFE_NO_CCH_FUNCTIONS !! -#endif - -// This should only be defined when we are building strsafe.lib -#ifdef STRSAFE_LIB_IMPL -#define STRSAFE_INLINE -#endif - - -// If both strsafe.h and ntstrsafe.h are included, only use definitions from one. -#ifndef _NTSTRSAFE_H_INCLUDED_ - -#define STRSAFE_MAX_CCH 2147483647 // max # of characters we support (same as INT_MAX) - -// Flags for controling the Ex functions -// -// STRSAFE_FILL_BYTE(0xFF) 0x000000FF // bottom byte specifies fill pattern -#define STRSAFE_IGNORE_NULLS 0x00000100 // treat null as TEXT("") -- don't fault on NULL buffers -#define STRSAFE_FILL_BEHIND_NULL 0x00000200 // fill in extra space behind the null terminator -#define STRSAFE_FILL_ON_FAILURE 0x00000400 // on failure, overwrite pszDest with fill pattern and null terminate it -#define STRSAFE_NULL_ON_FAILURE 0x00000800 // on failure, set *pszDest = TEXT('\0') -#define STRSAFE_NO_TRUNCATION 0x00001000 // instead of returning a truncated result, copy/append nothing to pszDest and null terminate it - -#define STRSAFE_VALID_FLAGS (0x000000FF | STRSAFE_IGNORE_NULLS | STRSAFE_FILL_BEHIND_NULL | STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION) - -// helper macro to set the fill character and specify buffer filling -#define STRSAFE_FILL_BYTE(x) ((unsigned long)((x & 0x000000FF) | STRSAFE_FILL_BEHIND_NULL)) -#define STRSAFE_FAILURE_BYTE(x) ((unsigned long)((x & 0x000000FF) | STRSAFE_FILL_ON_FAILURE)) - -#define STRSAFE_GET_FILL_PATTERN(dwFlags) ((int)(dwFlags & 0x000000FF)) - -#endif // _NTSTRSAFE_H_INCLUDED_ - -// STRSAFE error return codes -// -#define STRSAFE_E_INSUFFICIENT_BUFFER ((HRESULT)0x8007007AL) // 0x7A = 122L = ERROR_INSUFFICIENT_BUFFER -#define STRSAFE_E_INVALID_PARAMETER ((HRESULT)0x80070057L) // 0x57 = 87L = ERROR_INVALID_PARAMETER -#define STRSAFE_E_END_OF_FILE ((HRESULT)0x80070026L) // 0x26 = 38L = ERROR_HANDLE_EOF - -// prototypes for the worker functions -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCopyWorkerA(char* pszDest, size_t cchDest, const char* pszSrc); -STRSAFEAPI StringCopyWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc); -STRSAFEAPI StringCopyExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFEAPI StringCopyExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFEAPI StringCopyNWorkerA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchSrc); -STRSAFEAPI StringCopyNWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchSrc); -STRSAFEAPI StringCopyNExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, size_t cchSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFEAPI StringCopyNExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, size_t cchSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFEAPI StringCatWorkerA(char* pszDest, size_t cchDest, const char* pszSrc); -STRSAFEAPI StringCatWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc); -STRSAFEAPI StringCatExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFEAPI StringCatExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFEAPI StringCatNWorkerA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchMaxAppend); -STRSAFEAPI StringCatNWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchMaxAppend); -STRSAFEAPI StringCatNExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, size_t cchMaxAppend, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFEAPI StringCatNExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, size_t cchMaxAppend, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFEAPI StringVPrintfWorkerA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList); -STRSAFEAPI StringVPrintfWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszFormat, va_list argList); -STRSAFEAPI StringVPrintfExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList); -STRSAFEAPI StringVPrintfExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const wchar_t* pszFormat, va_list argList); -STRSAFEAPI StringLengthWorkerA(const char* psz, size_t cchMax, size_t* pcch); -STRSAFEAPI StringLengthWorkerW(const wchar_t* psz, size_t cchMax, size_t* pcch); -#endif // STRSAFE_INLINE - -#ifndef STRSAFE_LIB_IMPL -// these functions are always inline -STRSAFE_INLINE_API StringGetsExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFE_INLINE_API StringGetsExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -#endif - -#ifdef _NTSTRSAFE_H_INCLUDED_ -#pragma warning(push) -#pragma warning(disable : 4995) -#endif // _NTSTRSAFE_H_INCLUDED_ - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchCopy( - OUT LPTSTR pszDest, - IN size_t cchDest, - IN LPCTSTR pszSrc - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strcpy'. - The size of the destination buffer (in characters) is a parameter and - this function will not write past the end of this buffer and it will - ALWAYS null terminate the destination buffer (unless it is zero length). - - This routine is not a replacement for strncpy. That function will pad the - destination string with extra null termination characters if the count is - greater than the length of the source string, and it will fail to null - terminate the destination string if the source string length is greater - than or equal to the count. You can not blindly use this instead of strncpy: - it is common for code to use it to "patch" strings and you would introduce - errors if the code started null terminating in the middle of the string. - - This function returns a hresult, and not a pointer. It returns - S_OK if the string was copied without truncation and null terminated, - otherwise it will return a failure code. In failure cases as much of - pszSrc will be copied to pszDest as possible, and pszDest will be null - terminated. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters. - length must be = (_tcslen(src) + 1) to hold all of the - source including the null terminator - - pszSrc - source string which must be null terminated - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL. See StringCchCopyEx if you require - the handling of NULL values. - -Return Value: - - S_OK - if there was source data and it was all copied and the - resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the copy - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function. - ---*/ - -STRSAFEAPI StringCchCopyA(char* pszDest, size_t cchDest, const char* pszSrc); -STRSAFEAPI StringCchCopyW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc); -#ifdef UNICODE -#define StringCchCopy StringCchCopyW -#else -#define StringCchCopy StringCchCopyA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchCopyA(char* pszDest, size_t cchDest, const char* pszSrc) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCopyWorkerA(pszDest, cchDest, pszSrc); - } - - return hr; -} - -STRSAFEAPI StringCchCopyW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCopyWorkerW(pszDest, cchDest, pszSrc); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbCopy( - OUT LPTSTR pszDest, - IN size_t cbDest, - IN LPCTSTR pszSrc - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strcpy'. - The size of the destination buffer (in bytes) is a parameter and this - function will not write past the end of this buffer and it will ALWAYS - null terminate the destination buffer (unless it is zero length). - - This routine is not a replacement for strncpy. That function will pad the - destination string with extra null termination characters if the count is - greater than the length of the source string, and it will fail to null - terminate the destination string if the source string length is greater - than or equal to the count. You can not blindly use this instead of strncpy: - it is common for code to use it to "patch" strings and you would introduce - errors if the code started null terminating in the middle of the string. - - This function returns a hresult, and not a pointer. It returns - S_OK if the string was copied without truncation and null terminated, - otherwise it will return a failure code. In failure cases as much of pszSrc - will be copied to pszDest as possible, and pszDest will be null terminated. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes. - length must be = ((_tcslen(src) + 1) * sizeof(TCHAR)) to - hold all of the source including the null terminator - - pszSrc - source string which must be null terminated - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL. See StringCbCopyEx if you require - the handling of NULL values. - -Return Value: - - S_OK - if there was source data and it was all copied and the - resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the copy - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function. - ---*/ - -STRSAFEAPI StringCbCopyA(char* pszDest, size_t cbDest, const char* pszSrc); -STRSAFEAPI StringCbCopyW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc); -#ifdef UNICODE -#define StringCbCopy StringCbCopyW -#else -#define StringCbCopy StringCbCopyA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbCopyA(char* pszDest, size_t cbDest, const char* pszSrc) -{ - HRESULT hr; - size_t cchDest; - - // convert to count of characters - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCopyWorkerA(pszDest, cchDest, pszSrc); - } - - return hr; -} - -STRSAFEAPI StringCbCopyW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc) -{ - HRESULT hr; - size_t cchDest; - - // convert to count of characters - cchDest = cbDest / sizeof(wchar_t); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCopyWorkerW(pszDest, cchDest, pszSrc); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchCopyEx( - OUT LPTSTR pszDest OPTIONAL, - IN size_t cchDest, - IN LPCTSTR pszSrc OPTIONAL, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcchRemaining OPTIONAL, - IN DWORD dwFlags - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strcpy' with - some additional parameters. In addition to functionality provided by - StringCchCopy, this routine also returns a pointer to the end of the - destination string and the number of characters left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters. - length must be = (_tcslen(pszSrc) + 1) to hold all of - the source including the null terminator - - pszSrc - source string which must be null terminated - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function copied any data, the result will point to the - null termination character - - pcchRemaining - if pcchRemaining is non-null, the function will return the - number of characters left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")). - this flag is useful for emulating functions like lstrcpy - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any truncated - string returned when the failure is - STRSAFE_E_INSUFFICIENT_BUFFER - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any truncated string - returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER. - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag - is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc - may be NULL. An error may still be returned even though NULLS are ignored - due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all copied and the - resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the copy - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchCopyExA(char* pszDest, size_t cchDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFEAPI StringCchCopyExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -#ifdef UNICODE -#define StringCchCopyEx StringCchCopyExW -#else -#define StringCchCopyEx StringCchCopyExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchCopyExA(char* pszDest, size_t cchDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1 - cbDest = cchDest * sizeof(char); - - hr = StringCopyExWorkerA(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, pcchRemaining, dwFlags); - } - - return hr; -} - -STRSAFEAPI StringCchCopyExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - cbDest = cchDest * sizeof(wchar_t); - - hr = StringCopyExWorkerW(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, pcchRemaining, dwFlags); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbCopyEx( - OUT LPTSTR pszDest OPTIONAL, - IN size_t cbDest, - IN LPCTSTR pszSrc OPTIONAL, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcbRemaining OPTIONAL, - IN DWORD dwFlags - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strcpy' with - some additional parameters. In addition to functionality provided by - StringCbCopy, this routine also returns a pointer to the end of the - destination string and the number of bytes left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes. - length must be ((_tcslen(pszSrc) + 1) * sizeof(TCHAR)) to - hold all of the source including the null terminator - - pszSrc - source string which must be null terminated - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function copied any data, the result will point to the - null termination character - - pcbRemaining - pcbRemaining is non-null,the function will return the - number of bytes left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")). - this flag is useful for emulating functions like lstrcpy - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any truncated - string returned when the failure is - STRSAFE_E_INSUFFICIENT_BUFFER - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any truncated string - returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER. - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag - is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc - may be NULL. An error may still be returned even though NULLS are ignored - due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all copied and the - resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the copy - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbCopyExA(char* pszDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags); -STRSAFEAPI StringCbCopyExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags); -#ifdef UNICODE -#define StringCbCopyEx StringCbCopyExW -#else -#define StringCbCopyEx StringCbCopyExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbCopyExA(char* pszDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCopyExWorkerA(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, &cchRemaining, dwFlags); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1 - *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char)); - } - } - - return hr; -} - -STRSAFEAPI StringCbCopyExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(wchar_t); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCopyExWorkerW(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, &cchRemaining, dwFlags); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)); - } - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchCopyN( - OUT LPTSTR pszDest, - IN size_t cchDest, - IN LPCTSTR pszSrc, - IN size_t cchSrc - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strncpy'. - The size of the destination buffer (in characters) is a parameter and - this function will not write past the end of this buffer and it will - ALWAYS null terminate the destination buffer (unless it is zero length). - - This routine is meant as a replacement for strncpy, but it does behave - differently. This function will not pad the destination buffer with extra - null termination characters if cchSrc is greater than the length of pszSrc. - - This function returns a hresult, and not a pointer. It returns - S_OK if the entire string or the first cchSrc characters were copied - without truncation and the resultant destination string was null terminated, - otherwise it will return a failure code. In failure cases as much of pszSrc - will be copied to pszDest as possible, and pszDest will be null terminated. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters. - length must be = (_tcslen(src) + 1) to hold all of the - source including the null terminator - - pszSrc - source string - - cchSrc - maximum number of characters to copy from source string, - not including the null terminator. - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL. See StringCchCopyNEx if you require - the handling of NULL values. - -Return Value: - - S_OK - if there was source data and it was all copied and the - resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the copy - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function. - ---*/ - -STRSAFEAPI StringCchCopyNA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchSrc); -STRSAFEAPI StringCchCopyNW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchSrc); -#ifdef UNICODE -#define StringCchCopyN StringCchCopyNW -#else -#define StringCchCopyN StringCchCopyNA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchCopyNA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchSrc) -{ - HRESULT hr; - - if ((cchDest > STRSAFE_MAX_CCH) || - (cchSrc > STRSAFE_MAX_CCH)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCopyNWorkerA(pszDest, cchDest, pszSrc, cchSrc); - } - - return hr; -} - -STRSAFEAPI StringCchCopyNW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchSrc) -{ - HRESULT hr; - - if ((cchDest > STRSAFE_MAX_CCH) || - (cchSrc > STRSAFE_MAX_CCH)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCopyNWorkerW(pszDest, cchDest, pszSrc, cchSrc); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbCopyN( - OUT LPTSTR pszDest, - IN size_t cbDest, - IN LPCTSTR pszSrc, - IN size_t cbSrc - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strncpy'. - The size of the destination buffer (in bytes) is a parameter and this - function will not write past the end of this buffer and it will ALWAYS - null terminate the destination buffer (unless it is zero length). - - This routine is meant as a replacement for strncpy, but it does behave - differently. This function will not pad the destination buffer with extra - null termination characters if cbSrc is greater than the size of pszSrc. - - This function returns a hresult, and not a pointer. It returns - S_OK if the entire string or the first cbSrc characters were - copied without truncation and the resultant destination string was null - terminated, otherwise it will return a failure code. In failure cases as - much of pszSrc will be copied to pszDest as possible, and pszDest will be - null terminated. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes. - length must be = ((_tcslen(src) + 1) * sizeof(TCHAR)) to - hold all of the source including the null terminator - - pszSrc - source string - - cbSrc - maximum number of bytes to copy from source string, - not including the null terminator. - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL. See StringCbCopyEx if you require - the handling of NULL values. - -Return Value: - - S_OK - if there was source data and it was all copied and the - resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the copy - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function. - ---*/ - -STRSAFEAPI StringCbCopyNA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbSrc); -STRSAFEAPI StringCbCopyNW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbSrc); -#ifdef UNICODE -#define StringCbCopyN StringCbCopyNW -#else -#define StringCbCopyN StringCbCopyNA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbCopyNA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbSrc) -{ - HRESULT hr; - size_t cchDest; - size_t cchSrc; - - // convert to count of characters - cchDest = cbDest / sizeof(char); - cchSrc = cbSrc / sizeof(char); - - if ((cchDest > STRSAFE_MAX_CCH) || - (cchSrc > STRSAFE_MAX_CCH)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCopyNWorkerA(pszDest, cchDest, pszSrc, cchSrc); - } - - return hr; -} - -STRSAFEAPI StringCbCopyNW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbSrc) -{ - HRESULT hr; - size_t cchDest; - size_t cchSrc; - - // convert to count of characters - cchDest = cbDest / sizeof(wchar_t); - cchSrc = cbSrc / sizeof(wchar_t); - - if ((cchDest > STRSAFE_MAX_CCH) || - (cchSrc > STRSAFE_MAX_CCH)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCopyNWorkerW(pszDest, cchDest, pszSrc, cchSrc); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchCopyNEx( - OUT LPTSTR pszDest OPTIONAL, - IN size_t cchDest, - IN LPCTSTR pszSrc OPTIONAL, - IN size_t cchSrc, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcchRemaining OPTIONAL, - IN DWORD dwFlags - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strncpy' with - some additional parameters. In addition to functionality provided by - StringCchCopyN, this routine also returns a pointer to the end of the - destination string and the number of characters left in the destination - string including the null terminator. The flags parameter allows - additional controls. - - This routine is meant as a replacement for strncpy, but it does behave - differently. This function will not pad the destination buffer with extra - null termination characters if cchSrc is greater than the length of pszSrc. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters. - length must be = (_tcslen(pszSrc) + 1) to hold all of - the source including the null terminator - - pszSrc - source string - - cchSrc - maximum number of characters to copy from the source - string - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function copied any data, the result will point to the - null termination character - - pcchRemaining - if pcchRemaining is non-null, the function will return the - number of characters left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")). - this flag is useful for emulating functions like lstrcpy - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any truncated - string returned when the failure is - STRSAFE_E_INSUFFICIENT_BUFFER - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any truncated string - returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER. - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag - is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc - may be NULL. An error may still be returned even though NULLS are ignored - due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all copied and the - resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the copy - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchCopyNExA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFEAPI StringCchCopyNExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -#ifdef UNICODE -#define StringCchCopyNEx StringCchCopyNExW -#else -#define StringCchCopyNEx StringCchCopyNExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchCopyNExA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr; - - if ((cchDest > STRSAFE_MAX_CCH) || - (cchSrc > STRSAFE_MAX_CCH)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1 - cbDest = cchDest * sizeof(char); - - hr = StringCopyNExWorkerA(pszDest, cchDest, cbDest, pszSrc, cchSrc, ppszDestEnd, pcchRemaining, dwFlags); - } - - return hr; -} - -STRSAFEAPI StringCchCopyNExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr; - - if ((cchDest > STRSAFE_MAX_CCH) || - (cchSrc > STRSAFE_MAX_CCH)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - cbDest = cchDest * sizeof(wchar_t); - - hr = StringCopyNExWorkerW(pszDest, cchDest, cbDest, pszSrc, cchSrc, ppszDestEnd, pcchRemaining, dwFlags); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbCopyNEx( - OUT LPTSTR pszDest OPTIONAL, - IN size_t cbDest, - IN LPCTSTR pszSrc OPTIONAL, - IN size_t cbSrc, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcbRemaining OPTIONAL, - IN DWORD dwFlags - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strncpy' with - some additional parameters. In addition to functionality provided by - StringCbCopyN, this routine also returns a pointer to the end of the - destination string and the number of bytes left in the destination string - including the null terminator. The flags parameter allows additional controls. - - This routine is meant as a replacement for strncpy, but it does behave - differently. This function will not pad the destination buffer with extra - null termination characters if cbSrc is greater than the size of pszSrc. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes. - length must be ((_tcslen(pszSrc) + 1) * sizeof(TCHAR)) to - hold all of the source including the null terminator - - pszSrc - source string - - cbSrc - maximum number of bytes to copy from source string - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function copied any data, the result will point to the - null termination character - - pcbRemaining - pcbRemaining is non-null,the function will return the - number of bytes left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")). - this flag is useful for emulating functions like lstrcpy - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any truncated - string returned when the failure is - STRSAFE_E_INSUFFICIENT_BUFFER - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any truncated string - returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER. - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag - is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc - may be NULL. An error may still be returned even though NULLS are ignored - due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all copied and the - resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the copy - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbCopyNExA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbSrc, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags); -STRSAFEAPI StringCbCopyNExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbSrc, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags); -#ifdef UNICODE -#define StringCbCopyNEx StringCbCopyNExW -#else -#define StringCbCopyNEx StringCbCopyNExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbCopyNExA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbSrc, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags) -{ - HRESULT hr; - size_t cchDest; - size_t cchSrc; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(char); - cchSrc = cbSrc / sizeof(char); - - if ((cchDest > STRSAFE_MAX_CCH) || - (cchSrc > STRSAFE_MAX_CCH)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCopyNExWorkerA(pszDest, cchDest, cbDest, pszSrc, cchSrc, ppszDestEnd, &cchRemaining, dwFlags); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1 - *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char)); - } - } - - return hr; -} - -STRSAFEAPI StringCbCopyNExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbSrc, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags) -{ - HRESULT hr; - size_t cchDest; - size_t cchSrc; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(wchar_t); - cchSrc = cbSrc / sizeof(wchar_t); - - if ((cchDest > STRSAFE_MAX_CCH) || - (cchSrc > STRSAFE_MAX_CCH)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCopyNExWorkerW(pszDest, cchDest, cbDest, pszSrc, cchSrc, ppszDestEnd, &cchRemaining, dwFlags); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)); - } - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchCat( - IN OUT LPTSTR pszDest, - IN size_t cchDest, - IN LPCTSTR pszSrc - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strcat'. - The size of the destination buffer (in characters) is a parameter and this - function will not write past the end of this buffer and it will ALWAYS - null terminate the destination buffer (unless it is zero length). - - This function returns a hresult, and not a pointer. It returns - S_OK if the string was concatenated without truncation and null terminated, - otherwise it will return a failure code. In failure cases as much of pszSrc - will be appended to pszDest as possible, and pszDest will be null - terminated. - -Arguments: - - pszDest - destination string which must be null terminated - - cchDest - size of destination buffer in characters. - length must be = (_tcslen(pszDest) + _tcslen(pszSrc) + 1) - to hold all of the combine string plus the null - terminator - - pszSrc - source string which must be null terminated - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL. See StringCchCatEx if you require - the handling of NULL values. - -Return Value: - - S_OK - if there was source data and it was all concatenated and - the resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the operation - failed due to insufficient space. When this error occurs, - the destination buffer is modified to contain a truncated - version of the ideal result and is null terminated. This - is useful for situations where truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchCatA(char* pszDest, size_t cchDest, const char* pszSrc); -STRSAFEAPI StringCchCatW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc); -#ifdef UNICODE -#define StringCchCat StringCchCatW -#else -#define StringCchCat StringCchCatA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchCatA(char* pszDest, size_t cchDest, const char* pszSrc) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCatWorkerA(pszDest, cchDest, pszSrc); - } - - return hr; -} - -STRSAFEAPI StringCchCatW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCatWorkerW(pszDest, cchDest, pszSrc); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbCat( - IN OUT LPTSTR pszDest, - IN size_t cbDest, - IN LPCTSTR pszSrc - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strcat'. - The size of the destination buffer (in bytes) is a parameter and this - function will not write past the end of this buffer and it will ALWAYS - null terminate the destination buffer (unless it is zero length). - - This function returns a hresult, and not a pointer. It returns - S_OK if the string was concatenated without truncation and null terminated, - otherwise it will return a failure code. In failure cases as much of pszSrc - will be appended to pszDest as possible, and pszDest will be null - terminated. - -Arguments: - - pszDest - destination string which must be null terminated - - cbDest - size of destination buffer in bytes. - length must be = ((_tcslen(pszDest) + _tcslen(pszSrc) + 1) * sizeof(TCHAR) - to hold all of the combine string plus the null - terminator - - pszSrc - source string which must be null terminated - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL. See StringCbCatEx if you require - the handling of NULL values. - -Return Value: - - S_OK - if there was source data and it was all concatenated and - the resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the operation - failed due to insufficient space. When this error occurs, - the destination buffer is modified to contain a truncated - version of the ideal result and is null terminated. This - is useful for situations where truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbCatA(char* pszDest, size_t cbDest, const char* pszSrc); -STRSAFEAPI StringCbCatW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc); -#ifdef UNICODE -#define StringCbCat StringCbCatW -#else -#define StringCbCat StringCbCatA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbCatA(char* pszDest, size_t cbDest, const char* pszSrc) -{ - HRESULT hr; - size_t cchDest; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCatWorkerA(pszDest, cchDest, pszSrc); - } - - return hr; -} - -STRSAFEAPI StringCbCatW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc) -{ - HRESULT hr; - size_t cchDest; - - cchDest = cbDest / sizeof(wchar_t); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCatWorkerW(pszDest, cchDest, pszSrc); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchCatEx( - IN OUT LPTSTR pszDest OPTIONAL, - IN size_t cchDest, - IN LPCTSTR pszSrc OPTIONAL, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcchRemaining OPTIONAL, - IN DWORD dwFlags - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strcat' with - some additional parameters. In addition to functionality provided by - StringCchCat, this routine also returns a pointer to the end of the - destination string and the number of characters left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string which must be null terminated - - cchDest - size of destination buffer in characters - length must be (_tcslen(pszDest) + _tcslen(pszSrc) + 1) - to hold all of the combine string plus the null - terminator. - - pszSrc - source string which must be null terminated - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function appended any data, the result will point to the - null termination character - - pcchRemaining - if pcchRemaining is non-null, the function will return the - number of characters left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")). - this flag is useful for emulating functions like lstrcat - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any pre-existing - or truncated string - - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any pre-existing or - truncated string - - STRSAFE_NO_TRUNCATION - if the function returns STRSAFE_E_INSUFFICIENT_BUFFER, pszDest - will not contain a truncated string, it will remain unchanged. - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag - is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc - may be NULL. An error may still be returned even though NULLS are ignored - due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all concatenated and - the resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the operation - failed due to insufficient space. When this error - occurs, the destination buffer is modified to contain - a truncated version of the ideal result and is null - terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchCatExA(char* pszDest, size_t cchDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFEAPI StringCchCatExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -#ifdef UNICODE -#define StringCchCatEx StringCchCatExW -#else -#define StringCchCatEx StringCchCatExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchCatExA(char* pszDest, size_t cchDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1 - cbDest = cchDest * sizeof(char); - - hr = StringCatExWorkerA(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, pcchRemaining, dwFlags); - } - - return hr; -} - -STRSAFEAPI StringCchCatExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - cbDest = cchDest * sizeof(wchar_t); - - hr = StringCatExWorkerW(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, pcchRemaining, dwFlags); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbCatEx( - IN OUT LPTSTR pszDest OPTIONAL, - IN size_t cbDest, - IN LPCTSTR pszSrc OPTIONAL, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcbRemaining OPTIONAL, - IN DWORD dwFlags - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strcat' with - some additional parameters. In addition to functionality provided by - StringCbCat, this routine also returns a pointer to the end of the - destination string and the number of bytes left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string which must be null terminated - - cbDest - size of destination buffer in bytes. - length must be ((_tcslen(pszDest) + _tcslen(pszSrc) + 1) * sizeof(TCHAR) - to hold all of the combine string plus the null - terminator. - - pszSrc - source string which must be null terminated - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function appended any data, the result will point to the - null termination character - - pcbRemaining - if pcbRemaining is non-null, the function will return - the number of bytes left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")). - this flag is useful for emulating functions like lstrcat - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any pre-existing - or truncated string - - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any pre-existing or - truncated string - - STRSAFE_NO_TRUNCATION - if the function returns STRSAFE_E_INSUFFICIENT_BUFFER, pszDest - will not contain a truncated string, it will remain unchanged. - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag - is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc - may be NULL. An error may still be returned even though NULLS are ignored - due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all concatenated - and the resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the operation - failed due to insufficient space. When this error - occurs, the destination buffer is modified to contain - a truncated version of the ideal result and is null - terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbCatExA(char* pszDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags); -STRSAFEAPI StringCbCatExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags); -#ifdef UNICODE -#define StringCbCatEx StringCbCatExW -#else -#define StringCbCatEx StringCbCatExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbCatExA(char* pszDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCatExWorkerA(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, &cchRemaining, dwFlags); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1 - *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char)); - } - } - - return hr; -} - -STRSAFEAPI StringCbCatExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(wchar_t); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCatExWorkerW(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, &cchRemaining, dwFlags); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)); - } - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchCatN( - IN OUT LPTSTR pszDest, - IN size_t cchDest, - IN LPCTSTR pszSrc, - IN size_t cchMaxAppend - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strncat'. - The size of the destination buffer (in characters) is a parameter as well as - the maximum number of characters to append, excluding the null terminator. - This function will not write past the end of the destination buffer and it will - ALWAYS null terminate pszDest (unless it is zero length). - - This function returns a hresult, and not a pointer. It returns - S_OK if all of pszSrc or the first cchMaxAppend characters were appended - to the destination string and it was null terminated, otherwise it will - return a failure code. In failure cases as much of pszSrc will be appended - to pszDest as possible, and pszDest will be null terminated. - -Arguments: - - pszDest - destination string which must be null terminated - - cchDest - size of destination buffer in characters. - length must be (_tcslen(pszDest) + min(cchMaxAppend, _tcslen(pszSrc)) + 1) - to hold all of the combine string plus the null - terminator. - - pszSrc - source string - - cchMaxAppend - maximum number of characters to append - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL. See StringCchCatNEx if you require - the handling of NULL values. - -Return Value: - - S_OK - if all of pszSrc or the first cchMaxAppend characters - were concatenated to pszDest and the resultant dest - string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the operation - failed due to insufficient space. When this error - occurs, the destination buffer is modified to contain - a truncated version of the ideal result and is null - terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchCatNA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchMaxAppend); -STRSAFEAPI StringCchCatNW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchMaxAppend); -#ifdef UNICODE -#define StringCchCatN StringCchCatNW -#else -#define StringCchCatN StringCchCatNA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchCatNA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchMaxAppend) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCatNWorkerA(pszDest, cchDest, pszSrc, cchMaxAppend); - } - - return hr; -} - -STRSAFEAPI StringCchCatNW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchMaxAppend) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringCatNWorkerW(pszDest, cchDest, pszSrc, cchMaxAppend); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbCatN( - IN OUT LPTSTR pszDest, - IN size_t cbDest, - IN LPCTSTR pszSrc, - IN size_t cbMaxAppend - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strncat'. - The size of the destination buffer (in bytes) is a parameter as well as - the maximum number of bytes to append, excluding the null terminator. - This function will not write past the end of the destination buffer and it will - ALWAYS null terminate pszDest (unless it is zero length). - - This function returns a hresult, and not a pointer. It returns - S_OK if all of pszSrc or the first cbMaxAppend bytes were appended - to the destination string and it was null terminated, otherwise it will - return a failure code. In failure cases as much of pszSrc will be appended - to pszDest as possible, and pszDest will be null terminated. - -Arguments: - - pszDest - destination string which must be null terminated - - cbDest - size of destination buffer in bytes. - length must be ((_tcslen(pszDest) + min(cbMaxAppend / sizeof(TCHAR), _tcslen(pszSrc)) + 1) * sizeof(TCHAR) - to hold all of the combine string plus the null - terminator. - - pszSrc - source string - - cbMaxAppend - maximum number of bytes to append - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL. See StringCbCatNEx if you require - the handling of NULL values. - -Return Value: - - S_OK - if all of pszSrc or the first cbMaxAppend bytes were - concatenated to pszDest and the resultant dest string - was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the operation - failed due to insufficient space. When this error - occurs, the destination buffer is modified to contain - a truncated version of the ideal result and is null - terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbCatNA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbMaxAppend); -STRSAFEAPI StringCbCatNW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbMaxAppend); -#ifdef UNICODE -#define StringCbCatN StringCbCatNW -#else -#define StringCbCatN StringCbCatNA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbCatNA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbMaxAppend) -{ - HRESULT hr; - size_t cchDest; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cchMaxAppend; - - cchMaxAppend = cbMaxAppend / sizeof(char); - - hr = StringCatNWorkerA(pszDest, cchDest, pszSrc, cchMaxAppend); - } - - return hr; -} - -STRSAFEAPI StringCbCatNW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbMaxAppend) -{ - HRESULT hr; - size_t cchDest; - - cchDest = cbDest / sizeof(wchar_t); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cchMaxAppend; - - cchMaxAppend = cbMaxAppend / sizeof(wchar_t); - - hr = StringCatNWorkerW(pszDest, cchDest, pszSrc, cchMaxAppend); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchCatNEx( - IN OUT LPTSTR pszDest OPTIONAL, - IN size_t cchDest, - IN LPCTSTR pszSrc OPTIONAL, - IN size_t cchMaxAppend, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcchRemaining OPTIONAL, - IN DWORD dwFlags - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strncat', with - some additional parameters. In addition to functionality provided by - StringCchCatN, this routine also returns a pointer to the end of the - destination string and the number of characters left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string which must be null terminated - - cchDest - size of destination buffer in characters. - length must be (_tcslen(pszDest) + min(cchMaxAppend, _tcslen(pszSrc)) + 1) - to hold all of the combine string plus the null - terminator. - - pszSrc - source string - - cchMaxAppend - maximum number of characters to append - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function appended any data, the result will point to the - null termination character - - pcchRemaining - if pcchRemaining is non-null, the function will return the - number of characters left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")) - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any pre-existing - or truncated string - - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any pre-existing or - truncated string - - STRSAFE_NO_TRUNCATION - if the function returns STRSAFE_E_INSUFFICIENT_BUFFER, pszDest - will not contain a truncated string, it will remain unchanged. - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag - is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc - may be NULL. An error may still be returned even though NULLS are ignored - due to insufficient space. - -Return Value: - - S_OK - if all of pszSrc or the first cchMaxAppend characters - were concatenated to pszDest and the resultant dest - string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the operation - failed due to insufficient space. When this error - occurs, the destination buffer is modified to contain - a truncated version of the ideal result and is null - terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchCatNExA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchMaxAppend, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFEAPI StringCchCatNExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchMaxAppend, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -#ifdef UNICODE -#define StringCchCatNEx StringCchCatNExW -#else -#define StringCchCatNEx StringCchCatNExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchCatNExA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchMaxAppend, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1 - cbDest = cchDest * sizeof(char); - - hr = StringCatNExWorkerA(pszDest, cchDest, cbDest, pszSrc, cchMaxAppend, ppszDestEnd, pcchRemaining, dwFlags); - } - - return hr; -} - -STRSAFEAPI StringCchCatNExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchMaxAppend, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - cbDest = cchDest * sizeof(wchar_t); - - hr = StringCatNExWorkerW(pszDest, cchDest, cbDest, pszSrc, cchMaxAppend, ppszDestEnd, pcchRemaining, dwFlags); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbCatNEx( - IN OUT LPTSTR pszDest OPTIONAL, - IN size_t cbDest, - IN LPCTSTR pszSrc OPTIONAL, - IN size_t cbMaxAppend, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcchRemaining OPTIONAL, - IN DWORD dwFlags - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strncat', with - some additional parameters. In addition to functionality provided by - StringCbCatN, this routine also returns a pointer to the end of the - destination string and the number of bytes left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string which must be null terminated - - cbDest - size of destination buffer in bytes. - length must be ((_tcslen(pszDest) + min(cbMaxAppend / sizeof(TCHAR), _tcslen(pszSrc)) + 1) * sizeof(TCHAR) - to hold all of the combine string plus the null - terminator. - - pszSrc - source string - - cbMaxAppend - maximum number of bytes to append - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function appended any data, the result will point to the - null termination character - - pcbRemaining - if pcbRemaining is non-null, the function will return the - number of bytes left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")) - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any pre-existing - or truncated string - - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any pre-existing or - truncated string - - STRSAFE_NO_TRUNCATION - if the function returns STRSAFE_E_INSUFFICIENT_BUFFER, pszDest - will not contain a truncated string, it will remain unchanged. - -Notes: - Behavior is undefined if source and destination strings overlap. - - pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag - is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc - may be NULL. An error may still be returned even though NULLS are ignored - due to insufficient space. - -Return Value: - - S_OK - if all of pszSrc or the first cbMaxAppend bytes were - concatenated to pszDest and the resultant dest string - was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the operation - failed due to insufficient space. When this error - occurs, the destination buffer is modified to contain - a truncated version of the ideal result and is null - terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbCatNExA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbMaxAppend, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags); -STRSAFEAPI StringCbCatNExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbMaxAppend, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags); -#ifdef UNICODE -#define StringCbCatNEx StringCbCatNExW -#else -#define StringCbCatNEx StringCbCatNExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbCatNExA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbMaxAppend, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cchMaxAppend; - - cchMaxAppend = cbMaxAppend / sizeof(char); - - hr = StringCatNExWorkerA(pszDest, cchDest, cbDest, pszSrc, cchMaxAppend, ppszDestEnd, &cchRemaining, dwFlags); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1 - *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char)); - } - } - - return hr; -} - -STRSAFEAPI StringCbCatNExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbMaxAppend, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(wchar_t); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cchMaxAppend; - - cchMaxAppend = cbMaxAppend / sizeof(wchar_t); - - hr = StringCatNExWorkerW(pszDest, cchDest, cbDest, pszSrc, cchMaxAppend, ppszDestEnd, &cchRemaining, dwFlags); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)); - } - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchVPrintf( - OUT LPTSTR pszDest, - IN size_t cchDest, - IN LPCTSTR pszFormat, - IN va_list argList - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'vsprintf'. - The size of the destination buffer (in characters) is a parameter and - this function will not write past the end of this buffer and it will - ALWAYS null terminate the destination buffer (unless it is zero length). - - This function returns a hresult, and not a pointer. It returns - S_OK if the string was printed without truncation and null terminated, - otherwise it will return a failure code. In failure cases it will return - a truncated version of the ideal result. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters - length must be sufficient to hold the resulting formatted - string, including the null terminator. - - pszFormat - format string which must be null terminated - - argList - va_list from the variable arguments according to the - stdarg.h convention - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL. See StringCchVPrintfEx if you - require the handling of NULL values. - -Return Value: - - S_OK - if there was sufficient space in the dest buffer for - the resultant string and it was null terminated. - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchVPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList); -STRSAFEAPI StringCchVPrintfW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszFormat, va_list argList); -#ifdef UNICODE -#define StringCchVPrintf StringCchVPrintfW -#else -#define StringCchVPrintf StringCchVPrintfA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchVPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList); - } - - return hr; -} - -STRSAFEAPI StringCchVPrintfW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszFormat, va_list argList) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbVPrintf( - OUT LPTSTR pszDest, - IN size_t cbDest, - IN LPCTSTR pszFormat, - IN va_list argList - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'vsprintf'. - The size of the destination buffer (in bytes) is a parameter and - this function will not write past the end of this buffer and it will - ALWAYS null terminate the destination buffer (unless it is zero length). - - This function returns a hresult, and not a pointer. It returns - S_OK if the string was printed without truncation and null terminated, - otherwise it will return a failure code. In failure cases it will return - a truncated version of the ideal result. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes - length must be sufficient to hold the resulting formatted - string, including the null terminator. - - pszFormat - format string which must be null terminated - - argList - va_list from the variable arguments according to the - stdarg.h convention - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL. See StringCbVPrintfEx if you - require the handling of NULL values. - - -Return Value: - - S_OK - if there was sufficient space in the dest buffer for - the resultant string and it was null terminated. - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbVPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, va_list argList); -STRSAFEAPI StringCbVPrintfW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszFormat, va_list argList); -#ifdef UNICODE -#define StringCbVPrintf StringCbVPrintfW -#else -#define StringCbVPrintf StringCbVPrintfA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbVPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, va_list argList) -{ - HRESULT hr; - size_t cchDest; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList); - } - - return hr; -} - -STRSAFEAPI StringCbVPrintfW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszFormat, va_list argList) -{ - HRESULT hr; - size_t cchDest; - - cchDest = cbDest / sizeof(wchar_t); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchPrintf( - OUT LPTSTR pszDest, - IN size_t cchDest, - IN LPCTSTR pszFormat, - ... - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'sprintf'. - The size of the destination buffer (in characters) is a parameter and - this function will not write past the end of this buffer and it will - ALWAYS null terminate the destination buffer (unless it is zero length). - - This function returns a hresult, and not a pointer. It returns - S_OK if the string was printed without truncation and null terminated, - otherwise it will return a failure code. In failure cases it will return - a truncated version of the ideal result. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters - length must be sufficient to hold the resulting formatted - string, including the null terminator. - - pszFormat - format string which must be null terminated - - ... - additional parameters to be formatted according to - the format string - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL. See StringCchPrintfEx if you - require the handling of NULL values. - -Return Value: - - S_OK - if there was sufficient space in the dest buffer for - the resultant string and it was null terminated. - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, ...); -STRSAFEAPI StringCchPrintfW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszFormat, ...); -#ifdef UNICODE -#define StringCchPrintf StringCchPrintfW -#else -#define StringCchPrintf StringCchPrintfA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, ...) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - va_list argList; - - va_start(argList, pszFormat); - - hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList); - - va_end(argList); - } - - return hr; -} - -STRSAFEAPI StringCchPrintfW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszFormat, ...) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - va_list argList; - - va_start(argList, pszFormat); - - hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList); - - va_end(argList); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbPrintf( - OUT LPTSTR pszDest, - IN size_t cbDest, - IN LPCTSTR pszFormat, - ... - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'sprintf'. - The size of the destination buffer (in bytes) is a parameter and - this function will not write past the end of this buffer and it will - ALWAYS null terminate the destination buffer (unless it is zero length). - - This function returns a hresult, and not a pointer. It returns - S_OK if the string was printed without truncation and null terminated, - otherwise it will return a failure code. In failure cases it will return - a truncated version of the ideal result. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes - length must be sufficient to hold the resulting formatted - string, including the null terminator. - - pszFormat - format string which must be null terminated - - ... - additional parameters to be formatted according to - the format string - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL. See StringCbPrintfEx if you - require the handling of NULL values. - - -Return Value: - - S_OK - if there was sufficient space in the dest buffer for - the resultant string and it was null terminated. - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, ...); -STRSAFEAPI StringCbPrintfW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszFormat, ...); -#ifdef UNICODE -#define StringCbPrintf StringCbPrintfW -#else -#define StringCbPrintf StringCbPrintfA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, ...) -{ - HRESULT hr; - size_t cchDest; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - va_list argList; - - va_start(argList, pszFormat); - - hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList); - - va_end(argList); - } - - return hr; -} - -STRSAFEAPI StringCbPrintfW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszFormat, ...) -{ - HRESULT hr; - size_t cchDest; - - cchDest = cbDest / sizeof(wchar_t); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - va_list argList; - - va_start(argList, pszFormat); - - hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList); - - va_end(argList); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchPrintfEx( - OUT LPTSTR pszDest OPTIONAL, - IN size_t cchDest, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcchRemaining OPTIONAL, - IN DWORD dwFlags, - IN LPCTSTR pszFormat OPTIONAL, - ... - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'sprintf' with - some additional parameters. In addition to functionality provided by - StringCchPrintf, this routine also returns a pointer to the end of the - destination string and the number of characters left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters. - length must be sufficient to contain the resulting - formatted string plus the null terminator. - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function printed any data, the result will point to the - null termination character - - pcchRemaining - if pcchRemaining is non-null, the function will return - the number of characters left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")) - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any truncated - string returned when the failure is - STRSAFE_E_INSUFFICIENT_BUFFER - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any truncated string - returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER. - - pszFormat - format string which must be null terminated - - ... - additional parameters to be formatted according to - the format string - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS - flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and - pszFormat may be NULL. An error may still be returned even though NULLS - are ignored due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all concatenated and - the resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, ...); -STRSAFEAPI StringCchPrintfExW(wchar_t* pszDest, size_t cchDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const wchar_t* pszFormat, ...); -#ifdef UNICODE -#define StringCchPrintfEx StringCchPrintfExW -#else -#define StringCchPrintfEx StringCchPrintfExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, ...) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - va_list argList; - - // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1 - cbDest = cchDest * sizeof(char); - va_start(argList, pszFormat); - - hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList); - - va_end(argList); - } - - return hr; -} - -STRSAFEAPI StringCchPrintfExW(wchar_t* pszDest, size_t cchDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const wchar_t* pszFormat, ...) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - va_list argList; - - // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - cbDest = cchDest * sizeof(wchar_t); - va_start(argList, pszFormat); - - hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList); - - va_end(argList); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbPrintfEx( - OUT LPTSTR pszDest OPTIONAL, - IN size_t cbDest, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcbRemaining OPTIONAL, - IN DWORD dwFlags, - IN LPCTSTR pszFormat OPTIONAL, - ... - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'sprintf' with - some additional parameters. In addition to functionality provided by - StringCbPrintf, this routine also returns a pointer to the end of the - destination string and the number of bytes left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes. - length must be sufficient to contain the resulting - formatted string plus the null terminator. - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function printed any data, the result will point to the - null termination character - - pcbRemaining - if pcbRemaining is non-null, the function will return - the number of bytes left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")) - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any truncated - string returned when the failure is - STRSAFE_E_INSUFFICIENT_BUFFER - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any truncated string - returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER. - - pszFormat - format string which must be null terminated - - ... - additional parameters to be formatted according to - the format string - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS - flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and - pszFormat may be NULL. An error may still be returned even though NULLS - are ignored due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all concatenated and - the resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, ...); -STRSAFEAPI StringCbPrintfExW(wchar_t* pszDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const wchar_t* pszFormat, ...); -#ifdef UNICODE -#define StringCbPrintfEx StringCbPrintfExW -#else -#define StringCbPrintfEx StringCbPrintfExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, ...) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - va_list argList; - - va_start(argList, pszFormat); - - hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList); - - va_end(argList); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1 - *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char)); - } - } - - return hr; -} - -STRSAFEAPI StringCbPrintfExW(wchar_t* pszDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const wchar_t* pszFormat, ...) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(wchar_t); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - va_list argList; - - va_start(argList, pszFormat); - - hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList); - - va_end(argList); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)); - } - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchVPrintfEx( - OUT LPTSTR pszDest OPTIONAL, - IN size_t cchDest, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcchRemaining OPTIONAL, - IN DWORD dwFlags, - IN LPCTSTR pszFormat OPTIONAL, - IN va_list argList - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'vsprintf' with - some additional parameters. In addition to functionality provided by - StringCchVPrintf, this routine also returns a pointer to the end of the - destination string and the number of characters left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters. - length must be sufficient to contain the resulting - formatted string plus the null terminator. - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function printed any data, the result will point to the - null termination character - - pcchRemaining - if pcchRemaining is non-null, the function will return - the number of characters left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")) - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any truncated - string returned when the failure is - STRSAFE_E_INSUFFICIENT_BUFFER - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any truncated string - returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER. - - pszFormat - format string which must be null terminated - - argList - va_list from the variable arguments according to the - stdarg.h convention - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS - flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and - pszFormat may be NULL. An error may still be returned even though NULLS - are ignored due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all concatenated and - the resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchVPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList); -STRSAFEAPI StringCchVPrintfExW(wchar_t* pszDest, size_t cchDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const wchar_t* pszFormat, va_list argList); -#ifdef UNICODE -#define StringCchVPrintfEx StringCchVPrintfExW -#else -#define StringCchVPrintfEx StringCchVPrintfExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchVPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1 - cbDest = cchDest * sizeof(char); - - hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList); - } - - return hr; -} - -STRSAFEAPI StringCchVPrintfExW(wchar_t* pszDest, size_t cchDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const wchar_t* pszFormat, va_list argList) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - cbDest = cchDest * sizeof(wchar_t); - - hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbVPrintfEx( - OUT LPTSTR pszDest OPTIONAL, - IN size_t cbDest, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcbRemaining OPTIONAL, - IN DWORD dwFlags, - IN LPCTSTR pszFormat OPTIONAL, - IN va_list argList - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'vsprintf' with - some additional parameters. In addition to functionality provided by - StringCbVPrintf, this routine also returns a pointer to the end of the - destination string and the number of characters left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes. - length must be sufficient to contain the resulting - formatted string plus the null terminator. - - ppszDestEnd - if ppszDestEnd is non-null, the function will return - a pointer to the end of the destination string. If the - function printed any data, the result will point to the - null termination character - - pcbRemaining - if pcbRemaining is non-null, the function will return - the number of bytes left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")) - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any truncated - string returned when the failure is - STRSAFE_E_INSUFFICIENT_BUFFER - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any truncated string - returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER. - - pszFormat - format string which must be null terminated - - argList - va_list from the variable arguments according to the - stdarg.h convention - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS - flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and - pszFormat may be NULL. An error may still be returned even though NULLS - are ignored due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all concatenated and - the resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print - operation failed due to insufficient space. When this - error occurs, the destination buffer is modified to - contain a truncated version of the ideal result and is - null terminated. This is useful for situations where - truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbVPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList); -STRSAFEAPI StringCbVPrintfExW(wchar_t* pszDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const wchar_t* pszFormat, va_list argList); -#ifdef UNICODE -#define StringCbVPrintfEx StringCbVPrintfExW -#else -#define StringCbVPrintfEx StringCbVPrintfExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbVPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1 - *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char)); - } - } - - return hr; -} - -STRSAFEAPI StringCbVPrintfExW(wchar_t* pszDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const wchar_t* pszFormat, va_list argList) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(wchar_t); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)); - } - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchGets( - OUT LPTSTR pszDest, - IN size_t cchDest - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'gets'. - The size of the destination buffer (in characters) is a parameter and - this function will not write past the end of this buffer and it will - ALWAYS null terminate the destination buffer (unless it is zero length). - - This routine is not a replacement for fgets. That function does not replace - newline characters with a null terminator. - - This function returns a hresult, and not a pointer. It returns - S_OK if any characters were read from stdin and copied to pszDest and - pszDest was null terminated, otherwise it will return a failure code. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters. - -Notes: - pszDest should not be NULL. See StringCchGetsEx if you require the handling - of NULL values. - - cchDest must be > 1 for this function to succeed. - -Return Value: - - S_OK - data was read from stdin and copied, and the resultant - dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_END_OF_FILE / - HRESULT_CODE(hr) == ERROR_HANDLE_EOF - - this return value indicates an error or end-of-file - condition, use feof or ferror to determine which one has - occured. - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that there was - insufficient space in the destination buffer to copy any - data - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function. - ---*/ - -#ifndef STRSAFE_LIB_IMPL -STRSAFE_INLINE_API StringCchGetsA(char* pszDest, size_t cchDest); -STRSAFE_INLINE_API StringCchGetsW(wchar_t* pszDest, size_t cchDest); -#ifdef UNICODE -#define StringCchGets StringCchGetsW -#else -#define StringCchGets StringCchGetsA -#endif // !UNICODE - -STRSAFE_INLINE_API StringCchGetsA(char* pszDest, size_t cchDest) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1 - cbDest = cchDest * sizeof(char); - - hr = StringGetsExWorkerA(pszDest, cchDest, cbDest, NULL, NULL, 0); - } - - return hr; -} - -STRSAFE_INLINE_API StringCchGetsW(wchar_t* pszDest, size_t cchDest) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - cbDest = cchDest * sizeof(wchar_t); - - hr = StringGetsExWorkerW(pszDest, cchDest, cbDest, NULL, NULL, 0); - } - - return hr; -} -#endif // !STRSAFE_NO_CCH_FUNCTIONS -#endif // !STRSAFE_LIB_IMPL - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbGets( - OUT LPTSTR pszDest, - IN size_t cbDest - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'gets'. - The size of the destination buffer (in bytes) is a parameter and - this function will not write past the end of this buffer and it will - ALWAYS null terminate the destination buffer (unless it is zero length). - - This routine is not a replacement for fgets. That function does not replace - newline characters with a null terminator. - - This function returns a hresult, and not a pointer. It returns - S_OK if any characters were read from stdin and copied to pszDest - and pszDest was null terminated, otherwise it will return a failure code. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes. - -Notes: - pszDest should not be NULL. See StringCbGetsEx if you require the handling - of NULL values. - - cbDest must be > sizeof(TCHAR) for this function to succeed. - -Return Value: - - S_OK - data was read from stdin and copied, and the resultant - dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_END_OF_FILE / - HRESULT_CODE(hr) == ERROR_HANDLE_EOF - - this return value indicates an error or end-of-file - condition, use feof or ferror to determine which one has - occured. - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that there was - insufficient space in the destination buffer to copy any - data - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function. - ---*/ - -#ifndef STRSAFE_LIB_IMPL -STRSAFE_INLINE_API StringCbGetsA(char* pszDest, size_t cbDest); -STRSAFE_INLINE_API StringCbGetsW(wchar_t* pszDest, size_t cbDest); -#ifdef UNICODE -#define StringCbGets StringCbGetsW -#else -#define StringCbGets StringCbGetsA -#endif // !UNICODE - -STRSAFE_INLINE_API StringCbGetsA(char* pszDest, size_t cbDest) -{ - HRESULT hr; - size_t cchDest; - - // convert to count of characters - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringGetsExWorkerA(pszDest, cchDest, cbDest, NULL, NULL, 0); - } - - return hr; -} - -STRSAFE_INLINE_API StringCbGetsW(wchar_t* pszDest, size_t cbDest) -{ - HRESULT hr; - size_t cchDest; - - // convert to count of characters - cchDest = cbDest / sizeof(wchar_t); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringGetsExWorkerW(pszDest, cchDest, cbDest, NULL, NULL, 0); - } - - return hr; -} -#endif // !STRSAFE_NO_CB_FUNCTIONS -#endif // !STRSAFE_LIB_IMPL - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchGetsEx( - OUT LPTSTR pszDest OPTIONAL, - IN size_t cchDest, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcchRemaining OPTIONAL, - IN DWORD dwFlags - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'gets' with - some additional parameters. In addition to functionality provided by - StringCchGets, this routine also returns a pointer to the end of the - destination string and the number of characters left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters. - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function copied any data, the result will point to the - null termination character - - pcchRemaining - if pcchRemaining is non-null, the function will return the - number of characters left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")). - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. - -Notes: - pszDest should not be NULL unless the STRSAFE_IGNORE_NULLS flag is specified. - If STRSAFE_IGNORE_NULLS is passed and pszDest is NULL, an error may still be - returned even though NULLS are ignored - - cchDest must be > 1 for this function to succeed. - -Return Value: - - S_OK - data was read from stdin and copied, and the resultant - dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_END_OF_FILE / - HRESULT_CODE(hr) == ERROR_HANDLE_EOF - - this return value indicates an error or end-of-file - condition, use feof or ferror to determine which one has - occured. - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that there was - insufficient space in the destination buffer to copy any - data - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function. - ---*/ - -#ifndef STRSAFE_LIB_IMPL -STRSAFE_INLINE_API StringCchGetsExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFE_INLINE_API StringCchGetsExW(wchar_t* pszDest, size_t cchDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -#ifdef UNICODE -#define StringCchGetsEx StringCchGetsExW -#else -#define StringCchGetsEx StringCchGetsExA -#endif // !UNICODE - -STRSAFE_INLINE_API StringCchGetsExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1 - cbDest = cchDest * sizeof(char); - - hr = StringGetsExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags); - } - - return hr; -} - -STRSAFE_INLINE_API StringCchGetsExW(wchar_t* pszDest, size_t cchDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - cbDest = cchDest * sizeof(wchar_t); - - hr = StringGetsExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags); - } - - return hr; -} -#endif // !STRSAFE_NO_CCH_FUNCTIONS -#endif // !STRSAFE_LIB_IMPL - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbGetsEx( - OUT LPTSTR pszDest OPTIONAL, - IN size_t cbDest, - OUT LPTSTR* ppszDestEnd OPTIONAL, - OUT size_t* pcbRemaining OPTIONAL, - IN DWORD dwFlags - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'gets' with - some additional parameters. In addition to functionality provided by - StringCbGets, this routine also returns a pointer to the end of the - destination string and the number of characters left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes. - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function copied any data, the result will point to the - null termination character - - pcbRemaining - if pbRemaining is non-null, the function will return the - number of bytes left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")). - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. - -Notes: - pszDest should not be NULL unless the STRSAFE_IGNORE_NULLS flag is specified. - If STRSAFE_IGNORE_NULLS is passed and pszDest is NULL, an error may still be - returned even though NULLS are ignored - - cbDest must be > sizeof(TCHAR) for this function to succeed - -Return Value: - - S_OK - data was read from stdin and copied, and the resultant - dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - STRSAFE_E_END_OF_FILE / - HRESULT_CODE(hr) == ERROR_HANDLE_EOF - - this return value indicates an error or end-of-file - condition, use feof or ferror to determine which one has - occured. - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that there was - insufficient space in the destination buffer to copy any - data - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function. - ---*/ - -#ifndef STRSAFE_LIB_IMPL -STRSAFE_INLINE_API StringCbGetsExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pbRemaining, unsigned long dwFlags); -STRSAFE_INLINE_API StringCbGetsExW(wchar_t* pszDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags); -#ifdef UNICODE -#define StringCbGetsEx StringCbGetsExW -#else -#define StringCbGetsEx StringCbGetsExA -#endif // !UNICODE - -STRSAFE_INLINE_API StringCbGetsExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringGetsExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags); - } - - if (SUCCEEDED(hr) || - (hr == STRSAFE_E_INSUFFICIENT_BUFFER) || - (hr == STRSAFE_E_END_OF_FILE)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1 - *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char)); - } - } - - return hr; -} - -STRSAFE_INLINE_API StringCbGetsExW(wchar_t* pszDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(wchar_t); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringGetsExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags); - } - - if (SUCCEEDED(hr) || - (hr == STRSAFE_E_INSUFFICIENT_BUFFER) || - (hr == STRSAFE_E_END_OF_FILE)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)); - } - } - - return hr; -} -#endif // !STRSAFE_NO_CB_FUNCTIONS -#endif // !STRSAFE_LIB_IMPL - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI -StringCchLength( - IN LPCTSTR psz, - IN size_t cchMax, - OUT size_t* pcch OPTIONAL - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strlen'. - It is used to make sure a string is not larger than a given length, and - it optionally returns the current length in characters not including - the null terminator. - - This function returns a hresult, and not a pointer. It returns - S_OK if the string is non-null and the length including the null - terminator is less than or equal to cchMax characters. - -Arguments: - - psz - string to check the length of - - cchMax - maximum number of characters including the null terminator - that psz is allowed to contain - - pcch - if the function succeeds and pcch is non-null, the current length - in characters of psz excluding the null terminator will be returned. - This out parameter is equivalent to the return value of strlen(psz) - -Notes: - psz can be null but the function will fail - - cchMax should be greater than zero or the function will fail - -Return Value: - - S_OK - psz is non-null and the length including the null - terminator is less than or equal to cchMax characters - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function. - ---*/ - -STRSAFEAPI StringCchLengthA(const char* psz, size_t cchMax, size_t* pcch); -STRSAFEAPI StringCchLengthW(const wchar_t* psz, size_t cchMax, size_t* pcch); -#ifdef UNICODE -#define StringCchLength StringCchLengthW -#else -#define StringCchLength StringCchLengthA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchLengthA(const char* psz, size_t cchMax, size_t* pcch) -{ - HRESULT hr; - - if ((psz == NULL) || (cchMax > STRSAFE_MAX_CCH)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringLengthWorkerA(psz, cchMax, pcch); - } - - return hr; -} - -STRSAFEAPI StringCchLengthW(const wchar_t* psz, size_t cchMax, size_t* pcch) -{ - HRESULT hr; - - if ((psz == NULL) || (cchMax > STRSAFE_MAX_CCH)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringLengthWorkerW(psz, cchMax, pcch); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI -StringCbLength( - IN LPCTSTR psz, - IN size_t cbMax, - OUT size_t* pcb OPTIONAL - ); - -Routine Description: - - This routine is a safer version of the C built-in function 'strlen'. - It is used to make sure a string is not larger than a given length, and - it optionally returns the current length in bytes not including - the null terminator. - - This function returns a hresult, and not a pointer. It returns - S_OK if the string is non-null and the length including the null - terminator is less than or equal to cbMax bytes. - -Arguments: - - psz - string to check the length of - - cbMax - maximum number of bytes including the null terminator - that psz is allowed to contain - - pcb - if the function succeeds and pcb is non-null, the current length - in bytes of psz excluding the null terminator will be returned. - This out parameter is equivalent to the return value of strlen(psz) * sizeof(TCHAR) - -Notes: - psz can be null but the function will fail - - cbMax should be greater than or equal to sizeof(TCHAR) or the function will fail - -Return Value: - - S_OK - psz is non-null and the length including the null - terminator is less than or equal to cbMax bytes - - failure - you can use the macro HRESULT_CODE() to get a win32 - error code for all hresult failure cases - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function. - ---*/ - -STRSAFEAPI StringCbLengthA(const char* psz, size_t cchMax, size_t* pcch); -STRSAFEAPI StringCbLengthW(const wchar_t* psz, size_t cchMax, size_t* pcch); -#ifdef UNICODE -#define StringCbLength StringCbLengthW -#else -#define StringCbLength StringCbLengthA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbLengthA(const char* psz, size_t cbMax, size_t* pcb) -{ - HRESULT hr; - size_t cchMax; - size_t cch = 0; - - cchMax = cbMax / sizeof(char); - - if ((psz == NULL) || (cchMax > STRSAFE_MAX_CCH)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringLengthWorkerA(psz, cchMax, &cch); - } - - if (SUCCEEDED(hr) && pcb) - { - // safe to multiply cch * sizeof(char) since cch < STRSAFE_MAX_CCH and sizeof(char) is 1 - *pcb = cch * sizeof(char); - } - - return hr; -} - -STRSAFEAPI StringCbLengthW(const wchar_t* psz, size_t cbMax, size_t* pcb) -{ - HRESULT hr; - size_t cchMax; - size_t cch = 0; - - cchMax = cbMax / sizeof(wchar_t); - - if ((psz == NULL) || (cchMax > STRSAFE_MAX_CCH)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringLengthWorkerW(psz, cchMax, &cch); - } - - if (SUCCEEDED(hr) && pcb) - { - // safe to multiply cch * sizeof(wchar_t) since cch < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2 - *pcb = cch * sizeof(wchar_t); - } - - return hr; -} -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -// these are the worker functions that actually do the work -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCopyWorkerA(char* pszDest, size_t cchDest, const char* pszSrc) -{ - HRESULT hr = S_OK; - - if (cchDest == 0) - { - // can not null terminate a zero-byte dest buffer - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - while (cchDest && (*pszSrc != '\0')) - { - *pszDest++ = *pszSrc++; - cchDest--; - } - - if (cchDest == 0) - { - // we are going to truncate pszDest - pszDest--; - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - - *pszDest= '\0'; - } - - return hr; -} - -STRSAFEAPI StringCopyWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc) -{ - HRESULT hr = S_OK; - - if (cchDest == 0) - { - // can not null terminate a zero-byte dest buffer - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - while (cchDest && (*pszSrc != L'\0')) - { - *pszDest++ = *pszSrc++; - cchDest--; - } - - if (cchDest == 0) - { - // we are going to truncate pszDest - pszDest--; - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - - *pszDest= L'\0'; - } - - return hr; -} - -STRSAFEAPI StringCopyExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr = S_OK; - char* pszDestEnd = pszDest; - size_t cchRemaining = 0; - - // ASSERT(cbDest == (cchDest * sizeof(char)) || - // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest != 0) || (cbDest != 0)) - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - - if (pszSrc == NULL) - { - pszSrc = ""; - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest == 0) - { - pszDestEnd = pszDest; - cchRemaining = 0; - - // only fail if there was actually src data to copy - if (*pszSrc != '\0') - { - if (pszDest == NULL) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - } - } - else - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - while (cchRemaining && (*pszSrc != '\0')) - { - *pszDestEnd++= *pszSrc++; - cchRemaining--; - } - - if (cchRemaining > 0) - { - if (dwFlags & STRSAFE_FILL_BEHIND_NULL) - { - memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(char)) + (cbDest % sizeof(char))); - } - } - else - { - // we are going to truncate pszDest - pszDestEnd--; - cchRemaining++; - - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - - *pszDestEnd = '\0'; - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = '\0'; - } - } - - if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = '\0'; - } - } - } - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} - -STRSAFEAPI StringCopyExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr = S_OK; - wchar_t* pszDestEnd = pszDest; - size_t cchRemaining = 0; - - // ASSERT(cbDest == (cchDest * sizeof(wchar_t)) || - // cbDest == (cchDest * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest != 0) || (cbDest != 0)) - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - - if (pszSrc == NULL) - { - pszSrc = L""; - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest == 0) - { - pszDestEnd = pszDest; - cchRemaining = 0; - - // only fail if there was actually src data to copy - if (*pszSrc != L'\0') - { - if (pszDest == NULL) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - } - } - else - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - while (cchRemaining && (*pszSrc != L'\0')) - { - *pszDestEnd++= *pszSrc++; - cchRemaining--; - } - - if (cchRemaining > 0) - { - if (dwFlags & STRSAFE_FILL_BEHIND_NULL) - { - memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t))); - } - } - else - { - // we are going to truncate pszDest - pszDestEnd--; - cchRemaining++; - - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - - *pszDestEnd = L'\0'; - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = L'\0'; - } - } - - if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = L'\0'; - } - } - } - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} - -STRSAFEAPI StringCopyNWorkerA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchSrc) -{ - HRESULT hr = S_OK; - - if (cchDest == 0) - { - // can not null terminate a zero-byte dest buffer - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - while (cchDest && cchSrc && (*pszSrc != '\0')) - { - *pszDest++= *pszSrc++; - cchDest--; - cchSrc--; - } - - if (cchDest == 0) - { - // we are going to truncate pszDest - pszDest--; - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - - *pszDest= '\0'; - } - - return hr; -} - -STRSAFEAPI StringCopyNWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchSrc) -{ - HRESULT hr = S_OK; - - if (cchDest == 0) - { - // can not null terminate a zero-byte dest buffer - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - while (cchDest && cchSrc && (*pszSrc != L'\0')) - { - *pszDest++= *pszSrc++; - cchDest--; - cchSrc--; - } - - if (cchDest == 0) - { - // we are going to truncate pszDest - pszDest--; - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - - *pszDest= L'\0'; - } - - return hr; -} - -STRSAFEAPI StringCopyNExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, size_t cchSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr = S_OK; - char* pszDestEnd = pszDest; - size_t cchRemaining = 0; - - // ASSERT(cbDest == (cchDest * sizeof(char)) || - // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest != 0) || (cbDest != 0)) - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - - if (pszSrc == NULL) - { - pszSrc = ""; - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest == 0) - { - pszDestEnd = pszDest; - cchRemaining = 0; - - // only fail if there was actually src data to copy - if (*pszSrc != '\0') - { - if (pszDest == NULL) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - } - } - else - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - while (cchRemaining && cchSrc && (*pszSrc != '\0')) - { - *pszDestEnd++= *pszSrc++; - cchRemaining--; - cchSrc--; - } - - if (cchRemaining > 0) - { - if (dwFlags & STRSAFE_FILL_BEHIND_NULL) - { - memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(char)) + (cbDest % sizeof(char))); - } - } - else - { - // we are going to truncate pszDest - pszDestEnd--; - cchRemaining++; - - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - - *pszDestEnd = '\0'; - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = '\0'; - } - } - - if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = '\0'; - } - } - } - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} - -STRSAFEAPI StringCopyNExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, size_t cchSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr = S_OK; - wchar_t* pszDestEnd = pszDest; - size_t cchRemaining = 0; - - // ASSERT(cbDest == (cchDest * sizeof(wchar_t)) || - // cbDest == (cchDest * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest != 0) || (cbDest != 0)) - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - - if (pszSrc == NULL) - { - pszSrc = L""; - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest == 0) - { - pszDestEnd = pszDest; - cchRemaining = 0; - - // only fail if there was actually src data to copy - if (*pszSrc != L'\0') - { - if (pszDest == NULL) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - } - } - else - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - while (cchRemaining && cchSrc && (*pszSrc != L'\0')) - { - *pszDestEnd++= *pszSrc++; - cchRemaining--; - cchSrc--; - } - - if (cchRemaining > 0) - { - if (dwFlags & STRSAFE_FILL_BEHIND_NULL) - { - memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t))); - } - } - else - { - // we are going to truncate pszDest - pszDestEnd--; - cchRemaining++; - - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - - *pszDestEnd = L'\0'; - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = L'\0'; - } - } - - if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = L'\0'; - } - } - } - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} - -STRSAFEAPI StringCatWorkerA(char* pszDest, size_t cchDest, const char* pszSrc) -{ - HRESULT hr; - size_t cchDestCurrent; - - hr = StringLengthWorkerA(pszDest, cchDest, &cchDestCurrent); - - if (SUCCEEDED(hr)) - { - hr = StringCopyWorkerA(pszDest + cchDestCurrent, - cchDest - cchDestCurrent, - pszSrc); - } - - return hr; -} - -STRSAFEAPI StringCatWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc) -{ - HRESULT hr; - size_t cchDestCurrent; - - hr = StringLengthWorkerW(pszDest, cchDest, &cchDestCurrent); - - if (SUCCEEDED(hr)) - { - hr = StringCopyWorkerW(pszDest + cchDestCurrent, - cchDest - cchDestCurrent, - pszSrc); - } - - return hr; -} - -STRSAFEAPI StringCatExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr = S_OK; - char* pszDestEnd = pszDest; - size_t cchRemaining = 0; - - // ASSERT(cbDest == (cchDest * sizeof(char)) || - // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cchDestCurrent; - - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest == 0) && (cbDest == 0)) - { - cchDestCurrent = 0; - } - else - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - else - { - hr = StringLengthWorkerA(pszDest, cchDest, &cchDestCurrent); - - if (SUCCEEDED(hr)) - { - pszDestEnd = pszDest + cchDestCurrent; - cchRemaining = cchDest - cchDestCurrent; - } - } - - if (pszSrc == NULL) - { - pszSrc = ""; - } - } - else - { - hr = StringLengthWorkerA(pszDest, cchDest, &cchDestCurrent); - - if (SUCCEEDED(hr)) - { - pszDestEnd = pszDest + cchDestCurrent; - cchRemaining = cchDest - cchDestCurrent; - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest == 0) - { - // only fail if there was actually src data to append - if (*pszSrc != '\0') - { - if (pszDest == NULL) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - } - } - else - { - // we handle the STRSAFE_FILL_ON_FAILURE and STRSAFE_NULL_ON_FAILURE cases below, so do not pass - // those flags through - hr = StringCopyExWorkerA(pszDestEnd, - cchRemaining, - (cchRemaining * sizeof(char)) + (cbDest % sizeof(char)), - pszSrc, - &pszDestEnd, - &cchRemaining, - dwFlags & (~(STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE))); - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - // STRSAFE_NO_TRUNCATION is taken care of by StringCopyExWorkerA() - - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else - if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = '\0'; - } - } - - if (dwFlags & STRSAFE_NULL_ON_FAILURE) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = '\0'; - } - } - } - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} - -STRSAFEAPI StringCatExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr = S_OK; - wchar_t* pszDestEnd = pszDest; - size_t cchRemaining = 0; - - // ASSERT(cbDest == (cchDest * sizeof(wchar_t)) || - // cbDest == (cchDest * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cchDestCurrent; - - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest == 0) && (cbDest == 0)) - { - cchDestCurrent = 0; - } - else - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - else - { - hr = StringLengthWorkerW(pszDest, cchDest, &cchDestCurrent); - - if (SUCCEEDED(hr)) - { - pszDestEnd = pszDest + cchDestCurrent; - cchRemaining = cchDest - cchDestCurrent; - } - } - - if (pszSrc == NULL) - { - pszSrc = L""; - } - } - else - { - hr = StringLengthWorkerW(pszDest, cchDest, &cchDestCurrent); - - if (SUCCEEDED(hr)) - { - pszDestEnd = pszDest + cchDestCurrent; - cchRemaining = cchDest - cchDestCurrent; - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest == 0) - { - // only fail if there was actually src data to append - if (*pszSrc != L'\0') - { - if (pszDest == NULL) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - } - } - else - { - // we handle the STRSAFE_FILL_ON_FAILURE and STRSAFE_NULL_ON_FAILURE cases below, so do not pass - // those flags through - hr = StringCopyExWorkerW(pszDestEnd, - cchRemaining, - (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)), - pszSrc, - &pszDestEnd, - &cchRemaining, - dwFlags & (~(STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE))); - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - // STRSAFE_NO_TRUNCATION is taken care of by StringCopyExWorkerW() - - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = L'\0'; - } - } - - if (dwFlags & STRSAFE_NULL_ON_FAILURE) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = L'\0'; - } - } - } - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} - -STRSAFEAPI StringCatNWorkerA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchMaxAppend) -{ - HRESULT hr; - size_t cchDestCurrent; - - hr = StringLengthWorkerA(pszDest, cchDest, &cchDestCurrent); - - if (SUCCEEDED(hr)) - { - hr = StringCopyNWorkerA(pszDest + cchDestCurrent, - cchDest - cchDestCurrent, - pszSrc, - cchMaxAppend); - } - - return hr; -} - -STRSAFEAPI StringCatNWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchMaxAppend) -{ - HRESULT hr; - size_t cchDestCurrent; - - hr = StringLengthWorkerW(pszDest, cchDest, &cchDestCurrent); - - if (SUCCEEDED(hr)) - { - hr = StringCopyNWorkerW(pszDest + cchDestCurrent, - cchDest - cchDestCurrent, - pszSrc, - cchMaxAppend); - } - - return hr; -} - -STRSAFEAPI StringCatNExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, size_t cchMaxAppend, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr = S_OK; - char* pszDestEnd = pszDest; - size_t cchRemaining = 0; - size_t cchDestCurrent = 0; - - // ASSERT(cbDest == (cchDest * sizeof(char)) || - // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest == 0) && (cbDest == 0)) - { - cchDestCurrent = 0; - } - else - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - else - { - hr = StringLengthWorkerA(pszDest, cchDest, &cchDestCurrent); - - if (SUCCEEDED(hr)) - { - pszDestEnd = pszDest + cchDestCurrent; - cchRemaining = cchDest - cchDestCurrent; - } - } - - if (pszSrc == NULL) - { - pszSrc = ""; - } - } - else - { - hr = StringLengthWorkerA(pszDest, cchDest, &cchDestCurrent); - - if (SUCCEEDED(hr)) - { - pszDestEnd = pszDest + cchDestCurrent; - cchRemaining = cchDest - cchDestCurrent; - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest == 0) - { - // only fail if there was actually src data to append - if (*pszSrc != '\0') - { - if (pszDest == NULL) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - } - } - else - { - // we handle the STRSAFE_FILL_ON_FAILURE and STRSAFE_NULL_ON_FAILURE cases below, so do not pass - // those flags through - hr = StringCopyNExWorkerA(pszDestEnd, - cchRemaining, - (cchRemaining * sizeof(char)) + (cbDest % sizeof(char)), - pszSrc, - cchMaxAppend, - &pszDestEnd, - &cchRemaining, - dwFlags & (~(STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE))); - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - // STRSAFE_NO_TRUNCATION is taken care of by StringCopyNExWorkerA() - - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = '\0'; - } - } - - if (dwFlags & (STRSAFE_NULL_ON_FAILURE)) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = '\0'; - } - } - } - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} - -STRSAFEAPI StringCatNExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, size_t cchMaxAppend, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr = S_OK; - wchar_t* pszDestEnd = pszDest; - size_t cchRemaining = 0; - size_t cchDestCurrent = 0; - - - // ASSERT(cbDest == (cchDest * sizeof(wchar_t)) || - // cbDest == (cchDest * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest == 0) && (cbDest == 0)) - { - cchDestCurrent = 0; - } - else - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - else - { - hr = StringLengthWorkerW(pszDest, cchDest, &cchDestCurrent); - - if (SUCCEEDED(hr)) - { - pszDestEnd = pszDest + cchDestCurrent; - cchRemaining = cchDest - cchDestCurrent; - } - } - - if (pszSrc == NULL) - { - pszSrc = L""; - } - } - else - { - hr = StringLengthWorkerW(pszDest, cchDest, &cchDestCurrent); - - if (SUCCEEDED(hr)) - { - pszDestEnd = pszDest + cchDestCurrent; - cchRemaining = cchDest - cchDestCurrent; - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest == 0) - { - // only fail if there was actually src data to append - if (*pszSrc != L'\0') - { - if (pszDest == NULL) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - } - } - else - { - // we handle the STRSAFE_FILL_ON_FAILURE and STRSAFE_NULL_ON_FAILURE cases below, so do not pass - // those flags through - hr = StringCopyNExWorkerW(pszDestEnd, - cchRemaining, - (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)), - pszSrc, - cchMaxAppend, - &pszDestEnd, - &cchRemaining, - dwFlags & (~(STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE))); - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - // STRSAFE_NO_TRUNCATION is taken care of by StringCopyNExWorkerW() - - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = L'\0'; - } - } - - if (dwFlags & (STRSAFE_NULL_ON_FAILURE)) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = L'\0'; - } - } - } - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} - -STRSAFEAPI StringVPrintfWorkerA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList) -{ - HRESULT hr = S_OK; - - if (cchDest == 0) - { - // can not null terminate a zero-byte dest buffer - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - int iRet; - size_t cchMax; - - // leave the last space for the null terminator - cchMax = cchDest - 1; - - iRet = _vsnprintf(pszDest, cchMax, pszFormat, argList); - // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax)); - - if ((iRet < 0) || (((size_t)iRet) > cchMax)) - { - // need to null terminate the string - pszDest += cchMax; - *pszDest = '\0'; - - // we have truncated pszDest - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - else if (((size_t)iRet) == cchMax) - { - // need to null terminate the string - pszDest += cchMax; - *pszDest = '\0'; - } - } - - return hr; -} - -STRSAFEAPI StringVPrintfWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszFormat, va_list argList) -{ - HRESULT hr = S_OK; - - if (cchDest == 0) - { - // can not null terminate a zero-byte dest buffer - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - int iRet; - size_t cchMax; - - // leave the last space for the null terminator - cchMax = cchDest - 1; - - iRet = _vsnwprintf(pszDest, cchMax, pszFormat, argList); - // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax)); - - if ((iRet < 0) || (((size_t)iRet) > cchMax)) - { - // need to null terminate the string - pszDest += cchMax; - *pszDest = L'\0'; - - // we have truncated pszDest - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - else if (((size_t)iRet) == cchMax) - { - // need to null terminate the string - pszDest += cchMax; - *pszDest = L'\0'; - } - } - - return hr; -} - -STRSAFEAPI StringVPrintfExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList) -{ - HRESULT hr = S_OK; - char* pszDestEnd = pszDest; - size_t cchRemaining = 0; - - // ASSERT(cbDest == (cchDest * sizeof(char)) || - // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest != 0) || (cbDest != 0)) - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - - if (pszFormat == NULL) - { - pszFormat = ""; - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest == 0) - { - pszDestEnd = pszDest; - cchRemaining = 0; - - // only fail if there was actually a non-empty format string - if (*pszFormat != '\0') - { - if (pszDest == NULL) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - } - } - else - { - int iRet; - size_t cchMax; - - // leave the last space for the null terminator - cchMax = cchDest - 1; - - iRet = _vsnprintf(pszDest, cchMax, pszFormat, argList); - // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax)); - - if ((iRet < 0) || (((size_t)iRet) > cchMax)) - { - // we have truncated pszDest - pszDestEnd = pszDest + cchMax; - cchRemaining = 1; - - // need to null terminate the string - *pszDestEnd = '\0'; - - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - else if (((size_t)iRet) == cchMax) - { - // string fit perfectly - pszDestEnd = pszDest + cchMax; - cchRemaining = 1; - - // need to null terminate the string - *pszDestEnd = '\0'; - } - else if (((size_t)iRet) < cchMax) - { - // there is extra room - pszDestEnd = pszDest + iRet; - cchRemaining = cchDest - iRet; - - if (dwFlags & STRSAFE_FILL_BEHIND_NULL) - { - memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(char)) + (cbDest % sizeof(char))); - } - } - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = '\0'; - } - } - - if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = '\0'; - } - } - } - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} - -STRSAFEAPI StringVPrintfExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const wchar_t* pszFormat, va_list argList) -{ - HRESULT hr = S_OK; - wchar_t* pszDestEnd = pszDest; - size_t cchRemaining = 0; - - // ASSERT(cbDest == (cchDest * sizeof(wchar_t)) || - // cbDest == (cchDest * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest != 0) || (cbDest != 0)) - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - - if (pszFormat == NULL) - { - pszFormat = L""; - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest == 0) - { - pszDestEnd = pszDest; - cchRemaining = 0; - - // only fail if there was actually a non-empty format string - if (*pszFormat != L'\0') - { - if (pszDest == NULL) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - } - } - else - { - int iRet; - size_t cchMax; - - // leave the last space for the null terminator - cchMax = cchDest - 1; - - iRet = _vsnwprintf(pszDest, cchMax, pszFormat, argList); - // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax)); - - if ((iRet < 0) || (((size_t)iRet) > cchMax)) - { - // we have truncated pszDest - pszDestEnd = pszDest + cchMax; - cchRemaining = 1; - - // need to null terminate the string - *pszDestEnd = L'\0'; - - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - else if (((size_t)iRet) == cchMax) - { - // string fit perfectly - pszDestEnd = pszDest + cchMax; - cchRemaining = 1; - - // need to null terminate the string - *pszDestEnd = L'\0'; - } - else if (((size_t)iRet) < cchMax) - { - // there is extra room - pszDestEnd = pszDest + iRet; - cchRemaining = cchDest - iRet; - - if (dwFlags & STRSAFE_FILL_BEHIND_NULL) - { - memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t))); - } - } - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = L'\0'; - } - } - - if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = L'\0'; - } - } - } - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} - -STRSAFEAPI StringLengthWorkerA(const char* psz, size_t cchMax, size_t* pcch) -{ - HRESULT hr = S_OK; - size_t cchMaxPrev = cchMax; - - while (cchMax && (*psz != '\0')) - { - psz++; - cchMax--; - } - - if (cchMax == 0) - { - // the string is longer than cchMax - hr = STRSAFE_E_INVALID_PARAMETER; - } - - if (SUCCEEDED(hr) && pcch) - { - *pcch = cchMaxPrev - cchMax; - } - - return hr; -} - -STRSAFEAPI StringLengthWorkerW(const wchar_t* psz, size_t cchMax, size_t* pcch) -{ - HRESULT hr = S_OK; - size_t cchMaxPrev = cchMax; - - while (cchMax && (*psz != L'\0')) - { - psz++; - cchMax--; - } - - if (cchMax == 0) - { - // the string is longer than cchMax - hr = STRSAFE_E_INVALID_PARAMETER; - } - - if (SUCCEEDED(hr) && pcch) - { - *pcch = cchMaxPrev - cchMax; - } - - return hr; -} -#endif // STRSAFE_INLINE - -#ifndef STRSAFE_LIB_IMPL -STRSAFE_INLINE_API StringGetsExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr = S_OK; - char* pszDestEnd = pszDest; - size_t cchRemaining = 0; - - // ASSERT(cbDest == (cchDest * sizeof(char)) || - // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest != 0) || (cbDest != 0)) - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest <= 1) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - if (cchDest == 1) - { - *pszDestEnd = '\0'; - } - - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - else - { - char ch; - - pszDestEnd = pszDest; - cchRemaining = cchDest; - - while ((cchRemaining > 1) && (ch = (char)getc(stdin)) != '\n') - { - if (ch == EOF) - { - if (pszDestEnd == pszDest) - { - // we failed to read anything from stdin - hr = STRSAFE_E_END_OF_FILE; - } - break; - } - - *pszDestEnd = ch; - - pszDestEnd++; - cchRemaining--; - } - - if (cchRemaining > 0) - { - // there is extra room - if (dwFlags & STRSAFE_FILL_BEHIND_NULL) - { - memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(char)) + (cbDest % sizeof(char))); - } - } - - *pszDestEnd = '\0'; - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = '\0'; - } - } - - if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = '\0'; - } - } - } - } - - if (SUCCEEDED(hr) || - (hr == STRSAFE_E_INSUFFICIENT_BUFFER) || - (hr == STRSAFE_E_END_OF_FILE)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} - -STRSAFE_INLINE_API StringGetsExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags) -{ - HRESULT hr = S_OK; - wchar_t* pszDestEnd = pszDest; - size_t cchRemaining = 0; - - // ASSERT(cbDest == (cchDest * sizeof(char)) || - // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest != 0) || (cbDest != 0)) - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest <= 1) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - if (cchDest == 1) - { - *pszDestEnd = L'\0'; - } - - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - else - { - wchar_t ch; - - pszDestEnd = pszDest; - cchRemaining = cchDest; - - while ((cchRemaining > 1) && (ch = (wchar_t)getwc(stdin)) != L'\n') - { - if (ch == EOF) - { - if (pszDestEnd == pszDest) - { - // we failed to read anything from stdin - hr = STRSAFE_E_END_OF_FILE; - } - break; - } - - *pszDestEnd = ch; - - pszDestEnd++; - cchRemaining--; - } - - if (cchRemaining > 0) - { - // there is extra room - if (dwFlags & STRSAFE_FILL_BEHIND_NULL) - { - memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t))); - } - } - - *pszDestEnd = L'\0'; - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = L'\0'; - } - } - - if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = L'\0'; - } - } - } - } - - if (SUCCEEDED(hr) || - (hr == STRSAFE_E_INSUFFICIENT_BUFFER) || - (hr == STRSAFE_E_END_OF_FILE)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} -#endif // !STRSAFE_LIB_IMPL - - -// Do not call these functions, they are worker functions for internal use within this file -#ifdef DEPRECATE_SUPPORTED -#pragma deprecated(StringCopyWorkerA) -#pragma deprecated(StringCopyWorkerW) -#pragma deprecated(StringCopyExWorkerA) -#pragma deprecated(StringCopyExWorkerW) -#pragma deprecated(StringCatWorkerA) -#pragma deprecated(StringCatWorkerW) -#pragma deprecated(StringCatExWorkerA) -#pragma deprecated(StringCatExWorkerW) -#pragma deprecated(StringCatNWorkerA) -#pragma deprecated(StringCatNWorkerW) -#pragma deprecated(StringCatNExWorkerA) -#pragma deprecated(StringCatNExWorkerW) -#pragma deprecated(StringVPrintfWorkerA) -#pragma deprecated(StringVPrintfWorkerW) -#pragma deprecated(StringVPrintfExWorkerA) -#pragma deprecated(StringVPrintfExWorkerW) -#pragma deprecated(StringLengthWorkerA) -#pragma deprecated(StringLengthWorkerW) -#else -#define StringCopyWorkerA StringCopyWorkerA_instead_use_StringCchCopyA_or_StringCchCopyExA; -#define StringCopyWorkerW StringCopyWorkerW_instead_use_StringCchCopyW_or_StringCchCopyExW; -#define StringCopyExWorkerA StringCopyExWorkerA_instead_use_StringCchCopyA_or_StringCchCopyExA; -#define StringCopyExWorkerW StringCopyExWorkerW_instead_use_StringCchCopyW_or_StringCchCopyExW; -#define StringCatWorkerA StringCatWorkerA_instead_use_StringCchCatA_or_StringCchCatExA; -#define StringCatWorkerW StringCatWorkerW_instead_use_StringCchCatW_or_StringCchCatExW; -#define StringCatExWorkerA StringCatExWorkerA_instead_use_StringCchCatA_or_StringCchCatExA; -#define StringCatExWorkerW StringCatExWorkerW_instead_use_StringCchCatW_or_StringCchCatExW; -#define StringCatNWorkerA StringCatNWorkerA_instead_use_StringCchCatNA_or_StrincCbCatNA; -#define StringCatNWorkerW StringCatNWorkerW_instead_use_StringCchCatNW_or_StringCbCatNW; -#define StringCatNExWorkerA StringCatNExWorkerA_instead_use_StringCchCatNExA_or_StringCbCatNExA; -#define StringCatNExWorkerW StringCatNExWorkerW_instead_use_StringCchCatNExW_or_StringCbCatNExW; -#define StringVPrintfWorkerA StringVPrintfWorkerA_instead_use_StringCchVPrintfA_or_StringCchVPrintfExA; -#define StringVPrintfWorkerW StringVPrintfWorkerW_instead_use_StringCchVPrintfW_or_StringCchVPrintfExW; -#define StringVPrintfExWorkerA StringVPrintfExWorkerA_instead_use_StringCchVPrintfA_or_StringCchVPrintfExA; -#define StringVPrintfExWorkerW StringVPrintfExWorkerW_instead_use_StringCchVPrintfW_or_StringCchVPrintfExW; -#define StringLengthWorkerA StringLengthWorkerA_instead_use_StringCchLengthA_or_StringCbLengthA; -#define StringLengthWorkerW StringLengthWorkerW_instead_use_StringCchLengthW_or_StringCbLengthW; -#endif // !DEPRECATE_SUPPORTED - - -#ifndef STRSAFE_NO_DEPRECATE -// Deprecate all of the unsafe functions to generate compiletime errors. If you do not want -// this then you can #define STRSAFE_NO_DEPRECATE before including this file. -#ifdef DEPRECATE_SUPPORTED - -// First all the names that are a/w variants (or shouldn't be #defined by now anyway). -#pragma deprecated(lstrcpyA) -#pragma deprecated(lstrcpyW) -#pragma deprecated(lstrcatA) -#pragma deprecated(lstrcatW) -#pragma deprecated(wsprintfA) -#pragma deprecated(wsprintfW) - -#pragma deprecated(StrCpyW) -#pragma deprecated(StrCatW) -#pragma deprecated(StrNCatA) -#pragma deprecated(StrNCatW) -#pragma deprecated(StrCatNA) -#pragma deprecated(StrCatNW) -#pragma deprecated(wvsprintfA) -#pragma deprecated(wvsprintfW) - -#pragma deprecated(strcpy) -#pragma deprecated(wcscpy) -#pragma deprecated(strcat) -#pragma deprecated(wcscat) -#pragma deprecated(sprintf) -#pragma deprecated(swprintf) -#pragma deprecated(vsprintf) -#pragma deprecated(vswprintf) -#pragma deprecated(_snprintf) -#pragma deprecated(_snwprintf) -#pragma deprecated(_vsnprintf) -#pragma deprecated(_vsnwprintf) -#pragma deprecated(gets) -#pragma deprecated(_getws) - -// Then all the windows.h names - we need to undef and redef based on UNICODE setting -#undef lstrcpy -#undef lstrcat -#undef wsprintf -#undef wvsprintf -#pragma deprecated(lstrcpy) -#pragma deprecated(lstrcat) -#pragma deprecated(wsprintf) -#pragma deprecated(wvsprintf) -#ifdef UNICODE -#define lstrcpy lstrcpyW -#define lstrcat lstrcatW -#define wsprintf wsprintfW -#define wvsprintf wvsprintfW -#else -#define lstrcpy lstrcpyA -#define lstrcat lstrcatA -#define wsprintf wsprintfA -#define wvsprintf wvsprintfA -#endif - -// Then the shlwapi names - they key off UNICODE also. -#undef StrCpyA -#undef StrCpy -#undef StrCatA -#undef StrCat -#undef StrNCat -#undef StrCatN -#pragma deprecated(StrCpyA) -#pragma deprecated(StrCatA) -#pragma deprecated(StrCatN) -#pragma deprecated(StrCpy) -#pragma deprecated(StrCat) -#pragma deprecated(StrNCat) -#define StrCpyA lstrcpyA -#define StrCatA lstrcatA -#define StrCatN StrNCat -#ifdef UNICODE -#define StrCpy StrCpyW -#define StrCat StrCatW -#define StrNCat StrNCatW -#else -#define StrCpy lstrcpyA -#define StrCat lstrcatA -#define StrNCat StrNCatA -#endif - -// Then all the CRT names - we need to undef/redef based on _UNICODE value. -#undef _tcscpy -#undef _ftcscpy -#undef _tcscat -#undef _ftcscat -#undef _stprintf -#undef _sntprintf -#undef _vstprintf -#undef _vsntprintf -#undef _getts -#pragma deprecated(_tcscpy) -#pragma deprecated(_ftcscpy) -#pragma deprecated(_tcscat) -#pragma deprecated(_ftcscat) -#pragma deprecated(_stprintf) -#pragma deprecated(_sntprintf) -#pragma deprecated(_vstprintf) -#pragma deprecated(_vsntprintf) -#pragma deprecated(_getts) -#ifdef _UNICODE -#define _tcscpy wcscpy -#define _ftcscpy wcscpy -#define _tcscat wcscat -#define _ftcscat wcscat -#define _stprintf swprintf -#define _sntprintf _snwprintf -#define _vstprintf vswprintf -#define _vsntprintf _vsnwprintf -#define _getts _getws -#else -#define _tcscpy strcpy -#define _ftcscpy strcpy -#define _tcscat strcat -#define _ftcscat strcat -#define _stprintf sprintf -#define _sntprintf _snprintf -#define _vstprintf vsprintf -#define _vsntprintf _vsnprintf -#define _getts gets -#endif - -#else // DEPRECATE_SUPPORTED - -#undef strcpy -#define strcpy strcpy_instead_use_StringCbCopyA_or_StringCchCopyA; - -#undef wcscpy -#define wcscpy wcscpy_instead_use_StringCbCopyW_or_StringCchCopyW; - -#undef strcat -#define strcat strcat_instead_use_StringCbCatA_or_StringCchCatA; - -#undef wcscat -#define wcscat wcscat_instead_use_StringCbCatW_or_StringCchCatW; - -//#undef sprintf -//#define sprintf sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA; - -//#undef swprintf -//#define swprintf swprintf_instead_use_StringCbPrintfW_or_StringCchPrintfW; - -#undef vsprintf -#define vsprintf vsprintf_instead_use_StringCbVPrintfA_or_StringCchVPrintfA; - -#undef vswprintf -#define vswprintf vswprintf_instead_use_StringCbVPrintfW_or_StringCchVPrintfW; - -#undef _snprintf -#define _snprintf _snprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA; - -#undef _snwprintf -#define _snwprintf _snwprintf_instead_use_StringCbPrintfW_or_StringCchPrintfW; - -#undef _vsnprintf -#define _vsnprintf _vsnprintf_instead_use_StringCbVPrintfA_or_StringCchVPrintfA; - -#undef _vsnwprintf -#define _vsnwprintf _vsnwprintf_instead_use_StringCbVPrintfW_or_StringCchVPrintfW; - -#undef strcpyA -#define strcpyA strcpyA_instead_use_StringCbCopyA_or_StringCchCopyA; - -#undef strcpyW -#define strcpyW strcpyW_instead_use_StringCbCopyW_or_StringCchCopyW; - -#undef lstrcpy -#define lstrcpy lstrcpy_instead_use_StringCbCopy_or_StringCchCopy; - -#undef lstrcpyA -#define lstrcpyA lstrcpyA_instead_use_StringCbCopyA_or_StringCchCopyA; - -#undef lstrcpyW -#define lstrcpyW lstrcpyW_instead_use_StringCbCopyW_or_StringCchCopyW; - -#undef StrCpy -#define StrCpy StrCpy_instead_use_StringCbCopy_or_StringCchCopy; - -#undef StrCpyA -#define StrCpyA StrCpyA_instead_use_StringCbCopyA_or_StringCchCopyA; - -#undef StrCpyW -#define StrCpyW StrCpyW_instead_use_StringCbCopyW_or_StringCchCopyW; - -#undef _tcscpy -#define _tcscpy _tcscpy_instead_use_StringCbCopy_or_StringCchCopy; - -#undef _ftcscpy -#define _ftcscpy _ftcscpy_instead_use_StringCbCopy_or_StringCchCopy; - -#undef lstrcat -#define lstrcat lstrcat_instead_use_StringCbCat_or_StringCchCat; - -#undef lstrcatA -#define lstrcatA lstrcatA_instead_use_StringCbCatA_or_StringCchCatA; - -#undef lstrcatW -#define lstrcatW lstrcatW_instead_use_StringCbCatW_or_StringCchCatW; - -#undef StrCat -#define StrCat StrCat_instead_use_StringCbCat_or_StringCchCat; - -#undef StrCatA -#define StrCatA StrCatA_instead_use_StringCbCatA_or_StringCchCatA; - -#undef StrCatW -#define StrCatW StrCatW_instead_use_StringCbCatW_or_StringCchCatW; - -#undef StrNCat -#define StrNCat StrNCat_instead_use_StringCbCatN_or_StringCchCatN; - -#undef StrNCatA -#define StrNCatA StrNCatA_instead_use_StringCbCatNA_or_StringCchCatNA; - -#undef StrNCatW -#define StrNCatW StrNCatW_instead_use_StringCbCatNW_or_StringCchCatNW; - -#undef StrCatN -#define StrCatN StrCatN_instead_use_StringCbCatN_or_StringCchCatN; - -#undef StrCatNA -#define StrCatNA StrCatNA_instead_use_StringCbCatNA_or_StringCchCatNA; - -#undef StrCatNW -#define StrCatNW StrCatNW_instead_use_StringCbCatNW_or_StringCchCatNW; - -#undef _tcscat -#define _tcscat _tcscat_instead_use_StringCbCat_or_StringCchCat; - -#undef _ftcscat -#define _ftcscat _ftcscat_instead_use_StringCbCat_or_StringCchCat; - -#undef wsprintf -#define wsprintf wsprintf_instead_use_StringCbPrintf_or_StringCchPrintf; - -#undef wsprintfA -#define wsprintfA wsprintfA_instead_use_StringCbPrintfA_or_StringCchPrintfA; - -#undef wsprintfW -#define wsprintfW wsprintfW_instead_use_StringCbPrintfW_or_StringCchPrintfW; - -#undef wvsprintf -#define wvsprintf wvsprintf_instead_use_StringCbVPrintf_or_StringCchVPrintf; - -#undef wvsprintfA -#define wvsprintfA wvsprintfA_instead_use_StringCbVPrintfA_or_StringCchVPrintfA; - -#undef wvsprintfW -#define wvsprintfW wvsprintfW_instead_use_StringCbVPrintfW_or_StringCchVPrintfW; - -#undef _vstprintf -#define _vstprintf _vstprintf_instead_use_StringCbVPrintf_or_StringCchVPrintf; - -#undef _vsntprintf -#define _vsntprintf _vsntprintf_instead_use_StringCbVPrintf_or_StringCchVPrintf; - -#undef _stprintf -#define _stprintf _stprintf_instead_use_StringCbPrintf_or_StringCchPrintf; - -#undef _sntprintf -#define _sntprintf _sntprintf_instead_use_StringCbPrintf_or_StringCchPrintf; - -#undef _getts -#define _getts _getts_instead_use_StringCbGets_or_StringCchGets; - -#undef gets -#define gets _gets_instead_use_StringCbGetsA_or_StringCchGetsA; - -#undef _getws -#define _getws _getws_instead_use_StringCbGetsW_or_StringCchGetsW; - -#endif // !DEPRECATE_SUPPORTED -#endif // !STRSAFE_NO_DEPRECATE - -#ifdef _NTSTRSAFE_H_INCLUDED_ -#pragma warning(pop) -#endif // _NTSTRSAFE_H_INCLUDED_ - -#endif // _STRSAFE_H_INCLUDED_ diff --git a/cpp/wiipair/lib/DelcomDLL.lib b/cpp/wiipair/lib/DelcomDLL.lib deleted file mode 100644 index 0c540c6..0000000 Binary files a/cpp/wiipair/lib/DelcomDLL.lib and /dev/null differ diff --git a/cpp/wiipair/lib/advapi32.lib b/cpp/wiipair/lib/advapi32.lib deleted file mode 100644 index 2812216..0000000 Binary files a/cpp/wiipair/lib/advapi32.lib and /dev/null differ diff --git a/cpp/wiipair/lib/comdlg32.lib b/cpp/wiipair/lib/comdlg32.lib deleted file mode 100644 index 181fca1..0000000 Binary files a/cpp/wiipair/lib/comdlg32.lib and /dev/null differ diff --git a/cpp/wiipair/lib/gdi32.lib b/cpp/wiipair/lib/gdi32.lib deleted file mode 100644 index 63172a5..0000000 Binary files a/cpp/wiipair/lib/gdi32.lib and /dev/null differ diff --git a/cpp/wiipair/lib/irprops.lib b/cpp/wiipair/lib/irprops.lib deleted file mode 100644 index 1761118..0000000 Binary files a/cpp/wiipair/lib/irprops.lib and /dev/null differ diff --git a/cpp/wiipair/lib/kernel32.lib b/cpp/wiipair/lib/kernel32.lib deleted file mode 100644 index 77b0e53..0000000 Binary files a/cpp/wiipair/lib/kernel32.lib and /dev/null differ diff --git a/cpp/wiipair/lib/libcpmt.lib b/cpp/wiipair/lib/libcpmt.lib deleted file mode 100644 index 85e91bb..0000000 Binary files a/cpp/wiipair/lib/libcpmt.lib and /dev/null differ diff --git a/cpp/wiipair/lib/odbc32.lib b/cpp/wiipair/lib/odbc32.lib deleted file mode 100644 index 1add151..0000000 Binary files a/cpp/wiipair/lib/odbc32.lib and /dev/null differ diff --git a/cpp/wiipair/lib/odbccp32.lib b/cpp/wiipair/lib/odbccp32.lib deleted file mode 100644 index 0f2ef09..0000000 Binary files a/cpp/wiipair/lib/odbccp32.lib and /dev/null differ diff --git a/cpp/wiipair/lib/ole32.lib b/cpp/wiipair/lib/ole32.lib deleted file mode 100644 index 17d6af8..0000000 Binary files a/cpp/wiipair/lib/ole32.lib and /dev/null differ diff --git a/cpp/wiipair/lib/oleaut32.lib b/cpp/wiipair/lib/oleaut32.lib deleted file mode 100644 index 1955d00..0000000 Binary files a/cpp/wiipair/lib/oleaut32.lib and /dev/null differ diff --git a/cpp/wiipair/lib/shell32.lib b/cpp/wiipair/lib/shell32.lib deleted file mode 100644 index b723320..0000000 Binary files a/cpp/wiipair/lib/shell32.lib and /dev/null differ diff --git a/cpp/wiipair/lib/user32.lib b/cpp/wiipair/lib/user32.lib deleted file mode 100644 index eda26c0..0000000 Binary files a/cpp/wiipair/lib/user32.lib and /dev/null differ diff --git a/cpp/wiipair/lib/uuid.lib b/cpp/wiipair/lib/uuid.lib deleted file mode 100644 index f6e4ae2..0000000 Binary files a/cpp/wiipair/lib/uuid.lib and /dev/null differ diff --git a/cpp/wiipair/lib/wiiuse.lib b/cpp/wiipair/lib/wiiuse.lib deleted file mode 100644 index 6425e72..0000000 Binary files a/cpp/wiipair/lib/wiiuse.lib and /dev/null differ diff --git a/cpp/wiipair/lib/winspool.lib b/cpp/wiipair/lib/winspool.lib deleted file mode 100644 index 61cb936..0000000 Binary files a/cpp/wiipair/lib/winspool.lib and /dev/null differ diff --git a/cpp/wiipair/src/wiipair.cpp b/cpp/wiipair/src/wiipair.cpp deleted file mode 100644 index 764bbe2..0000000 --- a/cpp/wiipair/src/wiipair.cpp +++ /dev/null @@ -1,212 +0,0 @@ -#include -#include -#include -#include -#include -#include - -DWORD ShowErrorCode(LPTSTR msg, DWORD dw) -{ - // Retrieve the system error message for the last-error code - - LPVOID lpMsgBuf; - - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - dw, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &lpMsgBuf, - 0, - NULL - ); - - _tprintf(_T("%s: %s"), msg, lpMsgBuf); - - LocalFree(lpMsgBuf); - - return dw; -} - - -_TCHAR * FormatBTAddress(BLUETOOTH_ADDRESS address) -{ - static _TCHAR ret[20]; - _stprintf(ret, _T("%02x:%02x:%02x:%02x:%02x:%02x"), - address.rgBytes[5], - address.rgBytes[4], - address.rgBytes[3], - address.rgBytes[2], - address.rgBytes[1], - address.rgBytes[0] - ); - return ret; -} - -int _tmain(int argc, _TCHAR* argv[]) -{ - HANDLE hRadios[256]; - int nRadios; - int nPaired = 0; - - /////////////////////////////////////////////////////////////////////// - // Enumerate BT radios - /////////////////////////////////////////////////////////////////////// - { - HBLUETOOTH_RADIO_FIND hFindRadio; - BLUETOOTH_FIND_RADIO_PARAMS radioParam; - - _tprintf(_T("Enumerating radios...\n")); - - radioParam.dwSize = sizeof(BLUETOOTH_FIND_RADIO_PARAMS); - - nRadios = 0; - hFindRadio = BluetoothFindFirstRadio(&radioParam, &hRadios[nRadios++]); - if (hFindRadio) - { - while (BluetoothFindNextRadio(&radioParam, &hRadios[nRadios++])); - BluetoothFindRadioClose(hFindRadio); - } - else - { - ShowErrorCode(_T("Error enumerating radios"), GetLastError()); - return (1); - } - nRadios--; - _tprintf(_T("Found %d radios\n"), nRadios); - } - - /////////////////////////////////////////////////////////////////////// - // Keep looping until we pair with a Wii device - /////////////////////////////////////////////////////////////////////// - - while (nPaired == 0) - { - int radio; - - for (radio = 0; radio < nRadios; radio++) - { - BLUETOOTH_RADIO_INFO radioInfo; - HBLUETOOTH_DEVICE_FIND hFind; - BLUETOOTH_DEVICE_INFO btdi; - BLUETOOTH_DEVICE_SEARCH_PARAMS srch; - - radioInfo.dwSize = sizeof(radioInfo); - btdi.dwSize = sizeof(btdi); - srch.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS); - - ShowErrorCode(_T("BluetoothGetRadioInfo"), BluetoothGetRadioInfo(hRadios[radio], &radioInfo)); - - _tprintf(_T("Radio %d: %ls %s\n"), - radio, - radioInfo.szName, - FormatBTAddress(radioInfo.address) - ); - - srch.fReturnAuthenticated = TRUE; - srch.fReturnRemembered = TRUE; - srch.fReturnConnected = TRUE; - srch.fReturnUnknown = TRUE; - srch.fIssueInquiry = TRUE; - srch.cTimeoutMultiplier = 2; - srch.hRadio = hRadios[radio]; - - _tprintf(_T("Scanning...\n")); - - hFind = BluetoothFindFirstDevice(&srch, &btdi); - - if (hFind == NULL) - { - if (GetLastError() == ERROR_NO_MORE_ITEMS) - { - _tprintf(_T("No bluetooth devices found.\n")); - } - else - { - ShowErrorCode(_T("Error enumerating devices"), GetLastError()); - return (1); - } - } - else - { - do - { - _tprintf(_T("Found: %s\n"), btdi.szName); - - if (!wcscmp(btdi.szName, L"Nintendo RVL-WBC-01") || !wcscmp(btdi.szName, L"Nintendo RVL-CNT-01")) - { - WCHAR pass[6]; - DWORD pcServices = 16; - GUID guids[16]; - BOOL error = FALSE; - - if (!error) - { - if (btdi.fRemembered) - { - // Make Windows forget pairing - if (ShowErrorCode(_T("BluetoothRemoveDevice"), BluetoothRemoveDevice(&btdi.Address)) != ERROR_SUCCESS) - error = TRUE; - } - } - - // MAC address is passphrase - pass[0] = radioInfo.address.rgBytes[0]; - pass[1] = radioInfo.address.rgBytes[1]; - pass[2] = radioInfo.address.rgBytes[2]; - pass[3] = radioInfo.address.rgBytes[3]; - pass[4] = radioInfo.address.rgBytes[4]; - pass[5] = radioInfo.address.rgBytes[5]; - - if (!error) - { - // Pair with Wii device - if (ShowErrorCode(_T("BluetoothAuthenticateDevice"), BluetoothAuthenticateDevice(NULL, hRadios[radio], &btdi, pass, 6)) != ERROR_SUCCESS) - error = TRUE; - } - - if (!error) - { - // If this is not done, the Wii device will not remember the pairing - if (ShowErrorCode(_T("BluetoothEnumerateInstalledServices"), BluetoothEnumerateInstalledServices(hRadios[radio], &btdi, &pcServices, guids)) != ERROR_SUCCESS) - error = TRUE; - } - - /*if (!error) - { - // Activate service - if (ShowErrorCode(_T("BluetoothSetServiceState"), BluetoothSetServiceState(hRadios[radio], &btdi, &HumanInterfaceDeviceServiceClass_UUID, BLUETOOTH_SERVICE_ENABLE)) != ERROR_SUCCESS) - error = TRUE; - }*/ - - if (!error) - { - nPaired++; - } - } // if (!wcscmp(btdi.szName, L"Nintendo RVL-WBC-01") || !wcscmp(btdi.szName, L"Nintendo RVL-CNT-01")) - } - while (BluetoothFindNextDevice(hFind, &btdi)); - } // if (hFind == NULL) - } // for (radio = 0; radio < nRadios; radio++) - - Sleep(1000); - } - - /////////////////////////////////////////////////////////////////////// - // Clean up - /////////////////////////////////////////////////////////////////////// - - { - int radio; - - for (radio = 0; radio < nRadios; radio++) - { - CloseHandle(hRadios[radio]); - } - } - - _tprintf(_T("=============================================\n"), nPaired); - _tprintf(_T("%d Wii devices paired\n"), nPaired); - - return 0; -} diff --git a/cpp/wiiuse/.cproject b/cpp/wiiuse/.cproject deleted file mode 100644 index 4f179f9..0000000 --- a/cpp/wiiuse/.cproject +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/wiiuse/.project b/cpp/wiiuse/.project deleted file mode 100644 index 28aed5a..0000000 --- a/cpp/wiiuse/.project +++ /dev/null @@ -1,70 +0,0 @@ - - - cpp.wiiuse - - - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - clean,full,incremental, - - - ?name? - - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.buildArguments - - - - org.eclipse.cdt.make.core.buildCommand - make - - - org.eclipse.cdt.make.core.buildLocation - ${workspace_loc:/Wiiuse/Debug} - - - org.eclipse.cdt.make.core.contents - org.eclipse.cdt.make.core.activeConfigSettings - - - org.eclipse.cdt.make.core.enableAutoBuild - false - - - org.eclipse.cdt.make.core.enableCleanBuild - true - - - org.eclipse.cdt.make.core.enableFullBuild - true - - - org.eclipse.cdt.make.core.stopOnError - true - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - true - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - org.eclipse.cdt.core.cnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - diff --git a/cpp/wiiuse/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/cpp/wiiuse/.settings/org.eclipse.cdt.managedbuilder.core.prefs deleted file mode 100644 index 5b3588a..0000000 --- a/cpp/wiiuse/.settings/org.eclipse.cdt.managedbuilder.core.prefs +++ /dev/null @@ -1,28 +0,0 @@ -#Wed Oct 19 11:47:57 CEST 2011 -eclipse.preferences.version=1 -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.debug.1116435574/CPATH/delimiter=; -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.debug.1116435574/CPATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.debug.1116435574/C_INCLUDE_PATH/delimiter=; -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.debug.1116435574/C_INCLUDE_PATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.debug.1116435574/append=true -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.debug.1116435574/appendContributed=true -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.release.1074641339.10143143/CPATH/delimiter=; -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.release.1074641339.10143143/CPATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.release.1074641339.10143143/C_INCLUDE_PATH/delimiter=; -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.release.1074641339.10143143/C_INCLUDE_PATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.release.1074641339.10143143/append=true -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.release.1074641339.10143143/appendContributed=true -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.release.1074641339/CPATH/delimiter=; -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.release.1074641339/CPATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.release.1074641339/C_INCLUDE_PATH/delimiter=; -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.release.1074641339/C_INCLUDE_PATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.release.1074641339/append=true -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.release.1074641339/appendContributed=true -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.so.debug.1116435574/LIBRARY_PATH/delimiter=; -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.so.debug.1116435574/LIBRARY_PATH/operation=remove -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.so.debug.1116435574/append=true -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.so.debug.1116435574/appendContributed=true -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.so.release.1074641339/LIBRARY_PATH/delimiter=; -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.so.release.1074641339/LIBRARY_PATH/operation=remove -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.so.release.1074641339/append=true -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.so.release.1074641339/appendContributed=true diff --git a/cpp/wiiuse/Debug/copy.bat b/cpp/wiiuse/Debug/copy.bat deleted file mode 100644 index 7add6c4..0000000 --- a/cpp/wiiuse/Debug/copy.bat +++ /dev/null @@ -1,5 +0,0 @@ -copy ..\src\wiiuse.h ..\..\wiiusej\include\wiiuse.h -copy ..\src\wiiuse.h ..\..\wiiscan\include\wiiuse.h -copy wiiuse.lib ..\..\wiiusej\lib\wiiuse.lib -copy wiiuse.lib ..\..\wiiscan\lib\wiiuse.lib -copy wiiuse.dll ..\..\..\java\wiiusej\wiiuse.dll \ No newline at end of file diff --git a/cpp/wiiuse/Debug/wiiuse.lib b/cpp/wiiuse/Debug/wiiuse.lib deleted file mode 100644 index b9cc79d..0000000 Binary files a/cpp/wiiuse/Debug/wiiuse.lib and /dev/null differ diff --git a/cpp/wiiuse/Release/copy.bat b/cpp/wiiuse/Release/copy.bat deleted file mode 100644 index 7add6c4..0000000 --- a/cpp/wiiuse/Release/copy.bat +++ /dev/null @@ -1,5 +0,0 @@ -copy ..\src\wiiuse.h ..\..\wiiusej\include\wiiuse.h -copy ..\src\wiiuse.h ..\..\wiiscan\include\wiiuse.h -copy wiiuse.lib ..\..\wiiusej\lib\wiiuse.lib -copy wiiuse.lib ..\..\wiiscan\lib\wiiuse.lib -copy wiiuse.dll ..\..\..\java\wiiusej\wiiuse.dll \ No newline at end of file diff --git a/cpp/wiiuse/Release/wiiuse.dll b/cpp/wiiuse/Release/wiiuse.dll deleted file mode 100644 index fe4770f..0000000 Binary files a/cpp/wiiuse/Release/wiiuse.dll and /dev/null differ diff --git a/cpp/wiiuse/Release/wiiuse.lib b/cpp/wiiuse/Release/wiiuse.lib deleted file mode 100644 index b3a2b3b..0000000 Binary files a/cpp/wiiuse/Release/wiiuse.lib and /dev/null differ diff --git a/cpp/wiiuse/include/hidpi.h b/cpp/wiiuse/include/hidpi.h deleted file mode 100644 index e08cf3b..0000000 --- a/cpp/wiiuse/include/hidpi.h +++ /dev/null @@ -1,1788 +0,0 @@ -/*++ - -Copyright (c) Microsoft Corporation. All rights reserved. - -Module Name: - - HIDPI.H - -Abstract: - - Public Interface to the HID parsing library. - -Environment: - - Kernel & user mode - ---*/ - -#ifndef __HIDPI_H__ -#define __HIDPI_H__ - -#include - -// Please include "hidsdi.h" to use the user space (dll / parser) -// Please include "hidpddi.h" to use the kernel space parser - -// -// Special Link collection values for using the query functions -// -// Root collection references the collection at the base of the link -// collection tree. -// Unspecifies, references all collections in the link collection tree. -// -#define HIDP_LINK_COLLECTION_ROOT ((USHORT) -1) -#define HIDP_LINK_COLLECTION_UNSPECIFIED ((USHORT) 0) - - -typedef enum _HIDP_REPORT_TYPE -{ - HidP_Input, - HidP_Output, - HidP_Feature -} HIDP_REPORT_TYPE; - -typedef struct _USAGE_AND_PAGE -{ - USAGE Usage; - USAGE UsagePage; -} USAGE_AND_PAGE, *PUSAGE_AND_PAGE; - -#define HidP_IsSameUsageAndPage(u1, u2) ((* (PULONG) &u1) == (* (PULONG) &u2)) - -typedef struct _HIDP_BUTTON_CAPS -{ - USAGE UsagePage; - UCHAR ReportID; - BOOLEAN IsAlias; - - USHORT BitField; - USHORT LinkCollection; // A unique internal index pointer - - USAGE LinkUsage; - USAGE LinkUsagePage; - - BOOLEAN IsRange; - BOOLEAN IsStringRange; - BOOLEAN IsDesignatorRange; - BOOLEAN IsAbsolute; - - ULONG Reserved[10]; - union { - struct { - USAGE UsageMin, UsageMax; - USHORT StringMin, StringMax; - USHORT DesignatorMin, DesignatorMax; - USHORT DataIndexMin, DataIndexMax; - } Range; - struct { - USAGE Usage, Reserved1; - USHORT StringIndex, Reserved2; - USHORT DesignatorIndex, Reserved3; - USHORT DataIndex, Reserved4; - } NotRange; - }; - -} HIDP_BUTTON_CAPS, *PHIDP_BUTTON_CAPS; - - -typedef struct _HIDP_VALUE_CAPS -{ - USAGE UsagePage; - UCHAR ReportID; - BOOLEAN IsAlias; - - USHORT BitField; - USHORT LinkCollection; // A unique internal index pointer - - USAGE LinkUsage; - USAGE LinkUsagePage; - - BOOLEAN IsRange; - BOOLEAN IsStringRange; - BOOLEAN IsDesignatorRange; - BOOLEAN IsAbsolute; - - BOOLEAN HasNull; // Does this channel have a null report union - UCHAR Reserved; - USHORT BitSize; // How many bits are devoted to this value? - - USHORT ReportCount; // See Note below. Usually set to 1. - USHORT Reserved2[5]; - - ULONG UnitsExp; - ULONG Units; - - LONG LogicalMin, LogicalMax; - LONG PhysicalMin, PhysicalMax; - - union { - struct { - USAGE UsageMin, UsageMax; - USHORT StringMin, StringMax; - USHORT DesignatorMin, DesignatorMax; - USHORT DataIndexMin, DataIndexMax; - } Range; - - struct { - USAGE Usage, Reserved1; - USHORT StringIndex, Reserved2; - USHORT DesignatorIndex, Reserved3; - USHORT DataIndex, Reserved4; - } NotRange; - }; -} HIDP_VALUE_CAPS, *PHIDP_VALUE_CAPS; - -// -// Notes: -// -// ReportCount: When a report descriptor declares an Input, Output, or -// Feature main item with fewer usage declarations than the report count, then -// the last usage applies to all remaining unspecified count in that main item. -// (As an example you might have data that required many fields to describe, -// possibly buffered bytes.) In this case, only one value cap structure is -// allocated for these associtated fields, all with the same usage, and Report -// Count reflects the number of fields involved. Normally ReportCount is 1. -// To access all of the fields in such a value structure would require using -// HidP_GetUsageValueArray and HidP_SetUsageValueArray. HidP_GetUsageValue/ -// HidP_SetScaledUsageValue will also work, however, these functions will only -// work with the first field of the structure. -// - -// -// The link collection tree consists of an array of LINK_COLLECTION_NODES -// where the index into this array is the same as the collection number. -// -// Given a collection A which contains a subcollection B, A is defined to be -// the parent B, and B is defined to be the child. -// -// Given collections A, B, and C where B and C are children of A, and B was -// encountered before C in the report descriptor, B is defined as a sibling of -// C. (This implies, of course, that if B is a sibling of C, then C is NOT a -// sibling of B). -// -// B is defined as the NextSibling of C if and only if there exists NO -// child collection of A, call it D, such that B is a sibling of D and D -// is a sibling of C. -// -// E is defined to be the FirstChild of A if and only if for all children of A, -// F, that are not equivalent to E, F is a sibling of E. -// (This implies, of course, that the does not exist a child of A, call it G, -// where E is a sibling of G). In other words the first sibling is the last -// link collection found in the list. -// -// In other words, if a collection B is defined within the definition of another -// collection A, B becomes a child of A. All collections with the same parent -// are considered siblings. The FirstChild of the parent collection, A, will be -// last collection defined that has A as a parent. The order of sibling pointers -// is similarly determined. When a collection B is defined, it becomes the -// FirstChild of it's parent collection. The previously defined FirstChild of the -// parent collection becomes the NextSibling of the new collection. As new -// collections with the same parent are discovered, the chain of sibling is built. -// -// With that in mind, the following describes conclusively a data structure -// that provides direct traversal up, down, and accross the link collection -// tree. -// -// -typedef struct _HIDP_LINK_COLLECTION_NODE -{ - USAGE LinkUsage; - USAGE LinkUsagePage; - USHORT Parent; - USHORT NumberOfChildren; - USHORT NextSibling; - USHORT FirstChild; - ULONG CollectionType: 8; // As defined in 6.2.2.6 of HID spec - ULONG IsAlias : 1; // This link node is an allias of the next link node. - ULONG Reserved: 23; - PVOID UserContext; // The user can hang his coat here. -} HIDP_LINK_COLLECTION_NODE, *PHIDP_LINK_COLLECTION_NODE; - -// -// When a link collection is described by a delimiter, alias link collection -// nodes are created. (One for each usage within the delimiter). -// The parser assigns each capability description listed above only one -// link collection. -// -// If a control is defined within a collection defined by -// delimited usages, then that control is said to be within multiple link -// collections, one for each usage within the open and close delimiter tokens. -// Such multiple link collecions are said to be aliases. The first N-1 such -// collections, listed in the link collection node array, have their IsAlias -// bit set. The last such link collection is the link collection index used -// in the capabilities described above. -// Clients wishing to set a control in an aliased collection, should walk the -// collection array once for each time they see the IsAlias flag set, and use -// the last link collection as the index for the below accessor functions. -// -// NB: if IsAlias is set, then NextSibling should be one more than the current -// link collection node index. -// - -typedef PUCHAR PHIDP_REPORT_DESCRIPTOR; -typedef struct _HIDP_PREPARSED_DATA * PHIDP_PREPARSED_DATA; - -typedef struct _HIDP_CAPS -{ - USAGE Usage; - USAGE UsagePage; - USHORT InputReportByteLength; - USHORT OutputReportByteLength; - USHORT FeatureReportByteLength; - USHORT Reserved[17]; - - USHORT NumberLinkCollectionNodes; - - USHORT NumberInputButtonCaps; - USHORT NumberInputValueCaps; - USHORT NumberInputDataIndices; - - USHORT NumberOutputButtonCaps; - USHORT NumberOutputValueCaps; - USHORT NumberOutputDataIndices; - - USHORT NumberFeatureButtonCaps; - USHORT NumberFeatureValueCaps; - USHORT NumberFeatureDataIndices; -} HIDP_CAPS, *PHIDP_CAPS; - -typedef struct _HIDP_DATA -{ - USHORT DataIndex; - USHORT Reserved; - union { - ULONG RawValue; // for values - BOOLEAN On; // for buttons MUST BE TRUE for buttons. - }; -} HIDP_DATA, *PHIDP_DATA; -// -// The HIDP_DATA structure is used with HidP_GetData and HidP_SetData -// functions. -// -// The parser contiguously assigns every control (button or value) in a hid -// device a unique data index from zero to NumberXXXDataIndices -1 , inclusive. -// This value is found in the HIDP_BUTTON_CAPS and HIDP_VALUE_CAPS structures. -// -// Most clients will find the Get/Set Buttons / Value accessor functions -// sufficient to their needs, as they will allow the clients to access the -// data known to them while ignoring the other controls. -// -// More complex clients, which actually read the Button / Value Caps, and which -// do a value add service to these routines (EG Direct Input), will need to -// access all the data in the device without interest in the individual usage -// or link collection location. These are the clients that will find -// HidP_Data useful. -// - -typedef struct _HIDP_UNKNOWN_TOKEN -{ - UCHAR Token; - UCHAR Reserved[3]; - ULONG BitField; -} HIDP_UNKNOWN_TOKEN, *PHIDP_UNKNOWN_TOKEN; - -typedef struct _HIDP_EXTENDED_ATTRIBUTES -{ - UCHAR NumGlobalUnknowns; - UCHAR Reserved [3]; - PHIDP_UNKNOWN_TOKEN GlobalUnknowns; - // ... Additional attributes - ULONG Data [1]; // variableLength DO NOT ACCESS THIS FIELD -} HIDP_EXTENDED_ATTRIBUTES, *PHIDP_EXTENDED_ATTRIBUTES; - -NTSTATUS __stdcall -HidP_GetCaps ( - IN PHIDP_PREPARSED_DATA PreparsedData, - OUT PHIDP_CAPS Capabilities - ); -/*++ -Routine Description: - Returns a list of capabilities of a given hid device as described by its - preparsed data. - -Arguments: - PreparsedData The preparsed data returned from HIDCLASS. - Capabilities a HIDP_CAPS structure - -Return Value: -· HIDP_STATUS_SUCCESS -· HIDP_STATUS_INVALID_PREPARSED_DATA ---*/ - -NTSTATUS __stdcall -HidP_GetLinkCollectionNodes ( - OUT PHIDP_LINK_COLLECTION_NODE LinkCollectionNodes, - IN OUT PULONG LinkCollectionNodesLength, - IN PHIDP_PREPARSED_DATA PreparsedData - ); -/*++ -Routine Description: - Return a list of PHIDP_LINK_COLLECTION_NODEs used to describe the link - collection tree of this hid device. See the above description of - struct _HIDP_LINK_COLLECTION_NODE. - -Arguments: - LinkCollectionNodes - a caller allocated array into which - HidP_GetLinkCollectionNodes will store the information - - LinKCollectionNodesLength - the caller sets this value to the length of the - the array in terms of number of elements. - HidP_GetLinkCollectionNodes sets this value to the actual - number of elements set. The total number of nodes required to - describe this HID device can be found in the - NumberLinkCollectionNodes field in the HIDP_CAPS structure. - ---*/ - -NTSTATUS __stdcall -HidP_GetButtonCaps ( - IN HIDP_REPORT_TYPE ReportType, - OUT PHIDP_BUTTON_CAPS ButtonCaps, - IN OUT PUSHORT ButtonCapsLength, - IN PHIDP_PREPARSED_DATA PreparsedData -); -#define HidP_GetButtonCaps(_Type_, _Caps_, _Len_, _Data_) \ - HidP_GetSpecificButtonCaps (_Type_, 0, 0, 0, _Caps_, _Len_, _Data_) -NTSTATUS __stdcall -HidP_GetSpecificButtonCaps ( - IN HIDP_REPORT_TYPE ReportType, - IN USAGE UsagePage, // Optional (0 => ignore) - IN USHORT LinkCollection, // Optional (0 => ignore) - IN USAGE Usage, // Optional (0 => ignore) - OUT PHIDP_BUTTON_CAPS ButtonCaps, - IN OUT PUSHORT ButtonCapsLength, - IN PHIDP_PREPARSED_DATA PreparsedData - ); -/*++ -Description: - HidP_GetButtonCaps returns all the buttons (binary values) that are a part - of the given report type for the Hid device represented by the given - preparsed data. - -Parameters: - ReportType One of HidP_Input, HidP_Output, or HidP_Feature. - - UsagePage A usage page value used to limit the button caps returned to - those on a given usage page. If set to 0, this parameter is - ignored. Can be used with LinkCollection and Usage parameters - to further limit the number of button caps structures returned. - - LinkCollection HIDP_LINK_COLLECTION node array index used to limit the - button caps returned to those buttons in a given link - collection. If set to 0, this parameter is - ignored. Can be used with UsagePage and Usage parameters - to further limit the number of button caps structures - returned. - - Usage A usage value used to limit the button caps returned to those - with the specified usage value. If set to 0, this parameter - is ignored. Can be used with LinkCollection and UsagePage - parameters to further limit the number of button caps - structures returned. - - ButtonCaps A _HIDP_BUTTON_CAPS array containing information about all the - binary values in the given report. This buffer is provided by - the caller. - - ButtonLength As input, this parameter specifies the length of the - ButtonCaps parameter (array) in number of array elements. - As output, this value is set to indicate how many of those - array elements were filled in by the function. The maximum number of - button caps that can be returned is found in the HIDP_CAPS - structure. If HIDP_STATUS_BUFFER_TOO_SMALL is returned, - this value contains the number of array elements needed to - successfully complete the request. - - PreparsedData The preparsed data returned from HIDCLASS. - - -Return Value -HidP_GetSpecificButtonCaps returns the following error codes: -· HIDP_STATUS_SUCCESS. -· HIDP_STATUS_INVALID_REPORT_TYPE -· HIDP_STATUS_INVALID_PREPARSED_DATA -· HIDP_STATUS_BUFFER_TOO_SMALL (all given entries however have been filled in) -· HIDP_STATUS_USAGE_NOT_FOUND ---*/ - -NTSTATUS __stdcall -HidP_GetValueCaps ( - IN HIDP_REPORT_TYPE ReportType, - OUT PHIDP_VALUE_CAPS ValueCaps, - IN OUT PUSHORT ValueCapsLength, - IN PHIDP_PREPARSED_DATA PreparsedData -); -#define HidP_GetValueCaps(_Type_, _Caps_, _Len_, _Data_) \ - HidP_GetSpecificValueCaps (_Type_, 0, 0, 0, _Caps_, _Len_, _Data_) -NTSTATUS __stdcall -HidP_GetSpecificValueCaps ( - IN HIDP_REPORT_TYPE ReportType, - IN USAGE UsagePage, // Optional (0 => ignore) - IN USHORT LinkCollection, // Optional (0 => ignore) - IN USAGE Usage, // Optional (0 => ignore) - OUT PHIDP_VALUE_CAPS ValueCaps, - IN OUT PUSHORT ValueCapsLength, - IN PHIDP_PREPARSED_DATA PreparsedData - ); -/*++ -Description: - HidP_GetValueCaps returns all the values (non-binary) that are a part - of the given report type for the Hid device represented by the given - preparsed data. - -Parameters: - ReportType One of HidP_Input, HidP_Output, or HidP_Feature. - - UsagePage A usage page value used to limit the value caps returned to - those on a given usage page. If set to 0, this parameter is - ignored. Can be used with LinkCollection and Usage parameters - to further limit the number of value caps structures returned. - - LinkCollection HIDP_LINK_COLLECTION node array index used to limit the - value caps returned to those buttons in a given link - collection. If set to 0, this parameter is - ignored. Can be used with UsagePage and Usage parameters - to further limit the number of value caps structures - returned. - - Usage A usage value used to limit the value caps returned to those - with the specified usage value. If set to 0, this parameter - is ignored. Can be used with LinkCollection and UsagePage - parameters to further limit the number of value caps - structures returned. - - ValueCaps A _HIDP_VALUE_CAPS array containing information about all the - non-binary values in the given report. This buffer is provided - by the caller. - - ValueLength As input, this parameter specifies the length of the ValueCaps - parameter (array) in number of array elements. As output, - this value is set to indicate how many of those array elements - were filled in by the function. The maximum number of - value caps that can be returned is found in the HIDP_CAPS - structure. If HIDP_STATUS_BUFFER_TOO_SMALL is returned, - this value contains the number of array elements needed to - successfully complete the request. - - PreparsedData The preparsed data returned from HIDCLASS. - - -Return Value -HidP_GetValueCaps returns the following error codes: -· HIDP_STATUS_SUCCESS. -· HIDP_STATUS_INVALID_REPORT_TYPE -· HIDP_STATUS_INVALID_PREPARSED_DATA -· HIDP_STATUS_BUFFER_TOO_SMALL (all given entries however have been filled in) -· HIDP_STATUS_USAGE_NOT_FOUND - ---*/ - -NTSTATUS __stdcall -HidP_GetExtendedAttributes ( - IN HIDP_REPORT_TYPE ReportType, - IN USHORT DataIndex, - IN PHIDP_PREPARSED_DATA PreparsedData, - OUT PHIDP_EXTENDED_ATTRIBUTES Attributes, - IN OUT PULONG LengthAttributes - ); -/*++ -Description: - Given a data index from the value or button capabilities of a given control - return any extended attributes for the control if any exist. - -Parameters: - ReportType One of HidP_Input, HidP_Output, or HidP_Feature. - - DataIndex The data index for the given control, found in the capabilities - structure for that control - - PreparsedData The preparsed data returned from HIDCLASS. - - Attributes Pointer to a buffer into which the extended attribute data will - be copied. - - LengthAttributes Length of the given buffer in bytes. - -Return Value - HIDP_STATUS_SUCCESS - HIDP_STATUS_DATA_INDEX_NOT_FOUND ---*/ - -NTSTATUS __stdcall -HidP_InitializeReportForID ( - IN HIDP_REPORT_TYPE ReportType, - IN UCHAR ReportID, - IN PHIDP_PREPARSED_DATA PreparsedData, - IN OUT PCHAR Report, - IN ULONG ReportLength - ); -/*++ - -Routine Description: - - Initialize a report based on the given report ID. - -Parameters: - - ReportType One of HidP_Input, HidP_Output, or HidP_Feature. - - PreparasedData Preparsed data structure returned by HIDCLASS - - Report Buffer which to set the data into. - - ReportLength Length of Report...Report should be at least as long as the - value indicated in the HIDP_CAPS structure for the device and - the corresponding ReportType - -Return Value - -· HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid. -· HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid -· HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not equal - to the length specified in HIDP_CAPS - structure for the given ReportType -· HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device - for the given ReportType - ---*/ - -NTSTATUS __stdcall -HidP_SetData ( - IN HIDP_REPORT_TYPE ReportType, - IN PHIDP_DATA DataList, - IN OUT PULONG DataLength, - IN PHIDP_PREPARSED_DATA PreparsedData, - IN OUT PCHAR Report, - IN ULONG ReportLength - ); -/*++ - -Routine Description: - - Please Note: Since usage value arrays deal with multiple fields for - for one usage value, they cannot be used with HidP_SetData - and HidP_GetData. In this case, - HIDP_STATUS_IS_USAGE_VALUE_ARRAY will be returned. - -Parameters: - - ReportType One of HidP_Input, HidP_Output, or HidP_Feature. - - DataList Array of HIDP_DATA structures that contains the data values - that are to be set into the given report - - DataLength As input, length in array elements of DataList. As output, - contains the number of data elements set on successful - completion or an index into the DataList array to identify - the faulting HIDP_DATA value if an error code is returned. - - PreparasedData Preparsed data structure returned by HIDCLASS - - Report Buffer which to set the data into. - - ReportLength Length of Report...Report should be at least as long as the - value indicated in the HIDP_CAPS structure for the device and - the corresponding ReportType - -Return Value - HidP_SetData returns the following error codes. The report packet will - have all the data set up until the HIDP_DATA structure that caused the - error. DataLength, in the error case, will return this problem index. - -· HIDP_STATUS_SUCCESS -- upon successful insertion of all data - into the report packet. -· HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid. -· HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid -· HIDP_STATUS_DATA_INDEX_NOT_FOUND -- if a HIDP_DATA structure referenced a - data index that does not exist for this - device's ReportType -· HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not equal - to the length specified in HIDP_CAPS - structure for the given ReportType -· HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device - for the given ReportType -· HIDP_STATUS_IS_USAGE_VALUE_ARRAY -- if one of the HIDP_DATA structures - references a usage value array. - DataLength will contain the index into - the array that was invalid -· HIDP_STATUS_BUTTON_NOT_PRESSED -- if a HIDP_DATA structure attempted - to unset a button that was not already - set in the Report -· HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- a HIDP_DATA structure was found with - a valid index value but is contained - in a different report than the one - currently being processed -· HIDP_STATUS_BUFFER_TOO_SMALL -- if there are not enough entries in - a given Main Array Item to report all - buttons that have been requested to be - set ---*/ - -NTSTATUS __stdcall -HidP_GetData ( - IN HIDP_REPORT_TYPE ReportType, - OUT PHIDP_DATA DataList, - IN OUT PULONG DataLength, - IN PHIDP_PREPARSED_DATA PreparsedData, - IN PCHAR Report, - IN ULONG ReportLength - ); -/*++ - -Routine Description: - - Please Note: For obvious reasons HidP_SetData and HidP_GetData will not - access UsageValueArrays. - -Parameters: - ReportType One of HidP_Input, HidP_Output, or HidP_Feature. - - DataList Array of HIDP_DATA structures that will receive the data - values that are set in the given report - - DataLength As input, length in array elements of DataList. As output, - contains the number of data elements that were successfully - set by HidP_GetData. The maximum size necessary for DataList - can be determined by calling HidP_MaxDataListLength - - PreparasedData Preparsed data structure returned by HIDCLASS - - Report Buffer which to set the data into. - - ReportLength Length of Report...Report should be at least as long as the - value indicated in the HIDP_CAPS structure for the device and - the corresponding ReportType - -Return Value - HidP_GetData returns the following error codes. - -· HIDP_STATUS_SUCCESS -- upon successful retrieval of all data - from the report packet. -· HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid. -· HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid -· HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not equal - to the length specified in HIDP_CAPS - structure for the given ReportType -· HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device - for the given ReportType -· HIDP_STATUS_BUFFER_TOO_SMALL -- if there are not enough array entries in - DataList to store all the indice values - in the given report. DataLength will - contain the number of array entries - required to hold all data ---*/ - -ULONG __stdcall -HidP_MaxDataListLength ( - IN HIDP_REPORT_TYPE ReportType, - IN PHIDP_PREPARSED_DATA PreparsedData - ); -/*++ -Routine Description: - - This function returns the maximum length of HIDP_DATA elements that - HidP_GetData could return for the given report type. - -Parameters: - - ReportType One of HidP_Input, HidP_Output or HidP_Feature. - - PreparsedData Preparsed data structure returned by HIDCLASS - -Return Value: - - The length of the data list array required for the HidP_GetData function - call. If an error occurs (either HIDP_STATUS_INVALID_REPORT_TYPE or - HIDP_STATUS_INVALID_PREPARSED_DATA), this function returns 0. - ---*/ - -#define HidP_SetButtons(Rty, Up, Lco, ULi, ULe, Ppd, Rep, Rle) \ - HidP_SetUsages(Rty, Up, Lco, ULi, ULe, Ppd, Rep, Rle) - -NTSTATUS __stdcall -HidP_SetUsages ( - IN HIDP_REPORT_TYPE ReportType, - IN USAGE UsagePage, - IN USHORT LinkCollection, // Optional - IN PUSAGE UsageList, - IN OUT PULONG UsageLength, - IN PHIDP_PREPARSED_DATA PreparsedData, - IN OUT PCHAR Report, - IN ULONG ReportLength - ); -/*++ - -Routine Description: - This function sets binary values (buttons) in a report. Given an - initialized packet of correct length, it modifies the report packet so that - each element in the given list of usages has been set in the report packet. - For example, in an output report with 5 LED’s, each with a given usage, - an application could turn on any subset of these lights by placing their - usages in any order into the usage array (UsageList). HidP_SetUsages would, - in turn, set the appropriate bit or add the corresponding byte into the - HID Main Array Item. - - A properly initialized Report packet is one of the correct byte length, - and all zeros. - - NOTE: A packet that has already been set with a call to a HidP_Set routine - can also be passed in. This routine then sets processes the UsageList - in the same fashion but verifies that the ReportID already set in - Report matches the report ID for the given usages. - -Parameters: - ReportType One of HidP_Input, HidP_Output or HidP_Feature. - - UsagePage All of the usages in the usage array, which HidP_SetUsages will - set in the report, refer to this same usage page. - If a client wishes to set usages in a report for multiple - usage pages then that client needs to make multiple calls to - HidP_SetUsages for each of the usage pages. - - UsageList A usage array containing the usages that HidP_SetUsages will set in - the report packet. - - UsageLength The length of the given usage array in array elements. - The parser will set this value to the position in the usage - array where it stopped processing. If successful, UsageLength - will be unchanged. In any error condition, this parameter - reflects how many of the usages in the usage list have - actually been set by the parser. This is useful for finding - the usage in the list which caused the error. - - PreparsedData The preparsed data recevied from HIDCLASS - - Report The report packet. - - ReportLength Length of the given report packet...Must be equal to the - value reported in the HIDP_CAPS structure for the device - and corresponding report type. - -Return Value - HidP_SetUsages returns the following error codes. On error, the report packet - will be correct up until the usage element that caused the error. - -· HIDP_STATUS_SUCCESS -- upon successful insertion of all usages - into the report packet. -· HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid. -· HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid -· HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not - equal to the length specified in - the HIDP_CAPS structure for the given - ReportType -· HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device - for the given ReportType -· HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- if a usage was found that exists in a - different report. If the report is - zero-initialized on entry the first - usage in the list will determine which - report ID is used. Otherwise, the - parser will verify that usage matches - the passed in report's ID -· HIDP_STATUS_USAGE_NOT_FOUND -- if the usage does not exist for any - report (no matter what the report ID) - for the given report type. -· HIDP_STATUS_BUFFER_TOO_SMALL -- if there are not enough entries in a - given Main Array Item to list all of - the given usages. The caller needs - to split his request into more than - one call ---*/ - -#define HidP_UnsetButtons(Rty, Up, Lco, ULi, ULe, Ppd, Rep, Rle) \ - HidP_UnsetUsages(Rty, Up, Lco, ULi, ULe, Ppd, Rep, Rle) - -NTSTATUS __stdcall -HidP_UnsetUsages ( - IN HIDP_REPORT_TYPE ReportType, - IN USAGE UsagePage, - IN USHORT LinkCollection, // Optional - IN PUSAGE UsageList, - IN OUT PULONG UsageLength, - IN PHIDP_PREPARSED_DATA PreparsedData, - IN OUT PCHAR Report, - IN ULONG ReportLength - ); -/*++ - -Routine Description: - This function unsets (turns off) binary values (buttons) in the report. Given - an initialized packet of correct length, it modifies the report packet so - that each element in the given list of usages has been unset in the - report packet. - - This function is the "undo" operation for SetUsages. If the given usage - is not already set in the Report, it will return an error code of - HIDP_STATUS_BUTTON_NOT_PRESSED. If the button is pressed, HidP_UnsetUsages - will unset the appropriate bit or remove the corresponding index value from - the HID Main Array Item. - - A properly initialized Report packet is one of the correct byte length, - and all zeros.. - - NOTE: A packet that has already been set with a call to a HidP_Set routine - can also be passed in. This routine then processes the UsageList - in the same fashion but verifies that the ReportID already set in - Report matches the report ID for the given usages. - -Parameters: - ReportType One of HidP_Input, HidP_Output or HidP_Feature. - - UsagePage All of the usages in the usage array, which HidP_UnsetUsages will - unset in the report, refer to this same usage page. - If a client wishes to unset usages in a report for multiple - usage pages then that client needs to make multiple calls to - HidP_UnsetUsages for each of the usage pages. - - UsageList A usage array containing the usages that HidP_UnsetUsages will - unset in the report packet. - - UsageLength The length of the given usage array in array elements. - The parser will set this value to the position in the usage - array where it stopped processing. If successful, UsageLength - will be unchanged. In any error condition, this parameter - reflects how many of the usages in the usage list have - actually been unset by the parser. This is useful for finding - the usage in the list which caused the error. - - PreparsedData The preparsed data recevied from HIDCLASS - - Report The report packet. - - ReportLength Length of the given report packet...Must be equal to the - value reported in the HIDP_CAPS structure for the device - and corresponding report type. - -Return Value - HidP_UnsetUsages returns the following error codes. On error, the report - packet will be correct up until the usage element that caused the error. - -· HIDP_STATUS_SUCCESS -- upon successful "unsetting" of all usages - in the report packet. -· HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid. -· HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid -· HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not - equal to the length specified in - the HIDP_CAPS structure for the given - ReportType -· HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device - for the given ReportType -· HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- if a usage was found that exists in a - different report. If the report is - zero-initialized on entry the first - usage in the list will determine which - report ID is used. Otherwise, the - parser will verify that usage matches - the passed in report's ID -· HIDP_STATUS_USAGE_NOT_FOUND -- if the usage does not exist for any - report (no matter what the report ID) - for the given report type. -· HIDP_STATUS_BUTTON_NOT_PRESSED -- if a usage corresponds to a button that - is not already set in the given report ---*/ - -#define HidP_GetButtons(Rty, UPa, LCo, ULi, ULe, Ppd, Rep, RLe) \ - HidP_GetUsages(Rty, UPa, LCo, ULi, ULe, Ppd, Rep, RLe) - -NTSTATUS __stdcall -HidP_GetUsages ( - IN HIDP_REPORT_TYPE ReportType, - IN USAGE UsagePage, - IN USHORT LinkCollection, // Optional - OUT USAGE * UsageList, - IN OUT ULONG * UsageLength, - IN PHIDP_PREPARSED_DATA PreparsedData, - IN PCHAR Report, - IN ULONG ReportLength - ); -/*++ - -Routine Description: - This function returns the binary values (buttons) that are set in a HID - report. Given a report packet of correct length, it searches the report - packet for each usage for the given usage page and returns them in the - usage list. - -Parameters: - ReportType One of HidP_Input, HidP_Output or HidP_Feature. - - UsagePage All of the usages in the usage list, which HidP_GetUsages will - retrieve in the report, refer to this same usage page. - If the client wishes to get usages in a packet for multiple - usage pages then that client needs to make multiple calls - to HidP_GetUsages. - - LinkCollection An optional value which can limit which usages are returned - in the UsageList to those usages that exist in a specific - LinkCollection. A non-zero value indicates the index into - the HIDP_LINK_COLLECITON_NODE list returned by - HidP_GetLinkCollectionNodes of the link collection the - usage should belong to. A value of 0 indicates this - should value be ignored. - - UsageList The usage array that will contain all the usages found in - the report packet. - - UsageLength The length of the given usage array in array elements. - On input, this value describes the length of the usage list. - On output, HidP_GetUsages sets this value to the number of - usages that was found. Use HidP_MaxUsageListLength to - determine the maximum length needed to return all the usages - that a given report packet may contain. - - PreparsedData Preparsed data structure returned by HIDCLASS - - Report The report packet. - - ReportLength Length (in bytes) of the given report packet - - -Return Value - HidP_GetUsages returns the following error codes: - -· HIDP_STATUS_SUCCESS -- upon successfully retrieving all the - usages from the report packet -· HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid. -· HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid -· HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not - equal to the length specified in - the HIDP_CAPS structure for the given - ReportType -· HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device - for the given ReportType -· HIDP_STATUS_BUFFER_TOO_SMALL -- if the UsageList is not big enough to - hold all the usages found in the report - packet. If this is returned, the buffer - will contain UsageLength number of - usages. Use HidP_MaxUsageListLength to - find the maximum length needed -· HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- if no usages were found but usages - that match the UsagePage and - LinkCollection specified could be found - in a report with a different report ID -· HIDP_STATUS_USAGE_NOT_FOUND -- if there are no usages in a reports for - the device and ReportType that match the - UsagePage and LinkCollection that were - specified ---*/ - -#define HidP_GetButtonsEx(Rty, LCo, BLi, ULe, Ppd, Rep, RLe) \ - HidP_GetUsagesEx(Rty, LCo, BLi, ULe, Ppd, Rep, RLe) - -NTSTATUS __stdcall -HidP_GetUsagesEx ( - IN HIDP_REPORT_TYPE ReportType, - IN USHORT LinkCollection, // Optional - OUT PUSAGE_AND_PAGE ButtonList, - IN OUT ULONG * UsageLength, - IN PHIDP_PREPARSED_DATA PreparsedData, - IN PCHAR Report, - IN ULONG ReportLength - ); - -/*++ - -Routine Description: - This function returns the binary values (buttons) in a HID report. - Given a report packet of correct length, it searches the report packet - for all buttons and returns the UsagePage and Usage for each of the buttons - it finds. - -Parameters: - ReportType One of HidP_Input, HidP_Output or HidP_Feature. - - LinkCollection An optional value which can limit which usages are returned - in the ButtonList to those usages that exist in a specific - LinkCollection. A non-zero value indicates the index into - the HIDP_LINK_COLLECITON_NODE list returned by - HidP_GetLinkCollectionNodes of the link collection the - usage should belong to. A value of 0 indicates this - should value be ignored. - - ButtonList An array of USAGE_AND_PAGE structures describing all the - buttons currently ``down'' in the device. - - UsageLength The length of the given array in terms of elements. - On input, this value describes the length of the list. On - output, HidP_GetUsagesEx sets this value to the number of - usages that were found. Use HidP_MaxUsageListLength to - determine the maximum length needed to return all the usages - that a given report packet may contain. - - PreparsedData Preparsed data returned by HIDCLASS - - Report The report packet. - - ReportLength Length (in bytes) of the given report packet. - - -Return Value - HidP_GetUsagesEx returns the following error codes: - -· HIDP_STATUS_SUCCESS -- upon successfully retrieving all the - usages from the report packet -· HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid. -· HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid -· HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not - equal to the length specified in - the HIDP_CAPS structure for the given - ReportType -· HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device - for the given ReportType -· HIDP_STATUS_BUFFER_TOO_SMALL -- if ButtonList is not big enough to - hold all the usages found in the report - packet. If this is returned, the buffer - will contain UsageLength number of - usages. Use HidP_MaxUsageListLength to - find the maximum length needed -· HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- if no usages were found but usages - that match the specified LinkCollection - exist in report with a different report - ID. -· HIDP_STATUS_USAGE_NOT_FOUND -- if there are no usages in any reports that - match the LinkCollection parameter ---*/ - -#define HidP_GetButtonListLength(RTy, UPa, Ppd) \ - HidP_GetUsageListLength(Rty, UPa, Ppd) - -ULONG __stdcall -HidP_MaxUsageListLength ( - IN HIDP_REPORT_TYPE ReportType, - IN USAGE UsagePage, // Optional - IN PHIDP_PREPARSED_DATA PreparsedData - ); -/*++ -Routine Description: - This function returns the maximum number of usages that a call to - HidP_GetUsages or HidP_GetUsagesEx could return for a given HID report. - If calling for number of usages returned by HidP_GetUsagesEx, use 0 as - the UsagePage value. - -Parameters: - ReportType One of HidP_Input, HidP_Output or HidP_Feature. - - UsagePage Specifies the optional UsagePage to query for. If 0, will - return all the maximum number of usage values that could be - returned for a given ReportType. If non-zero, will return - the maximum number of usages that would be returned for the - ReportType with the given UsagePage. - - PreparsedData Preparsed data returned from HIDCLASS - -Return Value: - The length of the usage list array required for the HidP_GetUsages or - HidP_GetUsagesEx function call. If an error occurs (such as - HIDP_STATUS_INVALID_REPORT_TYPE or HIDP_INVALID_PREPARSED_DATA, this - returns 0. ---*/ - -NTSTATUS __stdcall -HidP_SetUsageValue ( - IN HIDP_REPORT_TYPE ReportType, - IN USAGE UsagePage, - IN USHORT LinkCollection, // Optional - IN USAGE Usage, - IN ULONG UsageValue, - IN PHIDP_PREPARSED_DATA PreparsedData, - IN OUT PCHAR Report, - IN ULONG ReportLength - ); -/*++ -Description: - HidP_SetUsageValue inserts a value into the HID Report Packet in the field - corresponding to the given usage page and usage. HidP_SetUsageValue - casts this value to the appropriate bit length. If a report packet - contains two different fields with the same Usage and UsagePage, - they can be distinguished with the optional LinkCollection field value. - Using this function sets the raw value into the report packet with - no checking done as to whether it actually falls within the logical - minimum/logical maximum range. Use HidP_SetScaledUsageValue for this... - - NOTE: Although the UsageValue parameter is a ULONG, any casting that is - done will preserve or sign-extend the value. The value being set - should be considered a LONG value and will be treated as such by - this function. - -Parameters: - - ReportType One of HidP_Output or HidP_Feature. - - UsagePage The usage page to which the given usage refers. - - LinkCollection (Optional) This value can be used to differentiate - between two fields that may have the same - UsagePage and Usage but exist in different - collections. If the link collection value - is zero, this function will set the first field - it finds that matches the usage page and - usage. - - Usage The usage whose value HidP_SetUsageValue will set. - - UsageValue The raw value to set in the report buffer. This value must be within - the logical range or if a NULL value this value should be the - most negative value that can be represented by the number of bits - for this field. - - PreparsedData The preparsed data returned for HIDCLASS - - Report The report packet. - - ReportLength Length (in bytes) of the given report packet. - - -Return Value: - HidP_SetUsageValue returns the following error codes: - -· HIDP_STATUS_SUCCESS -- upon successfully setting the value - in the report packet -· HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid. -· HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid -· HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not - equal to the length specified in - the HIDP_CAPS structure for the given - ReportType -· HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device - for the given ReportType -· HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- the specified usage page, usage and - link collection exist but exists in - a report with a different report ID - than the report being passed in. To - set this value, call HidP_SetUsageValue - again with a zero-initizialed report - packet -· HIDP_STATUS_USAGE_NOT_FOUND -- if the usage page, usage, and link - collection combination does not exist - in any reports for this ReportType ---*/ - -NTSTATUS __stdcall -HidP_SetScaledUsageValue ( - IN HIDP_REPORT_TYPE ReportType, - IN USAGE UsagePage, - IN USHORT LinkCollection, // Optional - IN USAGE Usage, - IN LONG UsageValue, - IN PHIDP_PREPARSED_DATA PreparsedData, - IN OUT PCHAR Report, - IN ULONG ReportLength - ); - -/*++ -Description: - HidP_SetScaledUsageValue inserts the UsageValue into the HID report packet - in the field corresponding to the given usage page and usage. If a report - packet contains two different fields with the same Usage and UsagePage, - they can be distinguished with the optional LinkCollection field value. - - If the specified field has a defined physical range, this function converts - the physical value specified to the corresponding logical value for the - report. If a physical value does not exist, the function will verify that - the value specified falls within the logical range and set according. - - If the range checking fails but the field has NULL values, the function will - set the field to the defined NULL value (most negative number possible) and - return HIDP_STATUS_NULL. In other words, use this function to set NULL - values for a given field by passing in a value that falls outside the - physical range if it is defined or the logical range otherwise. - - If the field does not support NULL values, an out of range error will be - returned instead. - -Parameters: - - ReportType One of HidP_Output or HidP_Feature. - - UsagePage The usage page to which the given usage refers. - - LinkCollection (Optional) This value can be used to differentiate - between two fields that may have the same - UsagePage and Usage but exist in different - collections. If the link collection value - is zero, this function will set the first field - it finds that matches the usage page and - usage. - - Usage The usage whose value HidP_SetScaledUsageValue will set. - - UsageValue The value to set in the report buffer. See the routine - description above for the different interpretations of this - value - - PreparsedData The preparsed data returned from HIDCLASS - - Report The report packet. - - ReportLength Length (in bytes) of the given report packet. - - -Return Value: - HidP_SetScaledUsageValue returns the following error codes: - -· HIDP_STATUS_SUCCESS -- upon successfully setting the value - in the report packet -· HIDP_STATUS_NULL -- upon successfully setting the value - in the report packet as a NULL value -· HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid. -· HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid -· HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not - equal to the length specified in - the HIDP_CAPS structure for the given - ReportType -· HIDP_STATUS_VALUE_OUT_OF_RANGE -- if the value specified failed to fall - within the physical range if it exists - or within the logical range otherwise - and the field specified by the usage - does not allow NULL values -· HIDP_STATUS_BAD_LOG_PHY_VALUES -- if the field has a physical range but - either the logical range is invalid - (max <= min) or the physical range is - invalid -· HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- the specified usage page, usage and - link collection exist but exists in - a report with a different report ID - than the report being passed in. To - set this value, call - HidP_SetScaledUsageValue again with - a zero-initialized report packet -· HIDP_STATUS_USAGE_NOT_FOUND -- if the usage page, usage, and link - collection combination does not exist - in any reports for this ReportType ---*/ - -NTSTATUS __stdcall -HidP_SetUsageValueArray ( - IN HIDP_REPORT_TYPE ReportType, - IN USAGE UsagePage, - IN USHORT LinkCollection, // Optional - IN USAGE Usage, - IN PCHAR UsageValue, - IN USHORT UsageValueByteLength, - IN PHIDP_PREPARSED_DATA PreparsedData, - OUT PCHAR Report, - IN ULONG ReportLength - ); - -/*++ -Routine Descripton: - A usage value array occurs when the last usage in the list of usages - describing a main item must be repeated because there are less usages defined - than there are report counts declared for the given main item. In this case - a single value cap is allocated for that usage and the report count of that - value cap is set to reflect the number of fields to which that usage refers. - - HidP_SetUsageValueArray sets the raw bits for that usage which spans - more than one field in a report. - - NOTE: This function currently does not support value arrays where the - ReportSize for each of the fields in the array is not a multiple - of 8 bits. - - The UsageValue buffer should have the values set as they would appear - in the report buffer. If this function supported non 8-bit multiples - for the ReportSize then caller should format the input buffer so that - each new value begins at the bit immediately following the last bit - of the previous value - -Parameters: - - ReportType One of HidP_Output or HidP_Feature. - - UsagePage The usage page to which the given usage refers. - - LinkCollection (Optional) This value can be used to differentiate - between two fields that may have the same - UsagePage and Usage but exist in different - collections. If the link collection value - is zero, this function will set the first field - it finds that matches the usage page and - usage. - - Usage The usage whose value array HidP_SetUsageValueArray will set. - - UsageValue The buffer with the values to set into the value array. - The number of BITS required is found by multiplying the - BitSize and ReportCount fields of the Value Cap for this - control. The least significant bit of this control found in the - given report will be placed in the least significan bit location - of the array given (little-endian format), regardless of whether - or not the field is byte alligned or if the BitSize is a multiple - of sizeof (CHAR). - - See the above note for current implementation limitations. - - UsageValueByteLength Length of the UsageValue buffer (in bytes) - - PreparsedData The preparsed data returned from HIDCLASS - - Report The report packet. - - ReportLength Length (in bytes) of the given report packet. - - -Return Value: -· HIDP_STATUS_SUCCESS -- upon successfully setting the value - array in the report packet -· HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid. -· HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid -· HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not - equal to the length specified in - the HIDP_CAPS structure for the given - ReportType -· HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device - for the given ReportType -· HIDP_STATUS_NOT_VALUE_ARRAY -- if the control specified is not a - value array -- a value array will have - a ReportCount field in the - HIDP_VALUE_CAPS structure that is > 1 - Use HidP_SetUsageValue instead -· HIDP_STATUS_BUFFER_TOO_SMALL -- if the size of the passed in buffer with - the values to set is too small (ie. has - fewer values than the number of fields in - the array -· HIDP_STATUS_NOT_IMPLEMENTED -- if the usage value array has field sizes - that are not multiples of 8 bits, this - error code is returned since the function - currently does not handle setting into - such arrays. -· HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- the specified usage page, usage and - link collection exist but exists in - a report with a different report ID - than the report being passed in. To - set this value, call - HidP_SetUsageValueArray again with - a zero-initialized report packet -· HIDP_STATUS_USAGE_NOT_FOUND -- if the usage page, usage, and link - collection combination does not exist - in any reports for this ReportType ---*/ - - -NTSTATUS __stdcall -HidP_GetUsageValue ( - IN HIDP_REPORT_TYPE ReportType, - IN USAGE UsagePage, - IN USHORT LinkCollection, // Optional - IN USAGE Usage, - OUT PULONG UsageValue, - IN PHIDP_PREPARSED_DATA PreparsedData, - IN PCHAR Report, - IN ULONG ReportLength - ); - -/* -Description - HidP_GetUsageValue retrieves the value from the HID Report for the usage - specified by the combination of usage page, usage and link collection. - If a report packet contains two different fields with the same - Usage and UsagePage, they can be distinguished with the optional - LinkCollection field value. - -Parameters: - - ReportType One of HidP_Input or HidP_Feature. - - UsagePage The usage page to which the given usage refers. - - LinkCollection (Optional) This value can be used to differentiate - between two fields that may have the same - UsagePage and Usage but exist in different - collections. If the link collection value - is zero, this function will set the first field - it finds that matches the usage page and - usage. - - Usage The usage whose value HidP_GetUsageValue will retrieve - - UsageValue The raw value that is set for the specified field in the report - buffer. This value will either fall within the logical range - or if NULL values are allowed, a number outside the range to - indicate a NULL - - PreparsedData The preparsed data returned for HIDCLASS - - Report The report packet. - - ReportLength Length (in bytes) of the given report packet. - - -Return Value: - HidP_GetUsageValue returns the following error codes: - -· HIDP_STATUS_SUCCESS -- upon successfully retrieving the value - from the report packet -· HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid. -· HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid -· HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not - equal to the length specified in - the HIDP_CAPS structure for the given - ReportType -· HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device - for the given ReportType -· HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- the specified usage page, usage and - link collection exist but exists in - a report with a different report ID - than the report being passed in. To - set this value, call HidP_GetUsageValue - again with a different report packet -· HIDP_STATUS_USAGE_NOT_FOUND -- if the usage page, usage, and link - collection combination does not exist - in any reports for this ReportType ---*/ - - -NTSTATUS __stdcall -HidP_GetScaledUsageValue ( - IN HIDP_REPORT_TYPE ReportType, - IN USAGE UsagePage, - IN USHORT LinkCollection, // Optional - IN USAGE Usage, - OUT PLONG UsageValue, - IN PHIDP_PREPARSED_DATA PreparsedData, - IN PCHAR Report, - IN ULONG ReportLength - ); - -/*++ -Description - HidP_GetScaledUsageValue retrieves a UsageValue from the HID report packet - in the field corresponding to the given usage page and usage. If a report - packet contains two different fields with the same Usage and UsagePage, - they can be distinguished with the optional LinkCollection field value. - - If the specified field has a defined physical range, this function converts - the logical value that exists in the report packet to the corresponding - physical value. If a physical range does not exist, the function will - return the logical value. This function will check to verify that the - logical value in the report falls within the declared logical range. - - When doing the conversion between logical and physical values, this - function assumes a linear extrapolation between the physical max/min and - the logical max/min. (Where logical is the values reported by the device - and physical is the value returned by this function). If the data field - size is less than 32 bits, then HidP_GetScaledUsageValue will sign extend - the value to 32 bits. - - If the range checking fails but the field has NULL values, the function - will set UsageValue to 0 and return HIDP_STATUS_NULL. Otherwise, it - returns a HIDP_STATUS_OUT_OF_RANGE error. - -Parameters: - - ReportType One of HidP_Output or HidP_Feature. - - UsagePage The usage page to which the given usage refers. - - LinkCollection (Optional) This value can be used to differentiate - between two fields that may have the same - UsagePage and Usage but exist in different - collections. If the link collection value - is zero, this function will retrieve the first - field it finds that matches the usage page - and usage. - - Usage The usage whose value HidP_GetScaledUsageValue will retrieve - - UsageValue The value retrieved from the report buffer. See the routine - description above for the different interpretations of this - value - - PreparsedData The preparsed data returned from HIDCLASS - - Report The report packet. - - ReportLength Length (in bytes) of the given report packet. - - -Return Value: - HidP_GetScaledUsageValue returns the following error codes: - -· HIDP_STATUS_SUCCESS -- upon successfully retrieving the value - from the report packet -· HIDP_STATUS_NULL -- if the report packet had a NULL value - set -· HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid. -· HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid -· HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not - equal to the length specified in - the HIDP_CAPS structure for the given - ReportType -· HIDP_STATUS_VALUE_OUT_OF_RANGE -- if the value retrieved from the packet - falls outside the logical range and - the field does not support NULL values -· HIDP_STATUS_BAD_LOG_PHY_VALUES -- if the field has a physical range but - either the logical range is invalid - (max <= min) or the physical range is - invalid -· HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- the specified usage page, usage and - link collection exist but exists in - a report with a different report ID - than the report being passed in. To - set this value, call - HidP_GetScaledUsageValue with a - different report packet -· HIDP_STATUS_USAGE_NOT_FOUND -- if the usage page, usage, and link - collection combination does not exist - in any reports for this ReportType ---*/ - -NTSTATUS __stdcall -HidP_GetUsageValueArray ( - IN HIDP_REPORT_TYPE ReportType, - IN USAGE UsagePage, - IN USHORT LinkCollection, // Optional - IN USAGE Usage, - OUT PCHAR UsageValue, - IN USHORT UsageValueByteLength, - IN PHIDP_PREPARSED_DATA PreparsedData, - IN PCHAR Report, - IN ULONG ReportLength - ); - -/*++ -Routine Descripton: - A usage value array occurs when the last usage in the list of usages - describing a main item must be repeated because there are less usages defined - than there are report counts declared for the given main item. In this case - a single value cap is allocated for that usage and the report count of that - value cap is set to reflect the number of fields to which that usage refers. - - HidP_GetUsageValueArray returns the raw bits for that usage which spans - more than one field in a report. - - NOTE: This function currently does not support value arrays where the - ReportSize for each of the fields in the array is not a multiple - of 8 bits. - - The UsageValue buffer will have the raw values as they are set - in the report packet. - -Parameters: - - ReportType One of HidP_Input, HidP_Output or HidP_Feature. - - UsagePage The usage page to which the given usage refers. - - LinkCollection (Optional) This value can be used to differentiate - between two fields that may have the same - UsagePage and Usage but exist in different - collections. If the link collection value - is zero, this function will set the first field - it finds that matches the usage page and - usage. - - Usage The usage whose value HidP_GetUsageValueArray will retreive. - - UsageValue A pointer to an array of characters where the value will be - placed. The number of BITS required is found by multiplying the - BitSize and ReportCount fields of the Value Cap for this - control. The least significant bit of this control found in the - given report will be placed in the least significant bit location - of the buffer (little-endian format), regardless of whether - or not the field is byte aligned or if the BitSize is a multiple - of sizeof (CHAR). - - See note above about current implementation limitations - - UsageValueByteLength - the length of the given UsageValue buffer. - - PreparsedData The preparsed data returned by the HIDCLASS - - Report The report packet. - - ReportLength Length of the given report packet. - -Return Value: - -· HIDP_STATUS_SUCCESS -- upon successfully retrieving the value - from the report packet -· HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid. -· HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid -· HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not - equal to the length specified in - the HIDP_CAPS structure for the given - ReportType -· HIDP_STATUS_NOT_VALUE_ARRAY -- if the control specified is not a - value array -- a value array will have - a ReportCount field in the - HIDP_VALUE_CAPS structure that is > 1 - Use HidP_GetUsageValue instead -· HIDP_STATUS_BUFFER_TOO_SMALL -- if the size of the passed in buffer in - which to return the array is too small - (ie. has fewer values than the number of - fields in the array -· HIDP_STATUS_NOT_IMPLEMENTED -- if the usage value array has field sizes - that are not multiples of 8 bits, this - error code is returned since the function - currently does not handle getting values - from such arrays. -· HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- the specified usage page, usage and - link collection exist but exists in - a report with a different report ID - than the report being passed in. To - set this value, call - HidP_GetUsageValueArray with a - different report packet -· HIDP_STATUS_USAGE_NOT_FOUND -- if the usage page, usage, and link - collection combination does not exist - in any reports for this ReportType ---*/ - -NTSTATUS __stdcall -HidP_UsageListDifference ( - IN PUSAGE PreviousUsageList, - IN PUSAGE CurrentUsageList, - OUT PUSAGE BreakUsageList, - OUT PUSAGE MakeUsageList, - IN ULONG UsageListLength - ); -/*++ -Routine Description: - This function will return the difference between a two lists of usages - (as might be returned from HidP_GetUsages), In other words, it will return - return a list of usages that are in the current list but not the previous - list as well as a list of usages that are in the previous list but not - the current list. - -Parameters: - - PreviousUsageList The list of usages before. - CurrentUsageList The list of usages now. - BreakUsageList Previous - Current. - MakeUsageList Current - Previous. - UsageListLength Represents the length of the usage lists in array - elements. If comparing two lists with a differing - number of array elements, this value should be - the size of the larger of the two lists. Any - zero found with a list indicates an early termination - of the list and any usages found after the first zero - will be ignored. ---*/ - -NTSTATUS __stdcall -HidP_UsageAndPageListDifference ( - IN PUSAGE_AND_PAGE PreviousUsageList, - IN PUSAGE_AND_PAGE CurrentUsageList, - OUT PUSAGE_AND_PAGE BreakUsageList, - OUT PUSAGE_AND_PAGE MakeUsageList, - IN ULONG UsageListLength - ); - -// -// Produce Make or Break Codes -// -typedef enum _HIDP_KEYBOARD_DIRECTION { - HidP_Keyboard_Break, - HidP_Keyboard_Make -} HIDP_KEYBOARD_DIRECTION; - -// -// A bitmap of the current shift state of the keyboard when using the -// below keyboard usages to i8042 translation function. -// -typedef struct _HIDP_KEYBOARD_MODIFIER_STATE { - union { - struct { - ULONG LeftControl: 1; - ULONG LeftShift: 1; - ULONG LeftAlt: 1; - ULONG LeftGUI: 1; - ULONG RightControl: 1; - ULONG RightShift: 1; - ULONG RightAlt: 1; - ULONG RigthGUI: 1; - ULONG CapsLock: 1; - ULONG ScollLock: 1; - ULONG NumLock: 1; - ULONG Reserved: 21; - }; - ULONG ul; - }; - -} HIDP_KEYBOARD_MODIFIER_STATE, * PHIDP_KEYBOARD_MODIFIER_STATE; - -// -// A call back function to give the i8042 scan codes to the caller of -// the below translation function. -// -typedef BOOLEAN (* PHIDP_INSERT_SCANCODES) ( - IN PVOID Context, // Some caller supplied context. - IN PCHAR NewScanCodes, // A list of i8042 scan codes. - IN ULONG Length // the length of the scan codes. - ); - -NTSTATUS __stdcall -HidP_TranslateUsageAndPagesToI8042ScanCodes ( - IN PUSAGE_AND_PAGE ChangedUsageList, - IN ULONG UsageListLength, - IN HIDP_KEYBOARD_DIRECTION KeyAction, - IN OUT PHIDP_KEYBOARD_MODIFIER_STATE ModifierState, - IN PHIDP_INSERT_SCANCODES InsertCodesProcedure, - IN PVOID InsertCodesContext - ); -/*++ -Routine Description: -Parameters: ---*/ - -NTSTATUS __stdcall -HidP_TranslateUsagesToI8042ScanCodes ( - IN PUSAGE ChangedUsageList, - IN ULONG UsageListLength, - IN HIDP_KEYBOARD_DIRECTION KeyAction, - IN OUT PHIDP_KEYBOARD_MODIFIER_STATE ModifierState, - IN PHIDP_INSERT_SCANCODES InsertCodesProcedure, - IN PVOID InsertCodesContext - ); -/*++ -Routine Description: -Parameters: ---*/ - - - -// -// Define NT Status codes with Facility Code of FACILITY_HID_ERROR_CODE -// - -// FACILITY_HID_ERROR_CODE defined in ntstatus.h -#ifndef FACILITY_HID_ERROR_CODE -#define FACILITY_HID_ERROR_CODE 0x11 -#endif - -#define HIDP_ERROR_CODES(SEV, CODE) \ - ((NTSTATUS) (((SEV) << 28) | (FACILITY_HID_ERROR_CODE << 16) | (CODE))) - -#define HIDP_STATUS_SUCCESS (HIDP_ERROR_CODES(0x0,0)) -#define HIDP_STATUS_NULL (HIDP_ERROR_CODES(0x8,1)) -#define HIDP_STATUS_INVALID_PREPARSED_DATA (HIDP_ERROR_CODES(0xC,1)) -#define HIDP_STATUS_INVALID_REPORT_TYPE (HIDP_ERROR_CODES(0xC,2)) -#define HIDP_STATUS_INVALID_REPORT_LENGTH (HIDP_ERROR_CODES(0xC,3)) -#define HIDP_STATUS_USAGE_NOT_FOUND (HIDP_ERROR_CODES(0xC,4)) -#define HIDP_STATUS_VALUE_OUT_OF_RANGE (HIDP_ERROR_CODES(0xC,5)) -#define HIDP_STATUS_BAD_LOG_PHY_VALUES (HIDP_ERROR_CODES(0xC,6)) -#define HIDP_STATUS_BUFFER_TOO_SMALL (HIDP_ERROR_CODES(0xC,7)) -#define HIDP_STATUS_INTERNAL_ERROR (HIDP_ERROR_CODES(0xC,8)) -#define HIDP_STATUS_I8042_TRANS_UNKNOWN (HIDP_ERROR_CODES(0xC,9)) -#define HIDP_STATUS_INCOMPATIBLE_REPORT_ID (HIDP_ERROR_CODES(0xC,0xA)) -#define HIDP_STATUS_NOT_VALUE_ARRAY (HIDP_ERROR_CODES(0xC,0xB)) -#define HIDP_STATUS_IS_VALUE_ARRAY (HIDP_ERROR_CODES(0xC,0xC)) -#define HIDP_STATUS_DATA_INDEX_NOT_FOUND (HIDP_ERROR_CODES(0xC,0xD)) -#define HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE (HIDP_ERROR_CODES(0xC,0xE)) -#define HIDP_STATUS_BUTTON_NOT_PRESSED (HIDP_ERROR_CODES(0xC,0xF)) -#define HIDP_STATUS_REPORT_DOES_NOT_EXIST (HIDP_ERROR_CODES(0xC,0x10)) -#define HIDP_STATUS_NOT_IMPLEMENTED (HIDP_ERROR_CODES(0xC,0x20)) - -// -// We blundered this status code. -// -#define HIDP_STATUS_I8242_TRANS_UNKNOWN HIDP_STATUS_I8042_TRANS_UNKNOWN - -#include - -#endif - diff --git a/cpp/wiiuse/include/hidsdi.h b/cpp/wiiuse/include/hidsdi.h deleted file mode 100644 index baca22e..0000000 --- a/cpp/wiiuse/include/hidsdi.h +++ /dev/null @@ -1,487 +0,0 @@ -/*++ - -Copyright (c) Microsoft Corporation. All rights reserved. - -Module Name: - - HIDSDI.H - -Abstract: - - This module contains the PUBLIC definitions for the - code that implements the HID dll. - -Environment: - - Kernel & user mode - ---*/ - - -#ifndef _HIDSDI_H -#define _HIDSDI_H - -#include - -//#include "wtypes.h" - -//#include -//#include -//#include - -typedef LONG NTSTATUS; -#include "hidusage.h" -#include "hidpi.h" - -typedef struct _HIDD_CONFIGURATION { - PVOID cookie; - ULONG size; - ULONG RingBufferSize; -} HIDD_CONFIGURATION, *PHIDD_CONFIGURATION; - -typedef struct _HIDD_ATTRIBUTES { - ULONG Size; // = sizeof (struct _HIDD_ATTRIBUTES) - - // - // Vendor ids of this hid device - // - USHORT VendorID; - USHORT ProductID; - USHORT VersionNumber; - - // - // Additional fields will be added to the end of this structure. - // -} HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES; - - -BOOLEAN __stdcall -HidD_GetAttributes ( - IN HANDLE HidDeviceObject, - OUT PHIDD_ATTRIBUTES Attributes - ); -/*++ -Routine Description: - Fill in the given HIDD_ATTRIBUTES structure with the attributes of the - given hid device. - ---*/ - - -void __stdcall -HidD_GetHidGuid ( - OUT LPGUID HidGuid - ); - -BOOLEAN __stdcall -HidD_GetPreparsedData ( - IN HANDLE HidDeviceObject, - OUT PHIDP_PREPARSED_DATA * PreparsedData - ); -/*++ -Routine Description: - Given a handle to a valid Hid Class Device Object, retrieve the preparsed - data for the device. This routine will allocate the appropriately - sized buffer to hold this preparsed data. It is up to client to call - HidP_FreePreparsedData to free the memory allocated to this structure when - it is no longer needed. - -Arguments: - HidDeviceObject A handle to a Hid Device that the client obtains using - a call to CreateFile on a valid Hid device string name. - The string name can be obtained using standard PnP calls. - - PreparsedData An opaque data structure used by other functions in this - library to retrieve information about a given device. - -Return Value: - TRUE if successful. - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_FreePreparsedData ( - IN PHIDP_PREPARSED_DATA PreparsedData - ); - -BOOLEAN __stdcall -HidD_FlushQueue ( - IN HANDLE HidDeviceObject - ); -/*++ -Routine Description: - Flush the input queue for the given HID device. - -Arguments: - HidDeviceObject A handle to a Hid Device that the client obtains using - a call to CreateFile on a valid Hid device string name. - The string name can be obtained using standard PnP calls. - -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_GetConfiguration ( - IN HANDLE HidDeviceObject, - OUT PHIDD_CONFIGURATION Configuration, - IN ULONG ConfigurationLength - ); -/*++ -Routine Description: - Get the configuration information for this Hid device - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - Configuration A configuration structure. HidD_GetConfiguration MUST - be called before the configuration can be modified and - set using HidD_SetConfiguration - - ConfigurationLength That is ``sizeof (HIDD_CONFIGURATION)''. Using this - parameter, we can later increase the length of the - configuration array and not break older apps. - -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_SetConfiguration ( - IN HANDLE HidDeviceObject, - IN PHIDD_CONFIGURATION Configuration, - IN ULONG ConfigurationLength - ); -/*++ -Routine Description: - Set the configuration information for this Hid device... - - NOTE: HidD_GetConfiguration must be called to retrieve the current - configuration information before this information can be modified - and set. - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - Configuration A configuration structure. HidD_GetConfiguration MUST - be called before the configuration can be modified and - set using HidD_SetConfiguration - - ConfigurationLength That is ``sizeof (HIDD_CONFIGURATION)''. Using this - parameter, we can later increase the length of the - configuration array and not break older apps. - -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_GetFeature ( - IN HANDLE HidDeviceObject, - OUT PVOID ReportBuffer, - IN ULONG ReportBufferLength - ); -/*++ -Routine Description: - Retrieve a feature report from a HID device. - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - ReportBuffer The buffer that the feature report should be placed - into. The first byte of the buffer should be set to - the report ID of the desired report - - ReportBufferLength The size (in bytes) of ReportBuffer. This value - should be greater than or equal to the - FeatureReportByteLength field as specified in the - HIDP_CAPS structure for the device -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_SetFeature ( - IN HANDLE HidDeviceObject, - IN PVOID ReportBuffer, - IN ULONG ReportBufferLength - ); -/*++ -Routine Description: - Send a feature report to a HID device. - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - ReportBuffer The buffer of the feature report to send to the device - - ReportBufferLength The size (in bytes) of ReportBuffer. This value - should be greater than or equal to the - FeatureReportByteLength field as specified in the - HIDP_CAPS structure for the device -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_GetInputReport ( - IN HANDLE HidDeviceObject, - OUT PVOID ReportBuffer, - IN ULONG ReportBufferLength - ); -/*++ -Routine Description: - Retrieve an input report from a HID device. - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - ReportBuffer The buffer that the input report should be placed - into. The first byte of the buffer should be set to - the report ID of the desired report - - ReportBufferLength The size (in bytes) of ReportBuffer. This value - should be greater than or equal to the - InputReportByteLength field as specified in the - HIDP_CAPS structure for the device -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_SetOutputReport ( - IN HANDLE HidDeviceObject, - IN PVOID ReportBuffer, - IN ULONG ReportBufferLength - ); -/*++ -Routine Description: - Send an output report to a HID device. - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - ReportBuffer The buffer of the output report to send to the device - - ReportBufferLength The size (in bytes) of ReportBuffer. This value - should be greater than or equal to the - OutputReportByteLength field as specified in the - HIDP_CAPS structure for the device -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_GetNumInputBuffers ( - IN HANDLE HidDeviceObject, - OUT PULONG NumberBuffers - ); -/*++ -Routine Description: - This function returns the number of input buffers used by the specified - file handle to the Hid device. Each file object has a number of buffers - associated with it to queue reports read from the device but which have - not yet been read by the user-mode app with a handle to that device. - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - NumberBuffers Number of buffers currently being used for this file - handle to the Hid device - -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_SetNumInputBuffers ( - IN HANDLE HidDeviceObject, - OUT ULONG NumberBuffers - ); -/*++ - -Routine Description: - This function sets the number of input buffers used by the specified - file handle to the Hid device. Each file object has a number of buffers - associated with it to queue reports read from the device but which have - not yet been read by the user-mode app with a handle to that device. - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - NumberBuffers New number of buffers to use for this file handle to - the Hid device - -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_GetPhysicalDescriptor ( - IN HANDLE HidDeviceObject, - OUT PVOID Buffer, - IN ULONG BufferLength - ); -/*++ -Routine Description: - This function retrieves the raw physical descriptor for the specified - Hid device. - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - Buffer Buffer which on return will contain the physical - descriptor if one exists for the specified device - handle - - BufferLength Length of buffer (in bytes) - - -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_GetManufacturerString ( - IN HANDLE HidDeviceObject, - OUT PVOID Buffer, - IN ULONG BufferLength - ); -/*++ -Routine Description: - This function retrieves the manufacturer string from the specified - Hid device. - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - Buffer Buffer which on return will contain the manufacturer - string returned from the device. This string is a - wide-character string - - BufferLength Length of Buffer (in bytes) - - -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_GetProductString ( - IN HANDLE HidDeviceObject, - OUT PVOID Buffer, - IN ULONG BufferLength - ); -/*++ -Routine Description: - This function retrieves the product string from the specified - Hid device. - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - Buffer Buffer which on return will contain the product - string returned from the device. This string is a - wide-character string - - BufferLength Length of Buffer (in bytes) - - -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_GetIndexedString ( - IN HANDLE HidDeviceObject, - IN ULONG StringIndex, - OUT PVOID Buffer, - IN ULONG BufferLength - ); -/*++ -Routine Description: - This function retrieves a string from the specified Hid device that is - specified with a certain string index. - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - StringIndex Index of the string to retrieve - - Buffer Buffer which on return will contain the product - string returned from the device. This string is a - wide-character string - - BufferLength Length of Buffer (in bytes) - -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_GetSerialNumberString ( - IN HANDLE HidDeviceObject, - OUT PVOID Buffer, - IN ULONG BufferLength - ); -/*++ -Routine Description: - This function retrieves the serial number string from the specified - Hid device. - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - Buffer Buffer which on return will contain the serial number - string returned from the device. This string is a - wide-character string - - BufferLength Length of Buffer (in bytes) - -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - -BOOLEAN __stdcall -HidD_GetMsGenreDescriptor ( - IN HANDLE HidDeviceObject, - OUT PVOID Buffer, - IN ULONG BufferLength - ); -/*++ -Routine Description: - This function retrieves the Microsoft Genre descriptor from the specified - Hid device. - -Arguments: - HidDeviceObject A handle to a Hid Device Object. - - Buffer Buffer which on return will contain the descriptor - returned from the device. - - BufferLength Length of Buffer (in bytes) - -Return Value: - TRUE if successful - FALSE otherwise -- Use GetLastError() to get extended error information ---*/ - - -#include - -#endif - diff --git a/cpp/wiiuse/include/hidusage.h b/cpp/wiiuse/include/hidusage.h deleted file mode 100644 index b1de106..0000000 --- a/cpp/wiiuse/include/hidusage.h +++ /dev/null @@ -1,271 +0,0 @@ -/*++ - -Copyright (c) Microsoft Corporation. All rights reserved. - -Module Name: - - HIDUSAGE.H - -Abstract: - - Public Definitions of HID USAGES. - -Environment: - - Kernel & user mode - ---*/ - -#ifndef __HIDUSAGE_H__ -#define __HIDUSAGE_H__ - -// -// Usage Pages -// - -typedef USHORT USAGE, *PUSAGE; - -#define HID_USAGE_PAGE_UNDEFINED ((USAGE) 0x00) -#define HID_USAGE_PAGE_GENERIC ((USAGE) 0x01) -#define HID_USAGE_PAGE_SIMULATION ((USAGE) 0x02) -#define HID_USAGE_PAGE_VR ((USAGE) 0x03) -#define HID_USAGE_PAGE_SPORT ((USAGE) 0x04) -#define HID_USAGE_PAGE_GAME ((USAGE) 0x05) -#define HID_USAGE_PAGE_KEYBOARD ((USAGE) 0x07) -#define HID_USAGE_PAGE_LED ((USAGE) 0x08) -#define HID_USAGE_PAGE_BUTTON ((USAGE) 0x09) -#define HID_USAGE_PAGE_ORDINAL ((USAGE) 0x0A) -#define HID_USAGE_PAGE_TELEPHONY ((USAGE) 0x0B) -#define HID_USAGE_PAGE_CONSUMER ((USAGE) 0x0C) -#define HID_USAGE_PAGE_DIGITIZER ((USAGE) 0x0D) -#define HID_USAGE_PAGE_UNICODE ((USAGE) 0x10) -#define HID_USAGE_PAGE_ALPHANUMERIC ((USAGE) 0x14) - - -// -// Usages from Generic Desktop Page (0x01) -// - -#define HID_USAGE_GENERIC_POINTER ((USAGE) 0x01) -#define HID_USAGE_GENERIC_MOUSE ((USAGE) 0x02) -#define HID_USAGE_GENERIC_JOYSTICK ((USAGE) 0x04) -#define HID_USAGE_GENERIC_GAMEPAD ((USAGE) 0x05) -#define HID_USAGE_GENERIC_KEYBOARD ((USAGE) 0x06) -#define HID_USAGE_GENERIC_KEYPAD ((USAGE) 0x07) -#define HID_USAGE_GENERIC_SYSTEM_CTL ((USAGE) 0x80) - -#define HID_USAGE_GENERIC_X ((USAGE) 0x30) -#define HID_USAGE_GENERIC_Y ((USAGE) 0x31) -#define HID_USAGE_GENERIC_Z ((USAGE) 0x32) -#define HID_USAGE_GENERIC_RX ((USAGE) 0x33) -#define HID_USAGE_GENERIC_RY ((USAGE) 0x34) -#define HID_USAGE_GENERIC_RZ ((USAGE) 0x35) -#define HID_USAGE_GENERIC_SLIDER ((USAGE) 0x36) -#define HID_USAGE_GENERIC_DIAL ((USAGE) 0x37) -#define HID_USAGE_GENERIC_WHEEL ((USAGE) 0x38) -#define HID_USAGE_GENERIC_HATSWITCH ((USAGE) 0x39) -#define HID_USAGE_GENERIC_COUNTED_BUFFER ((USAGE) 0x3A) -#define HID_USAGE_GENERIC_BYTE_COUNT ((USAGE) 0x3B) -#define HID_USAGE_GENERIC_MOTION_WAKEUP ((USAGE) 0x3C) -#define HID_USAGE_GENERIC_VX ((USAGE) 0x40) -#define HID_USAGE_GENERIC_VY ((USAGE) 0x41) -#define HID_USAGE_GENERIC_VZ ((USAGE) 0x42) -#define HID_USAGE_GENERIC_VBRX ((USAGE) 0x43) -#define HID_USAGE_GENERIC_VBRY ((USAGE) 0x44) -#define HID_USAGE_GENERIC_VBRZ ((USAGE) 0x45) -#define HID_USAGE_GENERIC_VNO ((USAGE) 0x46) -#define HID_USAGE_GENERIC_SYSCTL_POWER ((USAGE) 0x81) -#define HID_USAGE_GENERIC_SYSCTL_SLEEP ((USAGE) 0x82) -#define HID_USAGE_GENERIC_SYSCTL_WAKE ((USAGE) 0x83) -#define HID_USAGE_GENERIC_SYSCTL_CONTEXT_MENU ((USAGE) 0x84) -#define HID_USAGE_GENERIC_SYSCTL_MAIN_MENU ((USAGE) 0x85) -#define HID_USAGE_GENERIC_SYSCTL_APP_MENU ((USAGE) 0x86) -#define HID_USAGE_GENERIC_SYSCTL_HELP_MENU ((USAGE) 0x87) -#define HID_USAGE_GENERIC_SYSCTL_MENU_EXIT ((USAGE) 0x88) -#define HID_USAGE_GENERIC_SYSCTL_MENU_SELECT ((USAGE) 0x89) -#define HID_USAGE_GENERIC_SYSCTL_MENU_RIGHT ((USAGE) 0x8A) -#define HID_USAGE_GENERIC_SYSCTL_MENU_LEFT ((USAGE) 0x8B) -#define HID_USAGE_GENERIC_SYSCTL_MENU_UP ((USAGE) 0x8C) -#define HID_USAGE_GENERIC_SYSCTL_MENU_DOWN ((USAGE) 0x8D) - -// -// Usages from Simulation Controls Page (0x02) -// - -#define HID_USAGE_SIMULATION_RUDDER ((USAGE) 0xBA) -#define HID_USAGE_SIMULATION_THROTTLE ((USAGE) 0xBB) - -// -// Virtual Reality Controls Page (0x03) -// - - -// -// Sport Controls Page (0x04) -// - - -// -// Game Controls Page (0x05) -// - - -// -// Keyboard/Keypad Page (0x07) -// - - // Error "keys" -#define HID_USAGE_KEYBOARD_NOEVENT ((USAGE) 0x00) -#define HID_USAGE_KEYBOARD_ROLLOVER ((USAGE) 0x01) -#define HID_USAGE_KEYBOARD_POSTFAIL ((USAGE) 0x02) -#define HID_USAGE_KEYBOARD_UNDEFINED ((USAGE) 0x03) - - // Letters -#define HID_USAGE_KEYBOARD_aA ((USAGE) 0x04) -#define HID_USAGE_KEYBOARD_zZ ((USAGE) 0x1D) - // Numbers -#define HID_USAGE_KEYBOARD_ONE ((USAGE) 0x1E) -#define HID_USAGE_KEYBOARD_ZERO ((USAGE) 0x27) - // Modifier Keys -#define HID_USAGE_KEYBOARD_LCTRL ((USAGE) 0xE0) -#define HID_USAGE_KEYBOARD_LSHFT ((USAGE) 0xE1) -#define HID_USAGE_KEYBOARD_LALT ((USAGE) 0xE2) -#define HID_USAGE_KEYBOARD_LGUI ((USAGE) 0xE3) -#define HID_USAGE_KEYBOARD_RCTRL ((USAGE) 0xE4) -#define HID_USAGE_KEYBOARD_RSHFT ((USAGE) 0xE5) -#define HID_USAGE_KEYBOARD_RALT ((USAGE) 0xE6) -#define HID_USAGE_KEYBOARD_RGUI ((USAGE) 0xE7) -#define HID_USAGE_KEYBOARD_SCROLL_LOCK ((USAGE) 0x47) -#define HID_USAGE_KEYBOARD_NUM_LOCK ((USAGE) 0x53) -#define HID_USAGE_KEYBOARD_CAPS_LOCK ((USAGE) 0x39) - // Funtion keys -#define HID_USAGE_KEYBOARD_F1 ((USAGE) 0x3A) -#define HID_USAGE_KEYBOARD_F12 ((USAGE) 0x45) - -#define HID_USAGE_KEYBOARD_RETURN ((USAGE) 0x28) -#define HID_USAGE_KEYBOARD_ESCAPE ((USAGE) 0x29) -#define HID_USAGE_KEYBOARD_DELETE ((USAGE) 0x2A) - -#define HID_USAGE_KEYBOARD_PRINT_SCREEN ((USAGE) 0x46) - -// and hundreds more... - -// -// LED Page (0x08) -// - -#define HID_USAGE_LED_NUM_LOCK ((USAGE) 0x01) -#define HID_USAGE_LED_CAPS_LOCK ((USAGE) 0x02) -#define HID_USAGE_LED_SCROLL_LOCK ((USAGE) 0x03) -#define HID_USAGE_LED_COMPOSE ((USAGE) 0x04) -#define HID_USAGE_LED_KANA ((USAGE) 0x05) -#define HID_USAGE_LED_POWER ((USAGE) 0x06) -#define HID_USAGE_LED_SHIFT ((USAGE) 0x07) -#define HID_USAGE_LED_DO_NOT_DISTURB ((USAGE) 0x08) -#define HID_USAGE_LED_MUTE ((USAGE) 0x09) -#define HID_USAGE_LED_TONE_ENABLE ((USAGE) 0x0A) -#define HID_USAGE_LED_HIGH_CUT_FILTER ((USAGE) 0x0B) -#define HID_USAGE_LED_LOW_CUT_FILTER ((USAGE) 0x0C) -#define HID_USAGE_LED_EQUALIZER_ENABLE ((USAGE) 0x0D) -#define HID_USAGE_LED_SOUND_FIELD_ON ((USAGE) 0x0E) -#define HID_USAGE_LED_SURROUND_FIELD_ON ((USAGE) 0x0F) -#define HID_USAGE_LED_REPEAT ((USAGE) 0x10) -#define HID_USAGE_LED_STEREO ((USAGE) 0x11) -#define HID_USAGE_LED_SAMPLING_RATE_DETECT ((USAGE) 0x12) -#define HID_USAGE_LED_SPINNING ((USAGE) 0x13) -#define HID_USAGE_LED_CAV ((USAGE) 0x14) -#define HID_USAGE_LED_CLV ((USAGE) 0x15) -#define HID_USAGE_LED_RECORDING_FORMAT_DET ((USAGE) 0x16) -#define HID_USAGE_LED_OFF_HOOK ((USAGE) 0x17) -#define HID_USAGE_LED_RING ((USAGE) 0x18) -#define HID_USAGE_LED_MESSAGE_WAITING ((USAGE) 0x19) -#define HID_USAGE_LED_DATA_MODE ((USAGE) 0x1A) -#define HID_USAGE_LED_BATTERY_OPERATION ((USAGE) 0x1B) -#define HID_USAGE_LED_BATTERY_OK ((USAGE) 0x1C) -#define HID_USAGE_LED_BATTERY_LOW ((USAGE) 0x1D) -#define HID_USAGE_LED_SPEAKER ((USAGE) 0x1E) -#define HID_USAGE_LED_HEAD_SET ((USAGE) 0x1F) -#define HID_USAGE_LED_HOLD ((USAGE) 0x20) -#define HID_USAGE_LED_MICROPHONE ((USAGE) 0x21) -#define HID_USAGE_LED_COVERAGE ((USAGE) 0x22) -#define HID_USAGE_LED_NIGHT_MODE ((USAGE) 0x23) -#define HID_USAGE_LED_SEND_CALLS ((USAGE) 0x24) -#define HID_USAGE_LED_CALL_PICKUP ((USAGE) 0x25) -#define HID_USAGE_LED_CONFERENCE ((USAGE) 0x26) -#define HID_USAGE_LED_STAND_BY ((USAGE) 0x27) -#define HID_USAGE_LED_CAMERA_ON ((USAGE) 0x28) -#define HID_USAGE_LED_CAMERA_OFF ((USAGE) 0x29) -#define HID_USAGE_LED_ON_LINE ((USAGE) 0x2A) -#define HID_USAGE_LED_OFF_LINE ((USAGE) 0x2B) -#define HID_USAGE_LED_BUSY ((USAGE) 0x2C) -#define HID_USAGE_LED_READY ((USAGE) 0x2D) -#define HID_USAGE_LED_PAPER_OUT ((USAGE) 0x2E) -#define HID_USAGE_LED_PAPER_JAM ((USAGE) 0x2F) -#define HID_USAGE_LED_REMOTE ((USAGE) 0x30) -#define HID_USAGE_LED_FORWARD ((USAGE) 0x31) -#define HID_USAGE_LED_REVERSE ((USAGE) 0x32) -#define HID_USAGE_LED_STOP ((USAGE) 0x33) -#define HID_USAGE_LED_REWIND ((USAGE) 0x34) -#define HID_USAGE_LED_FAST_FORWARD ((USAGE) 0x35) -#define HID_USAGE_LED_PLAY ((USAGE) 0x36) -#define HID_USAGE_LED_PAUSE ((USAGE) 0x37) -#define HID_USAGE_LED_RECORD ((USAGE) 0x38) -#define HID_USAGE_LED_ERROR ((USAGE) 0x39) -#define HID_USAGE_LED_SELECTED_INDICATOR ((USAGE) 0x3A) -#define HID_USAGE_LED_IN_USE_INDICATOR ((USAGE) 0x3B) -#define HID_USAGE_LED_MULTI_MODE_INDICATOR ((USAGE) 0x3C) -#define HID_USAGE_LED_INDICATOR_ON ((USAGE) 0x3D) -#define HID_USAGE_LED_INDICATOR_FLASH ((USAGE) 0x3E) -#define HID_USAGE_LED_INDICATOR_SLOW_BLINK ((USAGE) 0x3F) -#define HID_USAGE_LED_INDICATOR_FAST_BLINK ((USAGE) 0x40) -#define HID_USAGE_LED_INDICATOR_OFF ((USAGE) 0x41) -#define HID_USAGE_LED_FLASH_ON_TIME ((USAGE) 0x42) -#define HID_USAGE_LED_SLOW_BLINK_ON_TIME ((USAGE) 0x43) -#define HID_USAGE_LED_SLOW_BLINK_OFF_TIME ((USAGE) 0x44) -#define HID_USAGE_LED_FAST_BLINK_ON_TIME ((USAGE) 0x45) -#define HID_USAGE_LED_FAST_BLINK_OFF_TIME ((USAGE) 0x46) -#define HID_USAGE_LED_INDICATOR_COLOR ((USAGE) 0x47) -#define HID_USAGE_LED_RED ((USAGE) 0x48) -#define HID_USAGE_LED_GREEN ((USAGE) 0x49) -#define HID_USAGE_LED_AMBER ((USAGE) 0x4A) -#define HID_USAGE_LED_GENERIC_INDICATOR ((USAGE) 0x3B) - -// -// Button Page (0x09) -// -// There is no need to label these usages. -// - - -// -// Ordinal Page (0x0A) -// -// There is no need to label these usages. -// - - -// -// Telephony Device Page (0x0B) -// - -#define HID_USAGE_TELEPHONY_PHONE ((USAGE) 0x01) -#define HID_USAGE_TELEPHONY_ANSWERING_MACHINE ((USAGE) 0x02) -#define HID_USAGE_TELEPHONY_MESSAGE_CONTROLS ((USAGE) 0x03) -#define HID_USAGE_TELEPHONY_HANDSET ((USAGE) 0x04) -#define HID_USAGE_TELEPHONY_HEADSET ((USAGE) 0x05) -#define HID_USAGE_TELEPHONY_KEYPAD ((USAGE) 0x06) -#define HID_USAGE_TELEPHONY_PROGRAMMABLE_BUTTON ((USAGE) 0x07) - -// -// and others... -// - -#define HID_USAGE_CONSUMERCTRL ((USAGE)0x01) -#define HID_USAGE_DIGITIZER_PEN ((USAGE)0x02) -#define HID_USAGE_DIGITIZER_IN_RANGE ((USAGE)0x32) -#define HID_USAGE_DIGITIZER_TIP_SWITCH ((USAGE)0x42) -#define HID_USAGE_DIGITIZER_BARREL_SWITCH ((USAGE)0x44) - -#endif - - diff --git a/cpp/wiiuse/lib/hid.lib b/cpp/wiiuse/lib/hid.lib deleted file mode 100644 index 2b5e749..0000000 Binary files a/cpp/wiiuse/lib/hid.lib and /dev/null differ diff --git a/cpp/wiiuse/src/balance_board.c b/cpp/wiiuse/src/balance_board.c deleted file mode 100644 index b765c09..0000000 --- a/cpp/wiiuse/src/balance_board.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * This file: - * Bertho Stultiens < para > - * - * Copyright 2009 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Balance Board expansion device. - */ - -#include -#include -#include - -#ifdef WIN32 - #include -#endif - -#include "definitions.h" -#include "wiiuse_internal.h" -#include "dynamics.h" -#include "events.h" -#include "balance_board.h" - -/** - * @brief Handle the handshake data from the guitar. - * - * @param cc A pointer to a classic_ctrl_t structure. - * @param data The data read in from the device. - * @param len The length of the data block, in bytes. - * - * @return Returns 1 if handshake was successful, 0 if not. - */ -int balance_board_handshake(struct wiimote_t* wm, struct balance_board_t* bb, byte* data, unsigned short len) { - int i; - - bb->tr = 0.0; - bb->br = 0.0; - bb->tl = 0.0; - bb->br = 0.0; - - if (len < 0xe0) - return 0; - - if (data[0xdc] != 0xa4) { - /* decrypt data */ - for (i = 0; i < len; ++i) - data[i] = (data[i] ^ 0x17) + 0x17; - } - - /* See: http://wiibrew.org/wiki/Wii_Balance_Board */ - /* Unknown data at 0xa40020..23 (mine says: 0x44 0x69 0x00 0x00) */ - bb->cal_0.tr = (data[0x04] << 8) + data[0x05]; - bb->cal_0.br = (data[0x06] << 8) + data[0x07]; - bb->cal_0.tl = (data[0x08] << 8) + data[0x09]; - bb->cal_0.bl = (data[0x0a] << 8) + data[0x0b]; - bb->cal_17.tr = (data[0x0c] << 8) + data[0x0d]; - bb->cal_17.br = (data[0x0e] << 8) + data[0x0f]; - bb->cal_17.tl = (data[0x10] << 8) + data[0x11]; - bb->cal_17.bl = (data[0x12] << 8) + data[0x13]; - bb->cal_34.tr = (data[0x14] << 8) + data[0x15]; - bb->cal_34.br = (data[0x16] << 8) + data[0x17]; - bb->cal_34.tl = (data[0x18] << 8) + data[0x19]; - bb->cal_34.bl = (data[0x1a] << 8) + data[0x1b]; - /* Unknown data at 0xa4003c..3f (mine says: 0x4c 0x81 0x59 0x95) */ - - WIIUSE_DEBUG("calibration 0: %04x %04x %04x %04x\n", bb->cal_0.tr, bb->cal_0.br, bb->cal_0.tl, bb->cal_0.br); - WIIUSE_DEBUG("calibration 17: %04x %04x %04x %04x\n", bb->cal_17.tr, bb->cal_17.br, bb->cal_17.tl, bb->cal_17.br); - WIIUSE_DEBUG("calibration 34: %04x %04x %04x %04x\n", bb->cal_34.tr, bb->cal_34.br, bb->cal_34.tl, bb->cal_34.br); - - /* handshake done */ - wm->exp.type = EXP_BALANCE_BOARD; - - #ifdef WIN32 - wm->timeout = WIIMOTE_DEFAULT_TIMEOUT; - #endif - - return 1; -} - - -/** - * @brief The balance board disconnected. - * - * @param cc A pointer to a balance_board_t structure. - */ -void balance_board_disconnected(struct balance_board_t* bb) { - memset(bb, 0, sizeof(*bb)); -} - - - -/** - * @brief Handle balance board event. - * - * @param cc A pointer to a balance board_t structure. - * @param msg The message specified in the event packet. - */ -#define set_bbval(x) do {\ - if(bb->raw.x < bb->cal_17.x) \ - bb->x = 17.0 * (float)(bb->raw.x - bb->cal_0.x) / (float)(bb->cal_17.x - bb->cal_0.x); \ - else \ - bb->x = 17.0 * (1.0 + (float)(bb->raw.x - bb->cal_17.x) / (float)(bb->cal_34.x - bb->cal_17.x)); \ - } while(0) -void balance_board_event(struct balance_board_t* bb, byte* msg) { - bb->raw.tr = (msg[0] << 8) + msg[1]; - bb->raw.br = (msg[2] << 8) + msg[3]; - bb->raw.tl = (msg[4] << 8) + msg[5]; - bb->raw.bl = (msg[6] << 8) + msg[7]; - set_bbval(tr); - set_bbval(br); - set_bbval(tl); - set_bbval(bl); -} - diff --git a/cpp/wiiuse/src/balance_board.h b/cpp/wiiuse/src/balance_board.h deleted file mode 100644 index a3d2ca5..0000000 --- a/cpp/wiiuse/src/balance_board.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * This file: - * Bertho Stultiens < para > - * - * Copyright 2009 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Balance Board expansion device. - */ - -#ifndef BALANCE_BOARD_H_INCLUDED -#define BALANCE_BOARD_H_INCLUDED - -#include "wiiuse_internal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int balance_board_handshake(struct wiimote_t* wm, struct balance_board_t* bb, byte* data, unsigned short len); -void balance_board_disconnected(struct balance_board_t* bb); -void balance_board_event(struct balance_board_t* bb, byte* msg); - -#ifdef __cplusplus -} -#endif - -#endif // BALANCE_BOARD_H_INCLUDED diff --git a/cpp/wiiuse/src/classic.c b/cpp/wiiuse/src/classic.c deleted file mode 100644 index 1d2c3ab..0000000 --- a/cpp/wiiuse/src/classic.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Classic controller expansion device. - */ - -#include -#include -#include - -#ifdef WIN32 - #include -#endif - -#include "definitions.h" -#include "wiiuse_internal.h" -#include "dynamics.h" -#include "events.h" -#include "classic.h" - -static void classic_ctrl_pressed_buttons(struct classic_ctrl_t* cc, short now); - -/** - * @brief Handle the handshake data from the classic controller. - * - * @param cc A pointer to a classic_ctrl_t structure. - * @param data The data read in from the device. - * @param len The length of the data block, in bytes. - * - * @return Returns 1 if handshake was successful, 0 if not. - */ -int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len) { - int i; - int offset = 0; - - cc->btns = 0; - cc->btns_held = 0; - cc->btns_released = 0; - cc->r_shoulder = 0; - cc->l_shoulder = 0; - - /* decrypt data */ - for (i = 0; i < len; ++i) - data[i] = (data[i] ^ 0x17) + 0x17; - - if (data[offset] == 0xFF) { - /* - * Sometimes the data returned here is not correct. - * This might happen because the wiimote is lagging - * behind our initialization sequence. - * To fix this just request the handshake again. - * - * Other times it's just the first 16 bytes are 0xFF, - * but since the next 16 bytes are the same, just use - * those. - */ - if (data[offset + 16] == 0xFF) { - /* get the calibration data */ - byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); - - WIIUSE_DEBUG("Classic controller handshake appears invalid, trying again."); - wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); - - return 0; - } else - offset += 16; - } - - - /* joystick stuff */ - cc->ljs.max.x = data[0 + offset] / 4; - cc->ljs.min.x = data[1 + offset] / 4; - cc->ljs.center.x = data[2 + offset] / 4; - cc->ljs.max.y = data[3 + offset] / 4; - cc->ljs.min.y = data[4 + offset] / 4; - cc->ljs.center.y = data[5 + offset] / 4; - - cc->rjs.max.x = data[6 + offset] / 8; - cc->rjs.min.x = data[7 + offset] / 8; - cc->rjs.center.x = data[8 + offset] / 8; - cc->rjs.max.y = data[9 + offset] / 8; - cc->rjs.min.y = data[10 + offset] / 8; - cc->rjs.center.y = data[11 + offset] / 8; - - /* handshake done */ - wm->exp.type = EXP_CLASSIC; - - #ifdef WIN32 - wm->timeout = WIIMOTE_DEFAULT_TIMEOUT; - #endif - - return 1; -} - - -/** - * @brief The classic controller disconnected. - * - * @param cc A pointer to a classic_ctrl_t structure. - */ -void classic_ctrl_disconnected(struct classic_ctrl_t* cc) { - memset(cc, 0, sizeof(struct classic_ctrl_t)); -} - - - -/** - * @brief Handle classic controller event. - * - * @param cc A pointer to a classic_ctrl_t structure. - * @param msg The message specified in the event packet. - */ -void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg) { - int i, lx, ly, rx, ry; - byte l, r; - - /* decrypt data */ - for (i = 0; i < 6; ++i) - msg[i] = (msg[i] ^ 0x17) + 0x17; - - classic_ctrl_pressed_buttons(cc, BIG_ENDIAN_SHORT(*(short*)(msg + 4))); - - /* left/right buttons */ - l = (((msg[2] & 0x60) >> 2) | ((msg[3] & 0xE0) >> 5)); - r = (msg[3] & 0x1F); - - /* - * TODO - LR range hardcoded from 0x00 to 0x1F. - * This is probably in the calibration somewhere. - */ - cc->r_shoulder = ((float)r / 0x1F); - cc->l_shoulder = ((float)l / 0x1F); - - /* calculate joystick orientation */ - lx = (msg[0] & 0x3F); - ly = (msg[1] & 0x3F); - rx = ((msg[0] & 0xC0) >> 3) | ((msg[1] & 0xC0) >> 5) | ((msg[2] & 0x80) >> 7); - ry = (msg[2] & 0x1F); - - calc_joystick_state(&cc->ljs, lx, ly); - calc_joystick_state(&cc->rjs, rx, ry); -} - - -/** - * @brief Find what buttons are pressed. - * - * @param cc A pointer to a classic_ctrl_t structure. - * @param msg The message byte specified in the event packet. - */ -static void classic_ctrl_pressed_buttons(struct classic_ctrl_t* cc, short now) { - /* message is inverted (0 is active, 1 is inactive) */ - now = ~now & CLASSIC_CTRL_BUTTON_ALL; - - /* pressed now & were pressed, then held */ - cc->btns_held = (now & cc->btns); - - /* were pressed or were held & not pressed now, then released */ - cc->btns_released = ((cc->btns | cc->btns_held) & ~now); - - /* buttons pressed now */ - cc->btns = now; -} diff --git a/cpp/wiiuse/src/classic.h b/cpp/wiiuse/src/classic.h deleted file mode 100644 index 356f6a4..0000000 --- a/cpp/wiiuse/src/classic.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Classic controller expansion device. - */ - -#ifndef CLASSIC_H_INCLUDED -#define CLASSIC_H_INCLUDED - -#include "wiiuse_internal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len); - -void classic_ctrl_disconnected(struct classic_ctrl_t* cc); - -void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg); - -#ifdef __cplusplus -} -#endif - -#endif // CLASSIC_H_INCLUDED diff --git a/cpp/wiiuse/src/definitions.h b/cpp/wiiuse/src/definitions.h deleted file mode 100644 index bc44ff5..0000000 --- a/cpp/wiiuse/src/definitions.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief General definitions. - */ - -#ifndef DEFINITIONS_H_INCLUDED -#define DEFINITIONS_H_INCLUDED - -/* this is wiiuse - used to distinguish from third party programs using wiiuse.h */ -#include "os.h" - -#define WIIMOTE_PI 3.14159265f - -/* Error output macros */ -#define WIIUSE_ERROR(fmt, ...) //fprintf(stderr, "[ERROR] " fmt "\n", ##__VA_ARGS__) - -/* Warning output macros */ -#define WIIUSE_WARNING(fmt, ...) //fprintf(stderr, "[WARNING] " fmt "\n", ##__VA_ARGS__) - -/* Information output macros */ -#define WIIUSE_INFO(fmt, ...) //fprintf(stderr, "[INFO] " fmt "\n", ##__VA_ARGS__) - -#ifdef WITH_WIIUSE_DEBUG - #ifdef WIN32 - #define WIIUSE_DEBUG(fmt, ...) do { \ - char* file = __FILE__; \ - int i = strlen(file) - 1; \ - for (; i && (file[i] != '\\'); --i); \ - fprintf(stdout, "[DEBUG] %s:%i: " fmt "\n", file+i+1, __LINE__, ##__VA_ARGS__); \ - fflush(stdout); \ - } while (0) - #else - #define WIIUSE_DEBUG(fmt, ...) fprintf(stderr, "[DEBUG] " __FILE__ ":%i: " fmt "\n", __LINE__, ##__VA_ARGS__) - #endif -#else - #define WIIUSE_DEBUG(fmt, ...) -#endif - -/* Convert between radians and degrees */ -#define RAD_TO_DEGREE(r) ((r * 180.0f) / WIIMOTE_PI) -#define DEGREE_TO_RAD(d) (d * (WIIMOTE_PI / 180.0f)) - -/* Convert to big endian */ -#define BIG_ENDIAN_LONG(i) (htonl(i)) -#define BIG_ENDIAN_SHORT(i) (htons(i)) - -#define absf(x) ((x >= 0) ? (x) : (x * -1.0f)) -#define diff_f(x, y) ((x >= y) ? (absf(x - y)) : (absf(y - x))) - -#endif // DEFINITIONS_H_INCLUDED diff --git a/cpp/wiiuse/src/dynamics.c b/cpp/wiiuse/src/dynamics.c deleted file mode 100644 index 53612a6..0000000 --- a/cpp/wiiuse/src/dynamics.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Handles the dynamics of the wiimote. - * - * The file includes functions that handle the dynamics - * of the wiimote. Such dynamics include orientation and - * motion sensing. - */ - -#include -#include -#include - -#ifdef WIN32 - #include -#endif - -#include "definitions.h" -#include "wiiuse_internal.h" -#include "ir.h" -#include "dynamics.h" - -/** - * @brief Calculate the roll, pitch, yaw. - * - * @param ac An accelerometer (accel_t) structure. - * @param accel [in] Pointer to a vec3b_t structure that holds the raw acceleration data. - * @param orient [out] Pointer to a orient_t structure that will hold the orientation data. - * @param rorient [out] Pointer to a orient_t structure that will hold the non-smoothed orientation data. - * @param smooth If smoothing should be performed on the angles calculated. 1 to enable, 0 to disable. - * - * Given the raw acceleration data from the accelerometer struct, calculate - * the orientation of the device and set it in the \a orient parameter. - */ -void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct orient_t* orient, int smooth) { - float xg, yg, zg; - float x, y, z; - - /* - * roll - use atan(z / x) [ ranges from -180 to 180 ] - * pitch - use atan(z / y) [ ranges from -180 to 180 ] - * yaw - impossible to tell without IR - */ - - /* yaw - set to 0, IR will take care of it if it's enabled */ - orient->yaw = 0.0f; - - /* find out how much it has to move to be 1g */ - xg = (float)ac->cal_g.x; - yg = (float)ac->cal_g.y; - zg = (float)ac->cal_g.z; - - /* find out how much it actually moved and normalize to +/- 1g */ - x = ((float)accel->x - (float)ac->cal_zero.x) / xg; - y = ((float)accel->y - (float)ac->cal_zero.y) / yg; - z = ((float)accel->z - (float)ac->cal_zero.z) / zg; - - /* make sure x,y,z are between -1 and 1 for the tan functions */ - if (x < -1.0f) x = -1.0f; - else if (x > 1.0f) x = 1.0f; - if (y < -1.0f) y = -1.0f; - else if (y > 1.0f) y = 1.0f; - if (z < -1.0f) z = -1.0f; - else if (z > 1.0f) z = 1.0f; - - /* if it is over 1g then it is probably accelerating and not reliable */ - if (abs(accel->x - ac->cal_zero.x) <= ac->cal_g.x) { - /* roll */ - x = RAD_TO_DEGREE(atan2f(x, z)); - - orient->roll = x; - orient->a_roll = x; - } - - if (abs(accel->y - ac->cal_zero.y) <= ac->cal_g.y) { - /* pitch */ - y = RAD_TO_DEGREE(atan2f(y, z)); - - orient->pitch = y; - orient->a_pitch = y; - } - - /* smooth the angles if enabled */ - if (smooth) { - apply_smoothing(ac, orient, SMOOTH_ROLL); - apply_smoothing(ac, orient, SMOOTH_PITCH); - } -} - - -/** - * @brief Calculate the gravity forces on each axis. - * - * @param ac An accelerometer (accel_t) structure. - * @param accel [in] Pointer to a vec3b_t structure that holds the raw acceleration data. - * @param gforce [out] Pointer to a gforce_t structure that will hold the gravity force data. - */ -void calculate_gforce(struct accel_t* ac, struct vec3b_t* accel, struct gforce_t* gforce) { - float xg, yg, zg; - - /* find out how much it has to move to be 1g */ - xg = (float)ac->cal_g.x; - yg = (float)ac->cal_g.y; - zg = (float)ac->cal_g.z; - - /* find out how much it actually moved and normalize to +/- 1g */ - gforce->x = ((float)accel->x - (float)ac->cal_zero.x) / xg; - gforce->y = ((float)accel->y - (float)ac->cal_zero.y) / yg; - gforce->z = ((float)accel->z - (float)ac->cal_zero.z) / zg; -} - - -/** - * @brief Calculate the angle and magnitude of a joystick. - * - * @param js [out] Pointer to a joystick_t structure. - * @param x The raw x-axis value. - * @param y The raw y-axis value. - */ -void calc_joystick_state(struct joystick_t* js, float x, float y) { - float rx, ry, ang; - - /* - * Since the joystick center may not be exactly: - * (min + max) / 2 - * Then the range from the min to the center and the center to the max - * may be different. - * Because of this, depending on if the current x or y value is greater - * or less than the assoicated axis center value, it needs to be interpolated - * between the center and the minimum or maxmimum rather than between - * the minimum and maximum. - * - * So we have something like this: - * (x min) [-1] ---------*------ [0] (x center) [0] -------- [1] (x max) - * Where the * is the current x value. - * The range is therefore -1 to 1, 0 being the exact center rather than - * the middle of min and max. - */ - if (x == js->center.x) - rx = 0; - else if (x >= js->center.x) - rx = ((float)(x - js->center.x) / (float)(js->max.x - js->center.x)); - else - rx = ((float)(x - js->min.x) / (float)(js->center.x - js->min.x)) - 1.0f; - - if (y == js->center.y) - ry = 0; - else if (y >= js->center.y) - ry = ((float)(y - js->center.y) / (float)(js->max.y - js->center.y)); - else - ry = ((float)(y - js->min.y) / (float)(js->center.y - js->min.y)) - 1.0f; - - /* calculate the joystick angle and magnitude */ - ang = RAD_TO_DEGREE(atanf(ry / rx)); - ang -= 90.0f; - if (rx < 0.0f) - ang -= 180.0f; - js->ang = absf(ang); - js->mag = (float) sqrt((rx * rx) + (ry * ry)); -} - - -void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type) { - switch (type) { - case SMOOTH_ROLL: - { - /* it's possible last iteration was nan or inf, so set it to 0 if that happened */ - if (isnan(ac->st_roll) || isinf(ac->st_roll)) - ac->st_roll = 0.0f; - - /* - * If the sign changes (which will happen if going from -180 to 180) - * or from (-1 to 1) then don't smooth, just use the new angle. - */ - if (((ac->st_roll < 0) && (orient->roll > 0)) || ((ac->st_roll > 0) && (orient->roll < 0))) { - ac->st_roll = orient->roll; - } else { - orient->roll = ac->st_roll + (ac->st_alpha * (orient->a_roll - ac->st_roll)); - ac->st_roll = orient->roll; - } - - return; - } - - case SMOOTH_PITCH: - { - if (isnan(ac->st_pitch) || isinf(ac->st_pitch)) - ac->st_pitch = 0.0f; - - if (((ac->st_pitch < 0) && (orient->pitch > 0)) || ((ac->st_pitch > 0) && (orient->pitch < 0))) { - ac->st_pitch = orient->pitch; - } else { - orient->pitch = ac->st_pitch + (ac->st_alpha * (orient->a_pitch - ac->st_pitch)); - ac->st_pitch = orient->pitch; - } - - return; - } - } -} diff --git a/cpp/wiiuse/src/dynamics.h b/cpp/wiiuse/src/dynamics.h deleted file mode 100644 index 2a8f965..0000000 --- a/cpp/wiiuse/src/dynamics.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Handles the dynamics of the wiimote. - * - * The file includes functions that handle the dynamics - * of the wiimote. Such dynamics include orientation and - * motion sensing. - */ - -#ifndef DYNAMICS_H_INCLUDED -#define DYNAMICS_H_INCLUDED - -#include "wiiuse_internal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct orient_t* orient, int smooth); -void calculate_gforce(struct accel_t* ac, struct vec3b_t* accel, struct gforce_t* gforce); -void calc_joystick_state(struct joystick_t* js, float x, float y); -void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type); - -#ifdef __cplusplus -} -#endif - -#endif // DYNAMICS_H_INCLUDED diff --git a/cpp/wiiuse/src/events.c b/cpp/wiiuse/src/events.c deleted file mode 100644 index e80a3d6..0000000 --- a/cpp/wiiuse/src/events.c +++ /dev/null @@ -1,907 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Handles wiimote events. - * - * The file includes functions that handle the events - * that are sent from the wiimote to us. - */ - -#include - -#ifndef WIN32 - #include - #include - #include -#else - #include -#endif - -#include -#include -#include - -#include "definitions.h" -#include "io.h" -#include "wiiuse_internal.h" -#include "dynamics.h" -#include "ir.h" -#include "nunchuk.h" -#include "classic.h" -#include "guitar_hero_3.h" -#include "balance_board.h" -#include "events.h" - -static void idle_cycle(struct wiimote_t* wm); -static void clear_dirty_reads(struct wiimote_t* wm); -static void propagate_event(struct wiimote_t* wm, byte event, byte* msg); -static void event_data_read(struct wiimote_t* wm, byte* msg); -static void event_status(struct wiimote_t* wm, byte* msg); -static void handle_expansion(struct wiimote_t* wm, byte* msg); - -static void save_state(struct wiimote_t* wm); -static int state_changed(struct wiimote_t* wm); - -/** - * @brief Poll the wiimotes for any events. - * - * @param wm An array of pointers to wiimote_t structures. - * @param wiimotes The number of wiimote_t structures in the \a wm array. - * - * @return Returns number of wiimotes that an event has occured on. - * - * It is necessary to poll the wiimote devices for events - * that occur. If an event occurs on a particular wiimote, - * the event variable will be set. - */ -int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { - int evnt = 0; - - #ifndef WIN32 - /* - * *nix - */ - struct timeval tv; - fd_set fds; - int r; - int i; - int highest_fd = -1; - - if (!wm) return 0; - - /* block select() for 1/2000th of a second */ - tv.tv_sec = 0; - tv.tv_usec = 500; - - FD_ZERO(&fds); - - for (i = 0; i < wiimotes; ++i) { - /* only poll it if it is connected */ - if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) { - FD_SET(wm[i]->in_sock, &fds); - - /* find the highest fd of the connected wiimotes */ - if (wm[i]->in_sock > highest_fd) - highest_fd = wm[i]->in_sock; - } - - wm[i]->event = WIIUSE_NONE; - } - - if (highest_fd == -1) - /* nothing to poll */ - return 0; - - if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) { - WIIUSE_ERROR("Unable to select() the wiimote interrupt socket(s)."); - perror("Error Details"); - return 0; - } - - /* check each socket for an event */ - for (i = 0; i < wiimotes; ++i) { - /* if this wiimote is not connected, skip it */ - if (!WIIMOTE_IS_CONNECTED(wm[i])) - continue; - - if (FD_ISSET(wm[i]->in_sock, &fds)) { - /* clear out the event buffer */ - memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); - - /* clear out any old read requests */ - clear_dirty_reads(wm[i]); - - /* read the pending message into the buffer */ - r = read(wm[i]->in_sock, wm[i]->event_buf, sizeof(wm[i]->event_buf)); - if (r == -1) { - /* error reading data */ - WIIUSE_ERROR("Receiving wiimote data (id %i).", wm[i]->unid); - perror("Error Details"); - - if (errno == ENOTCONN) { - /* this can happen if the bluetooth dongle is disconnected */ - WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm[i]->unid); - wiiuse_disconnect(wm[i]); - wm[i]->event = WIIUSE_UNEXPECTED_DISCONNECT; - } - - continue; - } - if (!r) { - /* remote disconnect */ - wiiuse_disconnected(wm[i]); - evnt = 1; - continue; - } - - /* propagate the event */ - propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); - evnt += (wm[i]->event != WIIUSE_NONE); - } else { - idle_cycle(wm[i]); - } - } - #else - /* - * Windows - */ - int i; - - if (!wm) return 0; - - for (i = 0; i < wiimotes; ++i) { - wm[i]->event = WIIUSE_NONE; - - if (wiiuse_io_read(wm[i])) { - /* propagate the event */ - propagate_event(wm[i], wm[i]->event_buf[0], wm[i]->event_buf+1); - evnt += (wm[i]->event != WIIUSE_NONE); - - /* clear out the event buffer */ - memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); - } else { - idle_cycle(wm[i]); - } - } - #endif - - return evnt; -} - - -/** - * @brief Called on a cycle where no significant change occurs. - * - * @param wm Pointer to a wiimote_t structure. - */ -static void idle_cycle(struct wiimote_t* wm) { - /* - * Smooth the angles. - * - * This is done to make sure that on every cycle the orientation - * angles are smoothed. Normally when an event occurs the angles - * are updated and smoothed, but if no packet comes in then the - * angles remain the same. This means the angle wiiuse reports - * is still an old value. Smoothing needs to be applied in this - * case in order for the angle it reports to converge to the true - * angle of the device. - */ - if (WIIUSE_USING_ACC(wm) && WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING)) { - apply_smoothing(&wm->accel_calib, &wm->orient, SMOOTH_ROLL); - apply_smoothing(&wm->accel_calib, &wm->orient, SMOOTH_PITCH); - } - - /* clear out any old read requests */ - clear_dirty_reads(wm); -} - - -/** - * @brief Clear out all old 'dirty' read requests. - * - * @param wm Pointer to a wiimote_t structure. - */ -static void clear_dirty_reads(struct wiimote_t* wm) { - struct read_req_t* req = wm->read_req; - - while (req && req->dirty) { - WIIUSE_DEBUG("Cleared old read request for address: %x", req->addr); - - wm->read_req = req->next; - free(req); - req = wm->read_req; - } -} - - -/** - * @brief Analyze the event that occured on a wiimote. - * - * @param wm An array of pointers to wiimote_t structures. - * @param event The event that occured. - * @param msg The message specified in the event packet. - * - * Pass the event to the registered event callback. - */ -static void propagate_event(struct wiimote_t* wm, byte event, byte* msg) { - save_state(wm); - - switch (event) { - case WM_RPT_BTN: - { - /* button */ - wiiuse_pressed_buttons(wm, msg); - break; - } - case WM_RPT_BTN_ACC: - { - /* button - motion */ - wiiuse_pressed_buttons(wm, msg); - - wm->accel.x = msg[2]; - wm->accel.y = msg[3]; - wm->accel.z = msg[4]; - - /* calculate the remote orientation */ - calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING)); - - /* calculate the gforces on each axis */ - calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce); - - break; - } - case WM_RPT_READ: - { - /* data read */ - event_data_read(wm, msg); - - /* yeah buttons may be pressed, but this wasn't an "event" */ - return; - } - case WM_RPT_CTRL_STATUS: - { - /* controller status */ - event_status(wm, msg); - - /* don't execute the event callback */ - return; - } - case WM_RPT_BTN_EXP: - { - /* button - expansion */ - wiiuse_pressed_buttons(wm, msg); - handle_expansion(wm, msg+2); - - break; - } - case WM_RPT_BTN_ACC_EXP: - { - /* button - motion - expansion */ - wiiuse_pressed_buttons(wm, msg); - - wm->accel.x = msg[2]; - wm->accel.y = msg[3]; - wm->accel.z = msg[4]; - - calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING)); - calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce); - - handle_expansion(wm, msg+5); - - break; - } - case WM_RPT_BTN_ACC_IR: - { - /* button - motion - ir */ - wiiuse_pressed_buttons(wm, msg); - - wm->accel.x = msg[2]; - wm->accel.y = msg[3]; - wm->accel.z = msg[4]; - - calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING)); - calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce); - - /* ir */ - calculate_extended_ir(wm, msg+5); - - break; - } - case WM_RPT_BTN_IR_EXP: - { - /* button - ir - expansion */ - wiiuse_pressed_buttons(wm, msg); - handle_expansion(wm, msg+12); - - /* ir */ - calculate_basic_ir(wm, msg+2); - - break; - } - case WM_RPT_BTN_ACC_IR_EXP: - { - /* button - motion - ir - expansion */ - wiiuse_pressed_buttons(wm, msg); - - wm->accel.x = msg[2]; - wm->accel.y = msg[3]; - wm->accel.z = msg[4]; - - calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING)); - calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce); - - handle_expansion(wm, msg+15); - - /* ir */ - calculate_basic_ir(wm, msg+5); - - break; - } - case WM_RPT_WRITE: - { - /* write feedback - safe to skip */ - break; - } - default: - { - WIIUSE_WARNING("Unknown event, can not handle it [Code 0x%x].", event); - return; - } - } - - /* was there an event? */ - if (state_changed(wm)) - wm->event = WIIUSE_EVENT; -} - - -/** - * @brief Find what buttons are pressed. - * - * @param wm Pointer to a wiimote_t structure. - * @param msg The message specified in the event packet. - */ -void wiiuse_pressed_buttons(struct wiimote_t* wm, byte* msg) { - short now; - - /* convert to big endian */ - now = BIG_ENDIAN_SHORT(*(short*)msg) & WIIMOTE_BUTTON_ALL; - - /* pressed now & were pressed, then held */ - wm->btns_held = (now & wm->btns); - - /* were pressed or were held & not pressed now, then released */ - wm->btns_released = ((wm->btns | wm->btns_held) & ~now); - - /* buttons pressed now */ - wm->btns = now; -} - - -/** - * @brief Received a data packet from a read request. - * - * @param wm Pointer to a wiimote_t structure. - * @param msg The message specified in the event packet. - * - * Data from the wiimote comes in packets. If the requested - * data segment size is bigger than one packet can hold then - * several packets will be received. These packets are first - * reassembled into one, then the registered callback function - * that handles data reads is invoked. - */ -static void event_data_read(struct wiimote_t* wm, byte* msg) { - /* we must always assume the packet received is from the most recent request */ - byte err; - byte len; - unsigned short offset; - struct read_req_t* req = wm->read_req; - - wiiuse_pressed_buttons(wm, msg); - - /* find the next non-dirty request */ - while (req && req->dirty) - req = req->next; - - /* if we don't have a request out then we didn't ask for this packet */ - if (!req) { - WIIUSE_WARNING("Received data packet when no request was made."); - return; - } - - err = msg[2] & 0x0F; - - if (err == 0x08) - WIIUSE_WARNING("Unable to read data - address does not exist."); - else if (err == 0x07) - WIIUSE_WARNING("Unable to read data - address is for write-only registers."); - else if (err) - WIIUSE_WARNING("Unable to read data - unknown error code %x.", err); - - if (err) { - /* this request errored out, so skip it and go to the next one */ - - /* delete this request */ - wm->read_req = req->next; - free(req); - - /* if another request exists send it to the wiimote */ - if (wm->read_req) - wiiuse_send_next_pending_read_request(wm); - - return; - } - - len = ((msg[2] & 0xF0) >> 4) + 1; - offset = BIG_ENDIAN_SHORT(*(unsigned short*)(msg + 3)); - req->addr = (req->addr & 0xFFFF); - - req->wait -= len; - if (req->wait >= req->size) - /* this should never happen */ - req->wait = 0; - - WIIUSE_DEBUG("Received read packet:"); - WIIUSE_DEBUG(" Packet read offset: %i bytes", offset); - WIIUSE_DEBUG(" Request read offset: %i bytes", req->addr); - WIIUSE_DEBUG(" Read offset into buf: %i bytes", offset - req->addr); - WIIUSE_DEBUG(" Read data size: %i bytes", len); - WIIUSE_DEBUG(" Still need: %i bytes", req->wait); - - /* reconstruct this part of the data */ - memcpy((req->buf + offset - req->addr), (msg + 5), len); - - #ifdef WITH_WIIUSE_DEBUG - { - int i = 0; - fprintf(stderr, "[DEBUG] Read: "); - for (; i < req->size - req->wait; ++i) - fprintf(stderr, "%x ", req->buf[i]); - fprintf(stderr, "\n"); - fflush(stderr); - } - #endif - - /* if all data has been received, execute the read event callback or generate event */ - if (!req->wait) { - if (req->cb) { - /* this was a callback, so invoke it now */ - req->cb(wm, req->buf, req->size); - - /* delete this request */ - wm->read_req = req->next; - free(req); - } else { - /* - * This should generate an event. - * We need to leave the event in the array so the client - * can access it still. We'll flag is as being 'dirty' - * and give the client one cycle to use it. Next event - * we will remove it from the list. - */ - wm->event = WIIUSE_READ_DATA; - req->dirty = 1; - } - - /* if another request exists send it to the wiimote */ - if (wm->read_req) - wiiuse_send_next_pending_read_request(wm); - } -} - - -/** - * @brief Read the controller status. - * - * @param wm Pointer to a wiimote_t structure. - * @param msg The message specified in the event packet. - * - * Read the controller status and execute the registered status callback. - */ -static void event_status(struct wiimote_t* wm, byte* msg) { - int led[4] = {0}; - int attachment = 0; - int ir = 0; - int exp_changed = 0; - - /* - * An event occured. - * This event can be overwritten by a more specific - * event type during a handshake or expansion removal. - */ - wm->event = WIIUSE_STATUS; - - wiiuse_pressed_buttons(wm, msg); - - /* find what LEDs are lit */ - if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_1) led[0] = 1; - if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_2) led[1] = 1; - if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_3) led[2] = 1; - if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_4) led[3] = 1; - - /* is an attachment connected to the expansion port? */ - if ((msg[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == WM_CTRL_STATUS_BYTE1_ATTACHMENT) - attachment = 1; - - /* is the speaker enabled? */ - if ((msg[2] & WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) == WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_SPEAKER); - - /* is IR sensing enabled? */ - if ((msg[2] & WM_CTRL_STATUS_BYTE1_IR_ENABLED) == WM_CTRL_STATUS_BYTE1_IR_ENABLED) - ir = 1; - - /* find the battery level and normalize between 0 and 1 */ - wm->battery_level = (msg[5] / (float)WM_MAX_BATTERY_CODE); - - /* expansion port */ - if (attachment && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) { - /* send the initialization code for the attachment */ - handshake_expansion(wm, NULL, 0); - exp_changed = 1; - } else if (!attachment && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) { - /* attachment removed */ - disable_expansion(wm); - exp_changed = 1; - } - - #ifdef WIN32 - if (!attachment) { - WIIUSE_DEBUG("Setting timeout to normal %i ms.", wm->normal_timeout); - wm->timeout = wm->normal_timeout; - } - #endif - - /* - * From now on the remote will only send status packets. - * We need to send a WIIMOTE_CMD_REPORT_TYPE packet to - * reenable other incoming reports. - */ - if (exp_changed && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { - /* - * Since the expansion status changed IR needs to - * be reset for the new IR report mode. - */ - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); - wiiuse_set_ir(wm, 1); - } else - wiiuse_set_report_type(wm); -} - - -/** - * @brief Handle data from the expansion. - * - * @param wm A pointer to a wiimote_t structure. - * @param msg The message specified in the event packet for the expansion. - */ -static void handle_expansion(struct wiimote_t* wm, byte* msg) { - switch (wm->exp.type) { - case EXP_NUNCHUK: - nunchuk_event(&wm->exp.nunchuk, msg); - break; - case EXP_CLASSIC: - classic_ctrl_event(&wm->exp.classic, msg); - break; - case EXP_GUITAR_HERO_3: - guitar_hero_3_event(&wm->exp.gh3, msg); - break; - case EXP_BALANCE_BOARD: - balance_board_event(&wm->exp.bb, msg); - break; - default: - break; - } -} - - -/** - * @brief Handle the handshake data from the expansion device. - * - * @param wm A pointer to a wiimote_t structure. - * @param data The data read in from the device. - * @param len The length of the data block, in bytes. - * - * Tries to determine what kind of expansion was attached - * and invoke the correct handshake function. - * - * If the data is NULL then this function will try to start - * a handshake with the expansion. - */ -void handshake_expansion(struct wiimote_t* wm, byte* data, unsigned short len) { - int id; - - if (!data) { - byte* handshake_buf; - byte buf = 0x55; - - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) - disable_expansion(wm); - - /* increase the timeout until the handshake completes */ - #ifdef WIN32 - WIIUSE_DEBUG("Setting timeout to expansion %i ms.", wm->exp_timeout); - wm->timeout = wm->exp_timeout; - #endif - - wiiuse_write_data(wm, WM_EXP_MEM_ENABLE1, &buf, 1); - buf = 0x00; - wiiuse_write_data(wm, WM_EXP_MEM_ENABLE2, &buf, 1); - - /* get the calibration data */ - handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); - wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); - - /* tell the wiimote to send expansion data */ - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP); - - return; - } - - id = BIG_ENDIAN_LONG(*(int*)(data + 220)); - - /* call the corresponding handshake function for this expansion */ - switch (id) { - case EXP_ID_CODE_NUNCHUK: - { - if (nunchuk_handshake(wm, &wm->exp.nunchuk, data, len)) - wm->event = WIIUSE_NUNCHUK_INSERTED; - break; - } - case EXP_ID_CODE_CLASSIC_CONTROLLER: - { - if (classic_ctrl_handshake(wm, &wm->exp.classic, data, len)) - wm->event = WIIUSE_CLASSIC_CTRL_INSERTED; - break; - } - case EXP_ID_CODE_GUITAR: - { - if (guitar_hero_3_handshake(wm, &wm->exp.gh3, data, len)) - wm->event = WIIUSE_GUITAR_HERO_3_CTRL_INSERTED; - break; - } - case EXP_ID_CODE_BALANCE_BOARD: - { - if (balance_board_handshake(wm, &wm->exp.bb, data, len)) - wm->event = WIIUSE_BALANCE_BOARD_CTRL_INSERTED; - break; - } - default: - { - WIIUSE_WARNING("Unknown expansion type. Code: 0x%x", id); - break; - } - } - - free(data); -} - - - -/** - * @brief Disable the expansion device if it was enabled. - * - * @param wm A pointer to a wiimote_t structure. - * @param data The data read in from the device. - * @param len The length of the data block, in bytes. - * - * If the data is NULL then this function will try to start - * a handshake with the expansion. - */ -void disable_expansion(struct wiimote_t* wm) { - if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) - return; - - /* tell the assoicated module the expansion was removed */ - switch (wm->exp.type) { - case EXP_NUNCHUK: - nunchuk_disconnected(&wm->exp.nunchuk); - wm->event = WIIUSE_NUNCHUK_REMOVED; - break; - case EXP_CLASSIC: - classic_ctrl_disconnected(&wm->exp.classic); - wm->event = WIIUSE_CLASSIC_CTRL_REMOVED; - break; - case EXP_GUITAR_HERO_3: - guitar_hero_3_disconnected(&wm->exp.gh3); - wm->event = WIIUSE_GUITAR_HERO_3_CTRL_REMOVED; - break; - case EXP_BALANCE_BOARD: - balance_board_disconnected(&wm->exp.bb); - wm->event = WIIUSE_BALANCE_BOARD_CTRL_REMOVED; - break; - default: - break; - } - - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP); - wm->exp.type = EXP_NONE; -} - - -/** - * @brief Save important state data. - * @param wm A pointer to a wiimote_t structure. - */ -static void save_state(struct wiimote_t* wm) { - /* wiimote */ - wm->lstate.btns = wm->btns; - wm->lstate.accel = wm->accel; - - /* ir */ - if (WIIUSE_USING_IR(wm)) { - wm->lstate.ir_ax = wm->ir.ax; - wm->lstate.ir_ay = wm->ir.ay; - wm->lstate.ir_distance = wm->ir.distance; - } - - /* expansion */ - switch (wm->exp.type) { - case EXP_NUNCHUK: - wm->lstate.exp_ljs_ang = wm->exp.nunchuk.js.ang; - wm->lstate.exp_ljs_mag = wm->exp.nunchuk.js.mag; - wm->lstate.exp_btns = wm->exp.nunchuk.btns; - wm->lstate.exp_accel = wm->exp.nunchuk.accel; - break; - - case EXP_CLASSIC: - wm->lstate.exp_ljs_ang = wm->exp.classic.ljs.ang; - wm->lstate.exp_ljs_mag = wm->exp.classic.ljs.mag; - wm->lstate.exp_rjs_ang = wm->exp.classic.rjs.ang; - wm->lstate.exp_rjs_mag = wm->exp.classic.rjs.mag; - wm->lstate.exp_r_shoulder = wm->exp.classic.r_shoulder; - wm->lstate.exp_l_shoulder = wm->exp.classic.l_shoulder; - wm->lstate.exp_btns = wm->exp.classic.btns; - break; - - case EXP_GUITAR_HERO_3: - wm->lstate.exp_ljs_ang = wm->exp.gh3.js.ang; - wm->lstate.exp_ljs_mag = wm->exp.gh3.js.mag; - wm->lstate.exp_r_shoulder = wm->exp.gh3.whammy_bar; - wm->lstate.exp_btns = wm->exp.gh3.btns; - break; - - case EXP_BALANCE_BOARD: - wm->lstate.exp_bb_raw = wm->exp.bb.raw; - break; - - case EXP_NONE: - break; - } -} - - -/** - * @brief Determine if the current state differs significantly from the previous. - * @param wm A pointer to a wiimote_t structure. - * @return 1 if a significant change occured, 0 if not. - */ -static int state_changed(struct wiimote_t* wm) { - #define STATE_CHANGED(a, b) if (a != b) return 1 - - #define CROSS_THRESH(last, now, thresh) \ - do { \ - if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) { \ - if ((diff_f(last.roll, now.roll) >= thresh) || \ - (diff_f(last.pitch, now.pitch) >= thresh) || \ - (diff_f(last.yaw, now.yaw) >= thresh)) \ - { \ - last = now; \ - return 1; \ - } \ - } else { \ - if (last.roll != now.roll) return 1; \ - if (last.pitch != now.pitch) return 1; \ - if (last.yaw != now.yaw) return 1; \ - } \ - } while (0) - - #define CROSS_THRESH_XYZ(last, now, thresh) \ - do { \ - if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) { \ - if ((diff_f(last.x, now.x) >= thresh) || \ - (diff_f(last.y, now.y) >= thresh) || \ - (diff_f(last.z, now.z) >= thresh)) \ - { \ - last = now; \ - return 1; \ - } \ - } else { \ - if (last.x != now.x) return 1; \ - if (last.y != now.y) return 1; \ - if (last.z != now.z) return 1; \ - } \ - } while (0) - - /* ir */ - if (WIIUSE_USING_IR(wm)) { - STATE_CHANGED(wm->lstate.ir_ax, wm->ir.ax); - STATE_CHANGED(wm->lstate.ir_ay, wm->ir.ay); - STATE_CHANGED(wm->lstate.ir_distance, wm->ir.distance); - } - - /* accelerometer */ - if (WIIUSE_USING_ACC(wm)) { - /* raw accelerometer */ - CROSS_THRESH_XYZ(wm->lstate.accel, wm->accel, wm->accel_threshold); - - /* orientation */ - CROSS_THRESH(wm->lstate.orient, wm->orient, wm->orient_threshold); - } - - /* expansion */ - switch (wm->exp.type) { - case EXP_NUNCHUK: - { - STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang); - STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag); - STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns); - - CROSS_THRESH(wm->lstate.exp_orient, wm->exp.nunchuk.orient, wm->exp.nunchuk.orient_threshold); - CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold); - break; - } - case EXP_CLASSIC: - { - STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang); - STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag); - STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang); - STATE_CHANGED(wm->lstate.exp_rjs_mag, wm->exp.classic.rjs.mag); - STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.classic.r_shoulder); - STATE_CHANGED(wm->lstate.exp_l_shoulder, wm->exp.classic.l_shoulder); - STATE_CHANGED(wm->lstate.exp_btns, wm->exp.classic.btns); - break; - } - case EXP_GUITAR_HERO_3: - { - STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.gh3.js.ang); - STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.gh3.js.mag); - STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.gh3.whammy_bar); - STATE_CHANGED(wm->lstate.exp_btns, wm->exp.gh3.btns); - break; - } - case EXP_BALANCE_BOARD: - { - STATE_CHANGED(wm->lstate.exp_bb_raw.tr, wm->exp.bb.raw.tr); - STATE_CHANGED(wm->lstate.exp_bb_raw.br, wm->exp.bb.raw.br); - STATE_CHANGED(wm->lstate.exp_bb_raw.tl, wm->exp.bb.raw.tl); - STATE_CHANGED(wm->lstate.exp_bb_raw.bl, wm->exp.bb.raw.bl); - break; - } - case EXP_NONE: - { - break; - } - } - - STATE_CHANGED(wm->lstate.btns, wm->btns); - - return 0; -} diff --git a/cpp/wiiuse/src/events.h b/cpp/wiiuse/src/events.h deleted file mode 100644 index 5e9b955..0000000 --- a/cpp/wiiuse/src/events.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Handles wiimote events. - * - * The file includes functions that handle the events - * that are sent from the wiimote to us. - */ - -#ifndef EVENTS_H_INCLUDED -#define EVENTS_H_INCLUDED - -#ifdef __cplusplus -extern "C" { -#endif - -void wiiuse_pressed_buttons(struct wiimote_t* wm, byte* msg); - -void handshake_expansion(struct wiimote_t* wm, byte* data, unsigned short len); -void disable_expansion(struct wiimote_t* wm); - -#ifdef __cplusplus -} -#endif - - -#endif // EVENTS_H_INCLUDED diff --git a/cpp/wiiuse/src/guitar_hero_3.c b/cpp/wiiuse/src/guitar_hero_3.c deleted file mode 100644 index 5837dc0..0000000 --- a/cpp/wiiuse/src/guitar_hero_3.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Guitar Hero 3 expansion device. - */ - -#include -#include -#include - -#ifdef WIN32 - #include -#endif - -#include "definitions.h" -#include "wiiuse_internal.h" -#include "dynamics.h" -#include "events.h" -#include "guitar_hero_3.h" - -static void guitar_hero_3_pressed_buttons(struct guitar_hero_3_t* gh3, short now); - -/** - * @brief Handle the handshake data from the guitar. - * - * @param cc A pointer to a classic_ctrl_t structure. - * @param data The data read in from the device. - * @param len The length of the data block, in bytes. - * - * @return Returns 1 if handshake was successful, 0 if not. - */ -int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len) { - int i; - int offset = 0; - - /* - * The good fellows that made the Guitar Hero 3 controller - * failed to factory calibrate the devices. There is no - * calibration data on the device. - */ - - gh3->btns = 0; - gh3->btns_held = 0; - gh3->btns_released = 0; - gh3->whammy_bar = 0.0f; - - /* decrypt data */ - for (i = 0; i < len; ++i) - data[i] = (data[i] ^ 0x17) + 0x17; - - if (data[offset] == 0xFF) { - /* - * Sometimes the data returned here is not correct. - * This might happen because the wiimote is lagging - * behind our initialization sequence. - * To fix this just request the handshake again. - * - * Other times it's just the first 16 bytes are 0xFF, - * but since the next 16 bytes are the same, just use - * those. - */ - if (data[offset + 16] == 0xFF) { - /* get the calibration data */ - byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); - - WIIUSE_DEBUG("Guitar Hero 3 handshake appears invalid, trying again."); - wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); - - return 0; - } else - offset += 16; - } - - /* joystick stuff */ - gh3->js.max.x = GUITAR_HERO_3_JS_MAX_X; - gh3->js.min.x = GUITAR_HERO_3_JS_MIN_X; - gh3->js.center.x = GUITAR_HERO_3_JS_CENTER_X; - gh3->js.max.y = GUITAR_HERO_3_JS_MAX_Y; - gh3->js.min.y = GUITAR_HERO_3_JS_MIN_Y; - gh3->js.center.y = GUITAR_HERO_3_JS_CENTER_Y; - - /* handshake done */ - wm->exp.type = EXP_GUITAR_HERO_3; - - #ifdef WIN32 - wm->timeout = WIIMOTE_DEFAULT_TIMEOUT; - #endif - - return 1; -} - - -/** - * @brief The guitar disconnected. - * - * @param cc A pointer to a classic_ctrl_t structure. - */ -void guitar_hero_3_disconnected(struct guitar_hero_3_t* gh3) { - memset(gh3, 0, sizeof(struct guitar_hero_3_t)); -} - - - -/** - * @brief Handle guitar event. - * - * @param cc A pointer to a classic_ctrl_t structure. - * @param msg The message specified in the event packet. - */ -void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg) { - int i; - - /* decrypt data */ - for (i = 0; i < 6; ++i) - msg[i] = (msg[i] ^ 0x17) + 0x17; - - guitar_hero_3_pressed_buttons(gh3, BIG_ENDIAN_SHORT(*(short*)(msg + 4))); - - /* whammy bar */ - gh3->whammy_bar = (msg[3] - GUITAR_HERO_3_WHAMMY_BAR_MIN) / (float)(GUITAR_HERO_3_WHAMMY_BAR_MAX - GUITAR_HERO_3_WHAMMY_BAR_MIN); - - /* joy stick */ - calc_joystick_state(&gh3->js, msg[0], msg[1]); -} - - -/** - * @brief Find what buttons are pressed. - * - * @param cc A pointer to a classic_ctrl_t structure. - * @param msg The message byte specified in the event packet. - */ -static void guitar_hero_3_pressed_buttons(struct guitar_hero_3_t* gh3, short now) { - /* message is inverted (0 is active, 1 is inactive) */ - now = ~now & GUITAR_HERO_3_BUTTON_ALL; - - /* pressed now & were pressed, then held */ - gh3->btns_held = (now & gh3->btns); - - /* were pressed or were held & not pressed now, then released */ - gh3->btns_released = ((gh3->btns | gh3->btns_held) & ~now); - - /* buttons pressed now */ - gh3->btns = now; -} diff --git a/cpp/wiiuse/src/guitar_hero_3.h b/cpp/wiiuse/src/guitar_hero_3.h deleted file mode 100644 index 024d603..0000000 --- a/cpp/wiiuse/src/guitar_hero_3.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Guitar Hero 3 expansion device. - */ - -#ifndef GUITAR_HERO_3_H_INCLUDED -#define GUITAR_HERO_3_H_INCLUDED - -#include "wiiuse_internal.h" - -#define GUITAR_HERO_3_JS_MIN_X 0xC5 -#define GUITAR_HERO_3_JS_MAX_X 0xFC -#define GUITAR_HERO_3_JS_CENTER_X 0xE0 -#define GUITAR_HERO_3_JS_MIN_Y 0xC5 -#define GUITAR_HERO_3_JS_MAX_Y 0xFA -#define GUITAR_HERO_3_JS_CENTER_Y 0xE0 -#define GUITAR_HERO_3_WHAMMY_BAR_MIN 0xEF -#define GUITAR_HERO_3_WHAMMY_BAR_MAX 0xFA - -#ifdef __cplusplus -extern "C" { -#endif - -int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len); - -void guitar_hero_3_disconnected(struct guitar_hero_3_t* gh3); - -void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg); - -#ifdef __cplusplus -} -#endif - -#endif // GUITAR_HERO_3_H_INCLUDED diff --git a/cpp/wiiuse/src/io.c b/cpp/wiiuse/src/io.c deleted file mode 100644 index ae420b9..0000000 --- a/cpp/wiiuse/src/io.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Handles device I/O (non-OS specific). - */ - -#include -#include - -#include "definitions.h" -#include "wiiuse_internal.h" -#include "io.h" - - - /** - * @brief Get initialization data from the wiimote. - * - * @param wm Pointer to a wiimote_t structure. - * @param data unused - * @param len unused - * - * When first called for a wiimote_t structure, a request - * is sent to the wiimote for initialization information. - * This includes factory set accelerometer data. - * The handshake will be concluded when the wiimote responds - * with this data. - */ -void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len) { - if (!wm) return; - - switch (wm->handshake_state) { - case 0: - { - /* send request to wiimote for accelerometer calibration */ - byte* buf; - - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); - wiiuse_set_leds(wm, WIIMOTE_LED_NONE); - - buf = (byte*)malloc(sizeof(byte) * 8); - wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7); - wm->handshake_state++; - - wiiuse_set_leds(wm, WIIMOTE_LED_NONE); - - break; - } - case 1: - { - struct read_req_t* req = wm->read_req; - struct accel_t* accel = &wm->accel_calib; - - /* received read data */ - accel->cal_zero.x = req->buf[0]; - accel->cal_zero.y = req->buf[1]; - accel->cal_zero.z = req->buf[2]; - - accel->cal_g.x = req->buf[4] - accel->cal_zero.x; - accel->cal_g.y = req->buf[5] - accel->cal_zero.y; - accel->cal_g.z = req->buf[6] - accel->cal_zero.z; - - /* done with the buffer */ - free(req->buf); - - /* handshake is done */ - WIIUSE_DEBUG("Handshake finished. Calibration: Idle: X=%x Y=%x Z=%x\t+1g: X=%x Y=%x Z=%x", - accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z, - accel->cal_g.x, accel->cal_g.y, accel->cal_g.z); - - - /* request the status of the wiimote to see if there is an expansion */ - wiiuse_status(wm); - - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE); - wm->handshake_state++; - - /* now enable IR if it was set before the handshake completed */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { - WIIUSE_DEBUG("Handshake finished, enabling IR."); - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); - wiiuse_set_ir(wm, 1); - } - - break; - } - default: - { - break; - } - } -} diff --git a/cpp/wiiuse/src/io.h b/cpp/wiiuse/src/io.h deleted file mode 100644 index 7a683e4..0000000 --- a/cpp/wiiuse/src/io.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Handles device I/O. - */ - -#ifndef CONNECT_H_INCLUDED -#define CONNECT_H_INCLUDED - -#ifndef WIN32 - #include -#endif - -#include "wiiuse_internal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len); - -int wiiuse_io_read(struct wiimote_t* wm); -int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len); - -#ifdef __cplusplus -} -#endif - -#endif // CONNECT_H_INCLUDED diff --git a/cpp/wiiuse/src/io_nix.c b/cpp/wiiuse/src/io_nix.c deleted file mode 100644 index ec4e0e1..0000000 --- a/cpp/wiiuse/src/io_nix.c +++ /dev/null @@ -1,270 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Handles device I/O for *nix. - */ - -#ifndef WIN32 - -#include -#include -#include - -#include -#include -#include -#include - -#include "definitions.h" -#include "wiiuse_internal.h" -#include "io.h" - -static int wiiuse_connect_single(struct wiimote_t* wm, char* address); - -/** - * @brief Find a wiimote or wiimotes. - * - * @param wm An array of wiimote_t structures. - * @param max_wiimotes The number of wiimote structures in \a wm. - * @param timeout The number of seconds before the search times out. - * - * @return The number of wiimotes found. - * - * @see wiimote_connect() - * - * This function will only look for wiimote devices. \n - * When a device is found the address in the structures will be set. \n - * You can then call wiimote_connect() to connect to the found \n - * devices. - */ -int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { - int device_id; - int device_sock; - int found_devices; - int found_wiimotes; - - /* reset all wiimote bluetooth device addresses */ - for (found_wiimotes = 0; found_wiimotes < max_wiimotes; ++found_wiimotes) - wm[found_wiimotes]->bdaddr = *BDADDR_ANY; - found_wiimotes = 0; - - /* get the id of the first bluetooth device. */ - device_id = hci_get_route(NULL); - if (device_id < 0) { - perror("hci_get_route"); - return 0; - } - - /* create a socket to the device */ - device_sock = hci_open_dev(device_id); - if (device_sock < 0) { - perror("hci_open_dev"); - return 0; - } - - inquiry_info scan_info_arr[128]; - inquiry_info* scan_info = scan_info_arr; - memset(&scan_info_arr, 0, sizeof(scan_info_arr)); - - /* scan for bluetooth devices for 'timeout' seconds */ - found_devices = hci_inquiry(device_id, timeout, 128, NULL, &scan_info, IREQ_CACHE_FLUSH); - if (found_devices < 0) { - perror("hci_inquiry"); - return 0; - } - - WIIUSE_INFO("Found %i bluetooth device(s).", found_devices); - - int i = 0; - - /* display discovered devices */ - for (; (i < found_devices) && (found_wiimotes < max_wiimotes); ++i) { - if ((scan_info[i].dev_class[0] == WM_DEV_CLASS_0) && - (scan_info[i].dev_class[1] == WM_DEV_CLASS_1) && - (scan_info[i].dev_class[2] == WM_DEV_CLASS_2)) - { - /* found a device */ - ba2str(&scan_info[i].bdaddr, wm[found_wiimotes]->bdaddr_str); - - WIIUSE_INFO("Found wiimote (%s) [id %i].", wm[found_wiimotes]->bdaddr_str, wm[found_wiimotes]->unid); - - wm[found_wiimotes]->bdaddr = scan_info[i].bdaddr; - WIIMOTE_ENABLE_STATE(wm[found_wiimotes], WIIMOTE_STATE_DEV_FOUND); - ++found_wiimotes; - } - } - - close(device_sock); - return found_wiimotes; -} - - -/** - * @brief Connect to a wiimote or wiimotes once an address is known. - * - * @param wm An array of wiimote_t structures. - * @param wiimotes The number of wiimote structures in \a wm. - * - * @return The number of wiimotes that successfully connected. - * - * @see wiiuse_find() - * @see wiiuse_connect_single() - * @see wiiuse_disconnect() - * - * Connect to a number of wiimotes when the address is already set - * in the wiimote_t structures. These addresses are normally set - * by the wiiuse_find() function, but can also be set manually. - */ -int wiiuse_connect(struct wiimote_t** wm, int wiimotes) { - int connected = 0; - int i = 0; - - for (; i < wiimotes; ++i) { - if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND)) - /* if the device address is not set, skip it */ - continue; - - if (wiiuse_connect_single(wm[i], NULL)) - ++connected; - } - - return connected; -} - - -/** - * @brief Connect to a wiimote with a known address. - * - * @param wm Pointer to a wiimote_t structure. - * @param address The address of the device to connect to. - * If NULL, use the address in the struct set by wiiuse_find(). - * - * @return 1 on success, 0 on failure - */ -static int wiiuse_connect_single(struct wiimote_t* wm, char* address) { - struct sockaddr_l2 addr; - - if (!wm || WIIMOTE_IS_CONNECTED(wm)) - return 0; - - addr.l2_family = AF_BLUETOOTH; - - if (address) - /* use provided address */ - str2ba(address, &addr.l2_bdaddr); - else - /* use address of device discovered */ - addr.l2_bdaddr = wm->bdaddr; - - /* - * OUTPUT CHANNEL - */ - wm->out_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); - if (wm->out_sock == -1) - return 0; - - addr.l2_psm = htobs(WM_OUTPUT_CHANNEL); - - /* connect to wiimote */ - if (connect(wm->out_sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) { - perror("connect() output sock"); - return 0; - } - - /* - * INPUT CHANNEL - */ - wm->in_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); - if (wm->in_sock == -1) { - close(wm->out_sock); - wm->out_sock = -1; - return 0; - } - - addr.l2_psm = htobs(WM_INPUT_CHANNEL); - - /* connect to wiimote */ - if (connect(wm->in_sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) { - perror("connect() interrupt sock"); - close(wm->out_sock); - wm->out_sock = -1; - return 0; - } - - WIIUSE_INFO("Connected to wiimote [id %i].", wm->unid); - - /* do the handshake */ - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); - wiiuse_handshake(wm, NULL, 0); - - wiiuse_set_report_type(wm); - - return 1; -} - - -/** - * @brief Disconnect a wiimote. - * - * @param wm Pointer to a wiimote_t structure. - * - * @see wiiuse_connect() - * - * Note that this will not free the wiimote structure. - */ -void wiiuse_disconnect(struct wiimote_t* wm) { - if (!wm || WIIMOTE_IS_CONNECTED(wm)) - return; - - close(wm->out_sock); - close(wm->in_sock); - - wm->out_sock = -1; - wm->in_sock = -1; - wm->event = WIIUSE_NONE; - - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); -} - - -int wiiuse_io_read(struct wiimote_t* wm) { - /* not used */ - return 0; -} - - -int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { - return write(wm->out_sock, buf, len); -} - - - -#endif /* ifndef WIN32 */ diff --git a/cpp/wiiuse/src/io_win.c b/cpp/wiiuse/src/io_win.c deleted file mode 100644 index 6b77ca0..0000000 --- a/cpp/wiiuse/src/io_win.c +++ /dev/null @@ -1,247 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Handles device I/O for Windows. - */ - -#ifdef WIN32 - -#include -#include - -#include -#include -#include - -#include "definitions.h" -#include "wiiuse_internal.h" -#include "io.h" - - -int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { - GUID device_id; - HANDLE dev; - HDEVINFO device_info; - int i, index; - DWORD len; - SP_DEVICE_INTERFACE_DATA device_data; - PSP_DEVICE_INTERFACE_DETAIL_DATA detail_data = NULL; - HIDD_ATTRIBUTES attr; - int found = 0; - - (void) timeout; // unused - - device_data.cbSize = sizeof(device_data); - index = 0; - - /* get the device id */ - HidD_GetHidGuid(&device_id); - - /* get all hid devices connected */ - device_info = SetupDiGetClassDevs(&device_id, NULL, NULL, (DIGCF_DEVICEINTERFACE | DIGCF_PRESENT)); - - for (;; ++index) { - - if (detail_data) { - free(detail_data); - detail_data = NULL; - } - - /* query the next hid device info */ - if (!SetupDiEnumDeviceInterfaces(device_info, NULL, &device_id, index, &device_data)) - break; - - /* get the size of the data block required */ - i = SetupDiGetDeviceInterfaceDetail(device_info, &device_data, NULL, 0, &len, NULL); - detail_data = malloc(len); - detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); - - /* query the data for this device */ - if (!SetupDiGetDeviceInterfaceDetail(device_info, &device_data, detail_data, len, NULL, NULL)) - continue; - - /* open the device */ - dev = CreateFile(detail_data->DevicePath, - (GENERIC_READ | GENERIC_WRITE), - (FILE_SHARE_READ | FILE_SHARE_WRITE), - NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); - if (dev == INVALID_HANDLE_VALUE) - continue; - - /* get device attributes */ - attr.Size = sizeof(attr); - i = HidD_GetAttributes(dev, &attr); - - if ((attr.VendorID == WM_VENDOR_ID) && (attr.ProductID == WM_PRODUCT_ID)) { - /* this is a wiimote */ - wm[found]->dev_handle = dev; - - wm[found]->hid_overlap.hEvent = CreateEvent(NULL, 1, 1, ""); - wm[found]->hid_overlap.Offset = 0; - wm[found]->hid_overlap.OffsetHigh = 0; - - WIIMOTE_ENABLE_STATE(wm[found], WIIMOTE_STATE_DEV_FOUND); - WIIMOTE_ENABLE_STATE(wm[found], WIIMOTE_STATE_CONNECTED); - - /* try to set the output report to see if the device is actually connected */ - if (!wiiuse_set_report_type(wm[found])) { - WIIMOTE_DISABLE_STATE(wm[found], WIIMOTE_STATE_CONNECTED); - continue; - } - - /* do the handshake */ - wiiuse_handshake(wm[found], NULL, 0); - - WIIUSE_INFO("Connected to wiimote [id %i].", wm[found]->unid); - - ++found; - if (found >= max_wiimotes) - break; - } else { - /* not a wiimote */ - CloseHandle(dev); - } - } - - if (detail_data) - free(detail_data); - - SetupDiDestroyDeviceInfoList(device_info); - - return found; -} - - -int wiiuse_connect(struct wiimote_t** wm, int wiimotes) { - int connected = 0; - int i = 0; - - for (; i < wiimotes; ++i) { - if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) - ++connected; - } - - return connected; -} - - -void wiiuse_disconnect(struct wiimote_t* wm) { - if (!wm || WIIMOTE_IS_CONNECTED(wm)) - return; - - CloseHandle(wm->dev_handle); - wm->dev_handle = 0; - - ResetEvent(&wm->hid_overlap); - - wm->event = WIIUSE_NONE; - - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); -} - - -int wiiuse_io_read(struct wiimote_t* wm) { - DWORD b, r; - - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) - return 0; - - if (!ReadFile(wm->dev_handle, wm->event_buf, sizeof(wm->event_buf), &b, &wm->hid_overlap)) { - /* partial read */ - b = GetLastError(); - - if ((b == ERROR_HANDLE_EOF) || (b == ERROR_DEVICE_NOT_CONNECTED)) { - /* remote disconnect */ - wiiuse_disconnected(wm); - return 0; - } - - r = WaitForSingleObject(wm->hid_overlap.hEvent, wm->timeout); - if (r == WAIT_TIMEOUT) { - /* timeout - cancel and continue */ - - if (*wm->event_buf) - WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout); - - CancelIo(wm->dev_handle); - ResetEvent(wm->hid_overlap.hEvent); - return 0; - } else if (r == WAIT_FAILED) { - WIIUSE_WARNING("A wait error occured on reading from wiimote %i.", wm->unid); - return 0; - } - - if (!GetOverlappedResult(wm->dev_handle, &wm->hid_overlap, &b, 0)) - return 0; - } - - ResetEvent(wm->hid_overlap.hEvent); - return 1; -} - - -int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { - DWORD bytes; - int i; - - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) - return 0; - - switch (wm->stack) { - case WIIUSE_STACK_UNKNOWN: - { - /* try to auto-detect the stack type */ - if ((i = WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap))) { - /* bluesoleil will always return 1 here, even if it's not connected */ - wm->stack = WIIUSE_STACK_BLUESOLEIL; - return i; - } - - if ((i = HidD_SetOutputReport(wm->dev_handle, buf, len))) { - wm->stack = WIIUSE_STACK_MS; - return i; - } - - WIIUSE_ERROR("Unable to determine bluetooth stack type."); - return 0; - } - - case WIIUSE_STACK_MS: - return HidD_SetOutputReport(wm->dev_handle, buf, len); - - case WIIUSE_STACK_BLUESOLEIL: - return WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap); - } - - return 0; -} - -#endif /* ifdef WIN32 */ diff --git a/cpp/wiiuse/src/ir.c b/cpp/wiiuse/src/ir.c deleted file mode 100644 index 4cc2e2d..0000000 --- a/cpp/wiiuse/src/ir.c +++ /dev/null @@ -1,747 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Handles IR data. - */ - -#include -#include - -#ifndef WIN32 - #include -#endif - -#include "definitions.h" -#include "wiiuse_internal.h" -#include "ir.h" - -static int get_ir_sens(struct wiimote_t* wm, char** block1, char** block2); -static void interpret_ir_data(struct wiimote_t* wm); -static void fix_rotated_ir_dots(struct ir_dot_t* dot, float ang); -static void get_ir_dot_avg(struct ir_dot_t* dot, int* x, int* y); -static void reorder_ir_dots(struct ir_dot_t* dot); -static float ir_distance(struct ir_dot_t* dot); -static int ir_correct_for_bounds(int* x, int* y, enum aspect_t aspect, int offset_x, int offset_y); -static void ir_convert_to_vres(int* x, int* y, enum aspect_t aspect, int vx, int vy); - - -/** - * @brief Set if the wiimote should track IR targets. - * - * @param wm Pointer to a wiimote_t structure. - * @param status 1 to enable, 0 to disable. - */ -void wiiuse_set_ir(struct wiimote_t* wm, int status) { - byte buf; - char* block1 = NULL; - char* block2 = NULL; - int ir_level; - - if (!wm) - return; - - /* - * Wait for the handshake to finish first. - * When it handshake finishes and sees that - * IR is enabled, it will call this function - * again to actually enable IR. - */ - if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE)) { - WIIUSE_DEBUG("Tried to enable IR, will wait until handshake finishes."); - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR); - return; - } - - /* - * Check to make sure a sensitivity setting is selected. - */ - ir_level = get_ir_sens(wm, &block1, &block2); - if (!ir_level) { - WIIUSE_ERROR("No IR sensitivity setting selected."); - return; - } - - if (status) { - /* if already enabled then stop */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) - return; - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR); - } else { - /* if already disabled then stop */ - if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) - return; - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); - } - - /* set camera 1 and 2 */ - buf = (status ? 0x04 : 0x00); - wiiuse_send(wm, WM_CMD_IR, &buf, 1); - wiiuse_send(wm, WM_CMD_IR_2, &buf, 1); - - if (!status) { - WIIUSE_DEBUG("Disabled IR cameras for wiimote id %i.", wm->unid); - wiiuse_set_report_type(wm); - return; - } - - /* enable IR, set sensitivity */ - buf = 0x08; - wiiuse_write_data(wm, WM_REG_IR, &buf, 1); - - /* wait for the wiimote to catch up */ - #ifndef WIN32 - usleep(50000); - #else - Sleep(50); - #endif - - /* write sensitivity blocks */ - wiiuse_write_data(wm, WM_REG_IR_BLOCK1, (byte*)block1, 9); - wiiuse_write_data(wm, WM_REG_IR_BLOCK2, (byte*)block2, 2); - - /* set the IR mode */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) - buf = WM_IR_TYPE_BASIC; - else - buf = WM_IR_TYPE_EXTENDED; - wiiuse_write_data(wm, WM_REG_IR_MODENUM, &buf, 1); - - #ifndef WIN32 - usleep(50000); - #else - Sleep(50); - #endif - - /* set the wiimote report type */ - wiiuse_set_report_type(wm); - - WIIUSE_DEBUG("Enabled IR camera for wiimote id %i (sensitivity level %i).", wm->unid, ir_level); -} - - -/** - * @brief Get the IR sensitivity settings. - * - * @param wm Pointer to a wiimote_t structure. - * @param block1 [out] Pointer to where block1 will be set. - * @param block2 [out] Pointer to where block2 will be set. - * - * @return Returns the sensitivity level. - */ -static int get_ir_sens(struct wiimote_t* wm, char** block1, char** block2) { - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL1)) { - *block1 = WM_IR_BLOCK1_LEVEL1; - *block2 = WM_IR_BLOCK2_LEVEL1; - return 1; - } else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL2)) { - *block1 = WM_IR_BLOCK1_LEVEL2; - *block2 = WM_IR_BLOCK2_LEVEL2; - return 2; - } else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL3)) { - *block1 = WM_IR_BLOCK1_LEVEL3; - *block2 = WM_IR_BLOCK2_LEVEL3; - return 3; - } else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL4)) { - *block1 = WM_IR_BLOCK1_LEVEL4; - *block2 = WM_IR_BLOCK2_LEVEL4; - return 4; - } else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL5)) { - *block1 = WM_IR_BLOCK1_LEVEL5; - *block2 = WM_IR_BLOCK2_LEVEL5; - return 5; - } - - *block1 = NULL; - *block2 = NULL; - return 0; -} - - -/** - * @brief Set the virtual screen resolution for IR tracking. - * - * @param wm Pointer to a wiimote_t structure. - * @param status 1 to enable, 0 to disable. - */ -void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y) { - if (!wm) return; - - wm->ir.vres[0] = (x-1); - wm->ir.vres[1] = (y-1); -} - - -/** - * @brief Set the XY position for the IR cursor. - * - * @param wm Pointer to a wiimote_t structure. - */ -void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) { - if (!wm) return; - - wm->ir.pos = pos; - - switch (pos) { - - case WIIUSE_IR_ABOVE: - wm->ir.offset[0] = 0; - - if (wm->ir.aspect == WIIUSE_ASPECT_16_9) - wm->ir.offset[1] = WM_ASPECT_16_9_Y/2 - 70; - else if (wm->ir.aspect == WIIUSE_ASPECT_4_3) - wm->ir.offset[1] = WM_ASPECT_4_3_Y/2 - 100; - - return; - - case WIIUSE_IR_BELOW: - wm->ir.offset[0] = 0; - - if (wm->ir.aspect == WIIUSE_ASPECT_16_9) - wm->ir.offset[1] = -WM_ASPECT_16_9_Y/2 + 100; - else if (wm->ir.aspect == WIIUSE_ASPECT_4_3) - wm->ir.offset[1] = -WM_ASPECT_4_3_Y/2 + 70; - - return; - - default: - return; - }; -} - - -/** - * @brief Set the aspect ratio of the TV/monitor. - * - * @param wm Pointer to a wiimote_t structure. - * @param aspect Either WIIUSE_ASPECT_16_9 or WIIUSE_ASPECT_4_3 - */ -void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect) { - if (!wm) return; - - wm->ir.aspect = aspect; - - if (aspect == WIIUSE_ASPECT_4_3) { - wm->ir.vres[0] = WM_ASPECT_4_3_X; - wm->ir.vres[1] = WM_ASPECT_4_3_Y; - } else { - wm->ir.vres[0] = WM_ASPECT_16_9_X; - wm->ir.vres[1] = WM_ASPECT_16_9_Y; - } - - /* reset the position offsets */ - wiiuse_set_ir_position(wm, wm->ir.pos); -} - - -/** - * @brief Set the IR sensitivity. - * - * @param wm Pointer to a wiimote_t structure. - * @param level 1-5, same as Wii system sensitivity setting. - * - * If the level is < 1, then level will be set to 1. - * If the level is > 5, then level will be set to 5. - */ -void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level) { - char* block1 = NULL; - char* block2 = NULL; - - if (!wm) return; - - if (level > 5) level = 5; - if (level < 1) level = 1; - - WIIMOTE_DISABLE_STATE(wm, (WIIMOTE_STATE_IR_SENS_LVL1 | - WIIMOTE_STATE_IR_SENS_LVL2 | - WIIMOTE_STATE_IR_SENS_LVL3 | - WIIMOTE_STATE_IR_SENS_LVL4 | - WIIMOTE_STATE_IR_SENS_LVL5)); - - switch (level) { - case 1: - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL1); - break; - case 2: - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL2); - break; - case 3: - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL3); - break; - case 4: - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL4); - break; - case 5: - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL5); - break; - default: - return; - } - - /* set the new sensitivity */ - get_ir_sens(wm, &block1, &block2); - - wiiuse_write_data(wm, WM_REG_IR_BLOCK1, (byte*)block1, 9); - wiiuse_write_data(wm, WM_REG_IR_BLOCK2, (byte*)block2, 2); - - WIIUSE_DEBUG("Set IR sensitivity to level %i (unid %i)", level, wm->unid); -} - - -/** - * @brief Calculate the data from the IR spots. Basic IR mode. - * - * @param wm Pointer to a wiimote_t structure. - * @param data Data returned by the wiimote for the IR spots. - */ -void calculate_basic_ir(struct wiimote_t* wm, byte* data) { - struct ir_dot_t* dot = wm->ir.dot; - int i; - - dot[0].rx = 1023 - (data[0] | ((data[2] & 0x30) << 4)); - dot[0].ry = data[1] | ((data[2] & 0xC0) << 2); - - dot[1].rx = 1023 - (data[3] | ((data[2] & 0x03) << 8)); - dot[1].ry = data[4] | ((data[2] & 0x0C) << 6); - - dot[2].rx = 1023 - (data[5] | ((data[7] & 0x30) << 4)); - dot[2].ry = data[6] | ((data[7] & 0xC0) << 2); - - dot[3].rx = 1023 - (data[8] | ((data[7] & 0x03) << 8)); - dot[3].ry = data[9] | ((data[7] & 0x0C) << 6); - - /* set each IR spot to visible if spot is in range */ - for (i = 0; i < 4; ++i) { - if (dot[i].ry == 1023) - dot[i].visible = 0; - else { - dot[i].visible = 1; - dot[i].size = 0; /* since we don't know the size, set it as 0 */ - } - } - - interpret_ir_data(wm); -} - - -/** - * @brief Calculate the data from the IR spots. Extended IR mode. - * - * @param wm Pointer to a wiimote_t structure. - * @param data Data returned by the wiimote for the IR spots. - */ -void calculate_extended_ir(struct wiimote_t* wm, byte* data) { - struct ir_dot_t* dot = wm->ir.dot; - int i; - - for (i = 0; i < 4; ++i) { - dot[i].rx = 1023 - (data[3*i] | ((data[(3*i)+2] & 0x30) << 4)); - dot[i].ry = data[(3*i)+1] | ((data[(3*i)+2] & 0xC0) << 2); - - dot[i].size = data[(3*i)+2] & 0x0F; - - /* if in range set to visible */ - if (dot[i].ry == 1023) - dot[i].visible = 0; - else - dot[i].visible = 1; - } - - interpret_ir_data(wm); -} - - -/** - * @brief Interpret IR data into more user friendly variables. - * - * @param wm Pointer to a wiimote_t structure. - */ -static void interpret_ir_data(struct wiimote_t* wm) { - struct ir_dot_t* dot = wm->ir.dot; - int i; - float roll = 0.0f; - int last_num_dots = wm->ir.num_dots; - - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC)) - roll = wm->orient.roll; - - /* count visible dots */ - wm->ir.num_dots = 0; - for (i = 0; i < 4; ++i) { - if (dot[i].visible) - wm->ir.num_dots++; - } - - switch (wm->ir.num_dots) { - case 0: - { - wm->ir.state = 0; - - /* reset the dot ordering */ - for (i = 0; i < 4; ++i) - dot[i].order = 0; - - wm->ir.x = 0; - wm->ir.y = 0; - wm->ir.z = 0.0f; - - return; - } - case 1: - { - fix_rotated_ir_dots(wm->ir.dot, roll); - - if (wm->ir.state < 2) { - /* - * Only 1 known dot, so use just that. - */ - for (i = 0; i < 4; ++i) { - if (dot[i].visible) { - wm->ir.x = dot[i].x; - wm->ir.y = dot[i].y; - - wm->ir.ax = wm->ir.x; - wm->ir.ay = wm->ir.y; - - /* can't calculate yaw because we don't have the distance */ - //wm->orient.yaw = calc_yaw(&wm->ir); - - ir_convert_to_vres(&wm->ir.x, &wm->ir.y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]); - break; - } - } - } else { - /* - * Only see 1 dot but know theres 2. - * Try to estimate where the other one - * should be and use that. - */ - for (i = 0; i < 4; ++i) { - if (dot[i].visible) { - int ox = 0; - int x, y; - - if (dot[i].order == 1) - /* visible is the left dot - estimate where the right is */ - ox = dot[i].x + wm->ir.distance; - else if (dot[i].order == 2) - /* visible is the right dot - estimate where the left is */ - ox = dot[i].x - wm->ir.distance; - - x = ((signed int)dot[i].x + ox) / 2; - y = dot[i].y; - - wm->ir.ax = x; - wm->ir.ay = y; - wm->orient.yaw = calc_yaw(&wm->ir); - - if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) { - ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]); - wm->ir.x = x; - wm->ir.y = y; - } - - break; - } - } - } - - break; - } - case 2: - case 3: - case 4: - { - /* - * Two (or more) dots known and seen. - * Average them together to estimate the true location. - */ - int x, y; - wm->ir.state = 2; - - fix_rotated_ir_dots(wm->ir.dot, roll); - - /* if there is at least 1 new dot, reorder them all */ - if (wm->ir.num_dots > last_num_dots) { - reorder_ir_dots(dot); - wm->ir.x = 0; - wm->ir.y = 0; - } - - wm->ir.distance = ir_distance(dot); - wm->ir.z = 1023 - wm->ir.distance; - - get_ir_dot_avg(wm->ir.dot, &x, &y); - - wm->ir.ax = x; - wm->ir.ay = y; - wm->orient.yaw = calc_yaw(&wm->ir); - - if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) { - ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]); - wm->ir.x = x; - wm->ir.y = y; - } - - break; - } - default: - { - break; - } - } - - #ifdef WITH_WIIUSE_DEBUG - { - int ir_level; - WIIUSE_GET_IR_SENSITIVITY(wm, &ir_level); - WIIUSE_DEBUG("IR sensitivity: %i", ir_level); - WIIUSE_DEBUG("IR visible dots: %i", wm->ir.num_dots); - for (i = 0; i < 4; ++i) - if (dot[i].visible) - WIIUSE_DEBUG("IR[%i][order %i] (%.3i, %.3i) -> (%.3i, %.3i)", i, dot[i].order, dot[i].rx, dot[i].ry, dot[i].x, dot[i].y); - WIIUSE_DEBUG("IR[absolute]: (%i, %i)", wm->ir.x, wm->ir.y); - } - #endif -} - - - -/** - * @brief Fix the rotation of the IR dots. - * - * @param dot An array of 4 ir_dot_t objects. - * @param ang The roll angle to correct by (-180, 180) - * - * If there is roll then the dots are rotated - * around the origin and give a false cursor - * position. Correct for the roll. - * - * If the accelerometer is off then obviously - * this will not do anything and the cursor - * position may be inaccurate. - */ -static void fix_rotated_ir_dots(struct ir_dot_t* dot, float ang) { - float s, c; - int x, y; - int i; - - if (!ang) { - for (i = 0; i < 4; ++i) { - dot[i].x = dot[i].rx; - dot[i].y = dot[i].ry; - } - return; - } - - s = sin(DEGREE_TO_RAD(ang)); - c = cos(DEGREE_TO_RAD(ang)); - - /* - * [ cos(theta) -sin(theta) ][ ir->rx ] - * [ sin(theta) cos(theta) ][ ir->ry ] - */ - - for (i = 0; i < 4; ++i) { - if (!dot[i].visible) - continue; - - x = dot[i].rx - (1024/2); - y = dot[i].ry - (768/2); - - dot[i].x = (c * x) + (-s * y); - dot[i].y = (s * x) + (c * y); - - dot[i].x += (1024/2); - dot[i].y += (768/2); - } -} - - -/** - * @brief Average IR dots. - * - * @param dot An array of 4 ir_dot_t objects. - * @param x [out] Average X - * @param y [out] Average Y - */ -static void get_ir_dot_avg(struct ir_dot_t* dot, int* x, int* y) { - int vis = 0, i = 0; - - *x = 0; - *y = 0; - - for (; i < 4; ++i) { - if (dot[i].visible) { - *x += dot[i].x; - *y += dot[i].y; - ++vis; - } - } - - *x /= vis; - *y /= vis; -} - - -/** - * @brief Reorder the IR dots. - * - * @param dot An array of 4 ir_dot_t objects. - */ -static void reorder_ir_dots(struct ir_dot_t* dot) { - int i, j, order; - - /* reset the dot ordering */ - for (i = 0; i < 4; ++i) - dot[i].order = 0; - - for (order = 1; order < 5; ++order) { - for (i = 0; i < 4 && (!dot[i].visible || dot[i].order); ++i) { - if (i >= 4) - return; - } - - for (j = 0; j < 4; ++j) { - if (dot[j].visible && !dot[j].order && (dot[j].x < dot[i].x)) - i = j; - } - - dot[i].order = order; - } -} - - -/** - * @brief Calculate the distance between the first 2 visible IR dots. - * - * @param dot An array of 4 ir_dot_t objects. - */ -static float ir_distance(struct ir_dot_t* dot) { - int i1, i2; - int xd, yd; - - for (i1 = 0; i1 < 4; ++i1) - if (dot[i1].visible) - break; - if (i1 == 4) - return 0.0f; - - for (i2 = i1+1; i2 < 4; ++i2) - if (dot[i2].visible) - break; - if (i2 == 4) - return 0.0f; - - xd = dot[i2].x - dot[i1].x; - yd = dot[i2].y - dot[i1].y; - - return sqrt(xd*xd + yd*yd); -} - - -/** - * @brief Correct for the IR bounding box. - * - * @param x [out] The current X, it will be updated if valid. - * @param y [out] The current Y, it will be updated if valid. - * @param aspect Aspect ratio of the screen. - * @param offset_x The X offset of the bounding box. - * @param offset_y The Y offset of the bounding box. - * - * @return Returns 1 if the point is valid and was updated. - * - * Nintendo was smart with this bit. They sacrifice a little - * precision for a big increase in usability. - */ -static int ir_correct_for_bounds(int* x, int* y, enum aspect_t aspect, int offset_x, int offset_y) { - int x0, y0; - int xs, ys; - - if (aspect == WIIUSE_ASPECT_16_9) { - xs = WM_ASPECT_16_9_X; - ys = WM_ASPECT_16_9_Y; - } else { - xs = WM_ASPECT_4_3_X; - ys = WM_ASPECT_4_3_Y; - } - - x0 = ((1024 - xs) / 2) + offset_x; - y0 = ((768 - ys) / 2) + offset_y; - - if ((*x >= x0) - && (*x <= (x0 + xs)) - && (*y >= y0) - && (*y <= (y0 + ys))) - { - *x -= offset_x; - *y -= offset_y; - - return 1; - } - - return 0; -} - - -/** - * @brief Interpolate the point to the user defined virtual screen resolution. - */ -static void ir_convert_to_vres(int* x, int* y, enum aspect_t aspect, int vx, int vy) { - int xs, ys; - - if (aspect == WIIUSE_ASPECT_16_9) { - xs = WM_ASPECT_16_9_X; - ys = WM_ASPECT_16_9_Y; - } else { - xs = WM_ASPECT_4_3_X; - ys = WM_ASPECT_4_3_Y; - } - - *x -= ((1024-xs)/2); - *y -= ((768-ys)/2); - - *x = (*x / (float)xs) * vx; - *y = (*y / (float)ys) * vy; -} - - -/** - * @brief Calculate yaw given the IR data. - * - * @param ir IR data structure. - */ -float calc_yaw(struct ir_t* ir) { - float x; - - x = ir->ax - 512; - x = x * (ir->z / 1024.0f); - - return RAD_TO_DEGREE( atanf(x / ir->z) ); -} diff --git a/cpp/wiiuse/src/ir.h b/cpp/wiiuse/src/ir.h deleted file mode 100644 index 9082492..0000000 --- a/cpp/wiiuse/src/ir.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Handles IR data. - */ - -#ifndef IR_H_INCLUDED -#define IR_H_INCLUDED - -#include "wiiuse_internal.h" - -#define WII_VRES_X 560 -#define WII_VRES_Y 340 - -#ifdef __cplusplus -extern "C" { -#endif - -void calculate_basic_ir(struct wiimote_t* wm, byte* data); -void calculate_extended_ir(struct wiimote_t* wm, byte* data); -float calc_yaw(struct ir_t* ir); - -#ifdef __cplusplus -} -#endif - -#endif // IR_H_INCLUDED - - diff --git a/cpp/wiiuse/src/nunchuk.c b/cpp/wiiuse/src/nunchuk.c deleted file mode 100644 index 2733174..0000000 --- a/cpp/wiiuse/src/nunchuk.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Nunchuk expansion device. - */ - -#include -#include -#include - -#include "definitions.h" -#include "wiiuse_internal.h" -#include "dynamics.h" -#include "events.h" -#include "nunchuk.h" - -static void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now); - -/** - * @brief Handle the handshake data from the nunchuk. - * - * @param nc A pointer to a nunchuk_t structure. - * @param data The data read in from the device. - * @param len The length of the data block, in bytes. - * - * @return Returns 1 if handshake was successful, 0 if not. - */ -int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len) { - int offset = 0; - - nc->btns = 0; - nc->btns_held = 0; - nc->btns_released = 0; - - /* set the smoothing to the same as the wiimote */ - nc->flags = &wm->flags; - nc->accel_calib.st_alpha = wm->accel_calib.st_alpha; - - if (data[offset] == 0xFF) { - /* - * Sometimes the data returned here is not correct. - * This might happen because the wiimote is lagging - * behind our initialization sequence. - * To fix this just request the handshake again. - * - * Other times it's just the first 16 bytes are 0xFF, - * but since the next 16 bytes are the same, just use - * those. - */ - if (data[offset + 16] == 0xFF) { - /* get the calibration data */ - byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); - - WIIUSE_DEBUG("Nunchuk handshake appears invalid, trying again."); - wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); - - return 0; - } else - offset += 16; - } - - nc->accel_calib.cal_zero.x = data[offset + 0]; - nc->accel_calib.cal_zero.y = data[offset + 1]; - nc->accel_calib.cal_zero.z = data[offset + 2]; - nc->accel_calib.cal_g.x = data[offset + 4]; - nc->accel_calib.cal_g.y = data[offset + 5]; - nc->accel_calib.cal_g.z = data[offset + 6]; - nc->js.max.x = data[offset + 8]; - nc->js.min.x = data[offset + 9]; - nc->js.center.x = data[offset + 10]; - nc->js.max.y = data[offset + 11]; - nc->js.min.y = data[offset + 12]; - nc->js.center.y = data[offset + 13]; - - /* default the thresholds to the same as the wiimote */ - nc->orient_threshold = wm->orient_threshold; - nc->accel_threshold = wm->accel_threshold; - - /* handshake done */ - wm->exp.type = EXP_NUNCHUK; - - #ifdef WIN32 - wm->timeout = WIIMOTE_DEFAULT_TIMEOUT; - #endif - - return 1; -} - - -/** - * @brief The nunchuk disconnected. - * - * @param nc A pointer to a nunchuk_t structure. - */ -void nunchuk_disconnected(struct nunchuk_t* nc) { - memset(nc, 0, sizeof(struct nunchuk_t)); -} - - - -/** - * @brief Handle nunchuk event. - * - * @param nc A pointer to a nunchuk_t structure. - * @param msg The message specified in the event packet. - */ -void nunchuk_event(struct nunchuk_t* nc, byte* msg) { - /* get button states */ - nunchuk_pressed_buttons(nc, msg[5]); - - /* calculate joystick state */ - calc_joystick_state(&nc->js, msg[0], msg[1]); - - /* calculate orientation */ - nc->accel.x = msg[2]; - nc->accel.y = msg[3]; - nc->accel.z = msg[4]; - - calculate_orientation(&nc->accel_calib, &nc->accel, &nc->orient, NUNCHUK_IS_FLAG_SET(nc, WIIUSE_SMOOTHING)); - calculate_gforce(&nc->accel_calib, &nc->accel, &nc->gforce); -} - - -/** - * @brief Find what buttons are pressed. - * - * @param nc Pointer to a nunchuk_t structure. - * @param msg The message byte specified in the event packet. - */ -static void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now) { - /* message is inverted (0 is active, 1 is inactive) */ - now = ~now & NUNCHUK_BUTTON_ALL; - - /* pressed now & were pressed, then held */ - nc->btns_held = (now & nc->btns); - - /* were pressed or were held & not pressed now, then released */ - nc->btns_released = ((nc->btns | nc->btns_held) & ~now); - - /* buttons pressed now */ - nc->btns = now; -} - - -/** - * @brief Set the orientation event threshold for the nunchuk. - * - * @param wm Pointer to a wiimote_t structure with a nunchuk attached. - * @param threshold The decimal place that should be considered a significant change. - * - * See wiiuse_set_orient_threshold() for details. - */ -void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold) { - if (!wm) return; - - wm->exp.nunchuk.orient_threshold = threshold; -} - - -/** - * @brief Set the accelerometer event threshold for the nunchuk. - * - * @param wm Pointer to a wiimote_t structure with a nunchuk attached. - * @param threshold The decimal place that should be considered a significant change. - * - * See wiiuse_set_orient_threshold() for details. - */ -void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold) { - if (!wm) return; - - wm->exp.nunchuk.accel_threshold = threshold; -} diff --git a/cpp/wiiuse/src/nunchuk.h b/cpp/wiiuse/src/nunchuk.h deleted file mode 100644 index f036073..0000000 --- a/cpp/wiiuse/src/nunchuk.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief Nunchuk expansion device. - */ - -#ifndef NUNCHUK_H_INCLUDED -#define NUNCHUK_H_INCLUDED - -#include "wiiuse_internal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len); - -void nunchuk_disconnected(struct nunchuk_t* nc); - -void nunchuk_event(struct nunchuk_t* nc, byte* msg); - -#ifdef __cplusplus -} -#endif - -#endif // NUNCHUK_H_INCLUDED diff --git a/cpp/wiiuse/src/os.h b/cpp/wiiuse/src/os.h deleted file mode 100644 index e207c8b..0000000 --- a/cpp/wiiuse/src/os.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - - -/** - * @file - * @brief Operating system related definitions. - * - * This file is an attempt to separate operating system - * dependent functions and choose what should be used - * at compile time. - */ - -#ifndef OS_H_INCLUDED -#define OS_H_INCLUDED - -#ifdef WIN32 - /* windows */ - //#define isnan(x) _isnan(x) - //#define isinf(x) !_finite(x) - - /* disable warnings I don't care about */ - //#pragma warning(disable:4244) /* possible loss of data conversion */ - //#pragma warning(disable:4273) /* inconsistent dll linkage */ - //#pragma warning(disable:4217) -#else - /* nix */ -#endif - - -#endif // OS_H_INCLUDED diff --git a/cpp/wiiuse/src/speaker.c b/cpp/wiiuse/src/speaker.c deleted file mode 100644 index 68f932f..0000000 --- a/cpp/wiiuse/src/speaker.c +++ /dev/null @@ -1,86 +0,0 @@ -#include -#include "definitions.h" -#include "wiiuse_internal.h" -#include "wiiuse.h" -#include "speaker.h" - -void wiiuse_speaker_init(struct wiimote_t* wm) { - wiiuse_speaker_format(wm, 0x00); - wiiuse_speaker_rate(wm, 0x00, 0x00); - wiiuse_speaker_volume(wm, 0x00); -} - -void wiiuse_speaker_enable(struct wiimote_t* wm) { - byte buf = WIIMOTE_GET_RUMBLE(wm) | WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED; - wiiuse_send(wm, WM_CMD_SPEAKER_ENABLE, &buf, 1); -} - -void wiiuse_speaker_disable(struct wiimote_t* wm) { - byte buf = WIIMOTE_GET_RUMBLE(wm); - wiiuse_send(wm, WM_CMD_SPEAKER_ENABLE, &buf, 1); -} - -void wiiuse_speaker_mute(struct wiimote_t* wm) { - byte buf = WIIMOTE_GET_RUMBLE(wm) | WM_CTRL_STATUS_BYTE1_SPEAKER_MUTE; - wiiuse_send(wm, WM_CMD_SPEAKER_MUTE, &buf , 1); -} - -void wiiuse_speaker_unmute(struct wiimote_t* wm) { - byte buf = WIIMOTE_GET_RUMBLE(wm); - wiiuse_send(wm, WM_CMD_SPEAKER_MUTE, &buf, 1); -} - -void wiiuse_speaker_activate(struct wiimote_t* wm) { - wiiuse_speaker_enable(wm); - wiiuse_speaker_mute(wm); -#if 0 - byte buf = 0x01; - wiiuse_write_data(wm, WM_REG_SPEAKER + 8, &buf, 1); - buf = 0x08; - wiiuse_write_data(wm, WM_REG_SPEAKER, &buf, 1); - wiiuse_speaker_config(wm); - buf = 0x01; - wiiuse_write_data(wm, WM_REG_SPEAKER + 7, &buf, 1); -#else - byte buf[9] = {0x00, wm->speaker.format, wm->speaker.rate, wm->speaker.freq, wm->speaker.vol, 0x00, 0x00, 0x01, 0x01}; - wiiuse_write_data(wm, WM_REG_SPEAKER, buf, 9); -#endif - wiiuse_speaker_unmute(wm); -} - -void wiiuse_speaker_deactivate(struct wiimote_t* wm) { - wiiuse_speaker_mute(wm); - wiiuse_speaker_disable(wm); -} - -void wiiuse_speaker_format(struct wiimote_t* wm, byte format) { - wm->speaker.format = format; -} - -void wiiuse_speaker_rate(struct wiimote_t* wm, byte rate, byte freq) { - // Check: pcm_sample_rate = 12000000 / rate_value adpcm_sample_rate = 6000000 / rate_value - wm->speaker.rate = rate; - //wm->speaker.freq = freq; -} - -void wiiuse_speaker_volume(struct wiimote_t* wm, double vol) { - wm->speaker.vol = vol * WIIMOTE_GET_SPEAKER_MAX_VOLUME(wm); -} - -void wiiuse_speaker_config(struct wiimote_t* wm) { - WIIUSE_DEBUG("speaker_config()"); - WIIUSE_DEBUG("format: %2x", wm->speaker.format); - WIIUSE_DEBUG("rate: %2x", wm->speaker.rate); - WIIUSE_DEBUG("freq: %2x", wm->speaker.freq); - WIIUSE_DEBUG("vol: %2x", wm->speaker.vol); - byte cfg[7] = {0x00, wm->speaker.format, wm->speaker.rate, wm->speaker.freq, wm->speaker.vol, 0x00, 0x00}; - wiiuse_write_data(wm, WM_REG_SPEAKER, cfg, 7); -} - -void wiiuse_speaker_data(struct wiimote_t* wm, byte* data, int len) { - byte buf[21] = {0x00}; - buf[0] = len << 3; - //WIIUSE_DEBUG("speaker_data(): length = %d", len); - memcpy(buf + 1, data, len); - wiiuse_send(wm, WM_CMD_STREAM_DATA, buf, 21); -} diff --git a/cpp/wiiuse/src/speaker.h b/cpp/wiiuse/src/speaker.h deleted file mode 100644 index a8bed66..0000000 --- a/cpp/wiiuse/src/speaker.h +++ /dev/null @@ -1,14 +0,0 @@ -#include "wiiuse.h" - -#define MIN(x,y) ((x) < (y) ? (x) : (y)) - -#define WIIMOTE_GET_RUMBLE(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE) ? 0x01 : 0x00) -#define WIIMOTE_GET_SPEAKER_MAX_VOLUME(wm) (wm->speaker.format == 0x00 ? 0x40 : 0xff) - -#define WM_CMD_SPEAKER_ENABLE 0x14 -#define WM_CMD_STREAM_DATA 0x18 -#define WM_CMD_SPEAKER_MUTE 0x19 - -#define WM_CTRL_STATUS_BYTE1_SPEAKER_MUTE 0x04 - -#define WM_REG_SPEAKER 0x04a20001 diff --git a/cpp/wiiuse/src/wiiuse.c b/cpp/wiiuse/src/wiiuse.c deleted file mode 100644 index 583733c..0000000 --- a/cpp/wiiuse/src/wiiuse.c +++ /dev/null @@ -1,768 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief General wiimote operations. - * - * The file includes functions that handle general - * tasks. Most of these are functions that are part - * of the API. - */ - -#include -#include - -#ifndef WIN32 - #include -#else - #include -#endif - -#include "definitions.h" -#include "wiiuse_internal.h" - -#include "wiiuse.h" -#include "events.h" -#include "io.h" - -static int g_banner = 1; - -/** - * @breif Returns the version of the library. - */ -const char* wiiuse_version() { - return WIIUSE_VERSION; -} - - -/** - * @brief Clean up wiimote_t array created by wiiuse_init() - */ -void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes) { - int i = 0; - - if (!wm) - return; - - WIIUSE_INFO("wiiuse clean up..."); - - for (; i < wiimotes; ++i) { - wiiuse_disconnect(wm[i]); - free(wm[i]); - } - - free(wm); - - return; -} - - -/** - * @brief Initialize an array of wiimote structures. - * - * @param wiimotes Number of wiimote_t structures to create. - * - * @return An array of initialized wiimote_t structures. - * - * @see wiiuse_connect() - * - * The array returned by this function can be passed to various - * functions, including wiiuse_connect(). - */ -struct wiimote_t** wiiuse_init(int wiimotes) { - int i = 0; - struct wiimote_t** wm = NULL; - - /* - * Please do not remove this banner. - * GPL asks that you please leave output credits intact. - * Thank you. - * - * This banner is only displayed once so that if you need - * to call this function again it won't be intrusive. - */ - if (!g_banner) { - printf( "wiiuse v" WIIUSE_VERSION " loaded.\n" - " By: Michael Laforest \n" - " http://wiiuse.net http://wiiuse.sf.net\n"); - g_banner = 1; - } - - if (!wiimotes) - return NULL; - - wm = malloc(sizeof(struct wiimote_t*) * wiimotes); - - for (i = 0; i < wiimotes; ++i) { - wm[i] = malloc(sizeof(struct wiimote_t)); - memset(wm[i], 0, sizeof(struct wiimote_t)); - - wm[i]->unid = i+1; - - #ifndef WIN32 - wm[i]->bdaddr = *BDADDR_ANY; - wm[i]->out_sock = -1; - wm[i]->in_sock = -1; - #else - wm[i]->dev_handle = 0; - wm[i]->stack = WIIUSE_STACK_UNKNOWN; - wm[i]->normal_timeout = WIIMOTE_DEFAULT_TIMEOUT; - wm[i]->exp_timeout = WIIMOTE_EXP_TIMEOUT; - wm[i]->timeout = wm[i]->normal_timeout; - #endif - - wm[i]->state = WIIMOTE_INIT_STATES; - wm[i]->flags = WIIUSE_INIT_FLAGS; - - wm[i]->event = WIIUSE_NONE; - - wm[i]->exp.type = EXP_NONE; - - wiiuse_set_aspect_ratio(wm[i], WIIUSE_ASPECT_4_3); - wiiuse_set_ir_position(wm[i], WIIUSE_IR_ABOVE); - - wm[i]->orient_threshold = 0.5f; - wm[i]->accel_threshold = 5; - - wm[i]->accel_calib.st_alpha = WIIUSE_DEFAULT_SMOOTH_ALPHA; - } - - return wm; -} - - -/** - * @brief The wiimote disconnected. - * - * @param wm Pointer to a wiimote_t structure. - */ -void wiiuse_disconnected(struct wiimote_t* wm) { - if (!wm) return; - - WIIUSE_INFO("Wiimote disconnected [id %i].", wm->unid); - - /* disable the connected flag */ - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); - - /* reset a bunch of stuff */ - #ifndef WIN32 - wm->out_sock = -1; - wm->in_sock = -1; - #else - wm->dev_handle = 0; - #endif - - wm->leds = 0; - wm->state = WIIMOTE_INIT_STATES; - wm->read_req = NULL; - wm->handshake_state = 0; - wm->btns = 0; - wm->btns_held = 0; - wm->btns_released = 0; - memset(wm->event_buf, 0, sizeof(wm->event_buf)); - - wm->event = WIIUSE_DISCONNECT; -} - - -/** - * @brief Enable or disable the rumble. - * - * @param wm Pointer to a wiimote_t structure. - * @param status 1 to enable, 0 to disable. - */ -void wiiuse_rumble(struct wiimote_t* wm, int status) { - byte buf; - - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) - return; - - /* make sure to keep the current lit leds */ - buf = wm->leds; - - if (status) { - WIIUSE_DEBUG("Starting rumble..."); - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_RUMBLE); - buf |= 0x01; - } else { - WIIUSE_DEBUG("Stopping rumble..."); - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_RUMBLE); - } - - /* preserve IR state */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) - buf |= 0x04; - - wiiuse_send(wm, WM_CMD_RUMBLE, &buf, 1); -} - - -/** - * @brief Toggle the state of the rumble. - * - * @param wm Pointer to a wiimote_t structure. - */ -void wiiuse_toggle_rumble(struct wiimote_t* wm) { - if (!wm) return; - - wiiuse_rumble(wm, !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)); -} - - -/** - * @brief Set the enabled LEDs. - * - * @param wm Pointer to a wiimote_t structure. - * @param leds What LEDs to enable. - * - * \a leds is a bitwise or of WIIMOTE_LED_1, WIIMOTE_LED_2, WIIMOTE_LED_3, or WIIMOTE_LED_4. - */ -void wiiuse_set_leds(struct wiimote_t* wm, int leds) { - byte buf; - - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) - return; - - /* remove the lower 4 bits because they control rumble */ - wm->leds = (leds & 0xF0); - - /* make sure if the rumble is on that we keep it on */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) - wm->leds |= 0x01; - - buf = wm->leds; - - wiiuse_send(wm, WM_CMD_LED, &buf, 1); -} - - -/** - * @brief Set if the wiimote should report motion sensing. - * - * @param wm Pointer to a wiimote_t structure. - * @param status 1 to enable, 0 to disable. - * - * Since reporting motion sensing sends a lot of data, - * the wiimote saves power by not transmitting it - * by default. - */ -void wiiuse_motion_sensing(struct wiimote_t* wm, int status) { - if (status) - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_ACC); - else - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC); - - wiiuse_set_report_type(wm); -} - - -/** - * @brief Set the report type based on the current wiimote state. - * - * @param wm Pointer to a wiimote_t structure. - * - * @return The report type sent. - * - * The wiimote reports formatted packets depending on the - * report type that was last requested. This function will - * update the type of report that should be sent based on - * the current state of the device. - */ -int wiiuse_set_report_type(struct wiimote_t* wm) { - byte buf[2]; - int motion, exp, ir; - - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) - return 0; - - buf[0] = (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_CONTINUOUS) ? 0x04 : 0x00); /* set to 0x04 for continuous reporting */ - buf[1] = 0x00; - - /* if rumble is enabled, make sure we keep it */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) - buf[0] |= 0x01; - - motion = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC); - exp = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP); - ir = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR); - - if (motion && ir && exp) buf[1] = WM_RPT_BTN_ACC_IR_EXP; - else if (motion && exp) buf[1] = WM_RPT_BTN_ACC_EXP; - else if (motion && ir) buf[1] = WM_RPT_BTN_ACC_IR; - else if (ir && exp) buf[1] = WM_RPT_BTN_IR_EXP; - else if (ir) buf[1] = WM_RPT_BTN_ACC_IR; - else if (exp) buf[1] = WM_RPT_BTN_EXP; - else if (motion) buf[1] = WM_RPT_BTN_ACC; - else buf[1] = WM_RPT_BTN; - - WIIUSE_DEBUG("Setting report type: 0x%x", buf[1]); - - exp = wiiuse_send(wm, WM_CMD_REPORT_TYPE, buf, 2); - if (exp <= 0) - return exp; - - return buf[1]; -} - - -/** - * @brief Read data from the wiimote (callback version). - * - * @param wm Pointer to a wiimote_t structure. - * @param read_cb Function pointer to call when the data arrives from the wiimote. - * @param buffer An allocated buffer to store the data as it arrives from the wiimote. - * Must be persistent in memory and large enough to hold the data. - * @param addr The address of wiimote memory to read from. - * @param len The length of the block to be read. - * - * The library can only handle one data read request at a time - * because it must keep track of the buffer and other - * events that are specific to that request. So if a request - * has already been made, subsequent requests will be added - * to a pending list and be sent out when the previous - * finishes. - */ -int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int addr, unsigned short len) { - struct read_req_t* req; - - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) - return 0; - if (!buffer || !len || !read_cb) - return 0; - - /* make this request structure */ - req = (struct read_req_t*)malloc(sizeof(struct read_req_t)); - req->cb = read_cb; - req->buf = buffer; - req->addr = addr; - req->size = len; - req->wait = len; - req->dirty = 0; - req->next = NULL; - - /* add this to the request list */ - if (!wm->read_req) { - /* root node */ - wm->read_req = req; - - WIIUSE_DEBUG("Data read request can be sent out immediately."); - - /* send the request out immediately */ - wiiuse_send_next_pending_read_request(wm); - } else { - struct read_req_t* nptr = wm->read_req; - for (; nptr->next; nptr = nptr->next); - nptr->next = req; - - WIIUSE_DEBUG("Added pending data read request."); - } - - return 1; -} - - -/** - * @brief Read data from the wiimote (event version). - * - * @param wm Pointer to a wiimote_t structure. - * @param buffer An allocated buffer to store the data as it arrives from the wiimote. - * Must be persistent in memory and large enough to hold the data. - * @param addr The address of wiimote memory to read from. - * @param len The length of the block to be read. - * - * The library can only handle one data read request at a time - * because it must keep track of the buffer and other - * events that are specific to that request. So if a request - * has already been made, subsequent requests will be added - * to a pending list and be sent out when the previous - * finishes. - */ -int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int addr, unsigned short len) { - struct read_req_t* req; - - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) - return 0; - if (!buffer || !len) - return 0; - - /* make this request structure */ - req = (struct read_req_t*)malloc(sizeof(struct read_req_t)); - req->cb = NULL; - req->buf = buffer; - req->addr = addr; - req->size = len; - req->wait = len; - req->dirty = 0; - req->next = NULL; - - /* add this to the request list */ - if (!wm->read_req) { - /* root node */ - wm->read_req = req; - - WIIUSE_DEBUG("Data read request can be sent out immediately."); - - /* send the request out immediately */ - wiiuse_send_next_pending_read_request(wm); - } else { - struct read_req_t* nptr = wm->read_req; - for (; nptr->next; nptr = nptr->next); - nptr->next = req; - - WIIUSE_DEBUG("Added pending data read request."); - } - - return 1; -} - - -/** - * @brief Send the next pending data read request to the wiimote. - * - * @param wm Pointer to a wiimote_t structure. - * - * @see wiiuse_read_data() - * - * This function is not part of the wiiuse API. - */ -void wiiuse_send_next_pending_read_request(struct wiimote_t* wm) { - byte buf[6]; - struct read_req_t* req; - - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) - return; - if (!wm->read_req) return; - - /* skip over dirty ones since they have already been read */ - req = wm->read_req; - while (req && req->dirty) - req = req->next; - if (!req) - return; - - /* the offset is in big endian */ - *(int*)(buf) = BIG_ENDIAN_LONG(req->addr); - - /* the length is in big endian */ - *(short*)(buf + 4) = BIG_ENDIAN_SHORT(req->size); - - WIIUSE_DEBUG("Request read at address: 0x%x length: %i", req->addr, req->size); - wiiuse_send(wm, WM_CMD_READ_DATA, buf, 6); -} - - -/** - * @brief Request the wiimote controller status. - * - * @param wm Pointer to a wiimote_t structure. - * - * Controller status includes: battery level, LED status, expansions - */ -void wiiuse_status(struct wiimote_t* wm) { - byte buf = 0; - - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) - return; - - WIIUSE_DEBUG("Requested wiimote status."); - - wiiuse_send(wm, WM_CMD_CTRL_STATUS, &buf, 1); -} - - -/** - * @brief Find a wiimote_t structure by its unique identifier. - * - * @param wm Pointer to a wiimote_t structure. - * @param wiimotes The number of wiimote_t structures in \a wm. - * @param unid The unique identifier to search for. - * - * @return Pointer to a wiimote_t structure, or NULL if not found. - */ -struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid) { - int i = 0; - - for (; i < wiimotes; ++i) { - if (wm[i]->unid == unid) - return wm[i]; - } - - return NULL; -} - - -/** - * @brief Write data to the wiimote. - * - * @param wm Pointer to a wiimote_t structure. - * @param addr The address to write to. - * @param data The data to be written to the memory location. - * @param len The length of the block to be written. - */ -int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len) { - byte buf[21] = {0}; /* the payload is always 23 */ - - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) - return 0; - if (!data || !len) - return 0; - - WIIUSE_DEBUG("Writing %i bytes to memory location 0x%x...", len, addr); - - #ifdef WITH_WIIUSE_DEBUG - { - int i = 0; - fprintf(stderr, "[DEBUG} Write data is: "); - for (; i < len; ++i) - fprintf(stderr, "%x ", data[i]); - fprintf(stderr, "\n"); - fflush(stderr); - } - #endif - - /* the offset is in big endian */ - *(int*)(buf) = BIG_ENDIAN_LONG(addr); - - /* length */ - *(byte*)(buf + 4) = len; - - /* data */ - memcpy(buf + 5, data, len); - - wiiuse_send(wm, WM_CMD_WRITE_DATA, buf, 21); - return 1; -} - - -/** - * @brief Send a packet to the wiimote. - * - * @param wm Pointer to a wiimote_t structure. - * @param report_type The report type to send (WIIMOTE_CMD_LED, WIIMOTE_CMD_RUMBLE, etc). Found in wiiuse.h - * @param msg The payload. - * @param len Length of the payload in bytes. - * - * This function should replace any write()s directly to the wiimote device. - */ -int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) { - byte buf[32]; /* no payload is better than this */ - int rumble = 0; - - #ifndef WIN32 - buf[0] = WM_SET_REPORT | WM_BT_OUTPUT; - buf[1] = report_type; - #else - buf[0] = report_type; - #endif - - switch (report_type) { - case WM_CMD_LED: - case WM_CMD_RUMBLE: - case WM_CMD_CTRL_STATUS: - { - /* Rumble flag for: 0x11, 0x13, 0x14, 0x15, 0x19 or 0x1a */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) - rumble = 1; - break; - } - default: - break; - } - - #ifndef WIN32 - memcpy(buf+2, msg, len); - if (rumble) - buf[2] |= 0x01; - #else - memcpy(buf+1, msg, len); - if (rumble) - buf[1] |= 0x01; - #endif - - #ifdef WITH_WIIUSE_DEBUG - { - int x = 2; - fprintf(stderr, "[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]); - #ifndef WIN32 - for (; x < len+2; ++x) - #else - for (; x < len+1; ++x) - #endif - fprintf(stderr, "%.2x ", buf[x]); - fprintf(stderr, "\n"); - fflush(stderr); - } - #endif - - #ifndef WIN32 - return wiiuse_io_write(wm, buf, len+2); - #else - return wiiuse_io_write(wm, buf, len+1); - #endif -} - - -/** - * @brief Set flags for the specified wiimote. - * - * @param wm Pointer to a wiimote_t structure. - * @param enable Flags to enable. - * @param disable Flags to disable. - * - * @return The flags set after 'enable' and 'disable' have been applied. - * - * The values 'enable' and 'disable' may be any flags OR'ed together. - * Flags are defined in wiiuse.h. - */ -int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable) { - if (!wm) return 0; - - /* remove mutually exclusive flags */ - enable &= ~disable; - disable &= ~enable; - - wm->flags |= enable; - wm->flags &= ~disable; - - return wm->flags; -} - - -/** - * @brief Set the wiimote smoothing alpha value. - * - * @param wm Pointer to a wiimote_t structure. - * @param alpha The alpha value to set. Between 0 and 1. - * - * @return Returns the old alpha value. - * - * The alpha value is between 0 and 1 and is used in an exponential - * smoothing algorithm. - * - * Smoothing is only performed if the WIIMOTE_USE_SMOOTHING is set. - */ -float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha) { - float old; - - if (!wm) return 0.0f; - - old = wm->accel_calib.st_alpha; - - wm->accel_calib.st_alpha = alpha; - - /* if there is a nunchuk set that too */ - if (wm->exp.type == EXP_NUNCHUK) - wm->exp.nunchuk.accel_calib.st_alpha = alpha; - - return old; -} - - -/** - * @brief Set the bluetooth stack type to use. - * - * @param wm Array of wiimote_t structures. - * @param wiimotes Number of objects in the wm array. - * @param type The type of bluetooth stack to use. - */ -void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type) { - #ifdef WIN32 - int i; - - if (!wm) return; - - for (i = 0; i < wiimotes; ++i) - wm[i]->stack = type; - #endif -} - - -/** - * @brief Set the orientation event threshold. - * - * @param wm Pointer to a wiimote_t structure. - * @param threshold The decimal place that should be considered a significant change. - * - * If threshold is 0.01, and any angle changes by 0.01 then a significant change - * has occured and the event callback will be invoked. If threshold is 1 then - * the angle has to change by a full degree to generate an event. - */ -void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold) { - if (!wm) return; - - wm->orient_threshold = threshold; -} - - -/** - * @brief Set the accelerometer event threshold. - * - * @param wm Pointer to a wiimote_t structure. - * @param threshold The decimal place that should be considered a significant change. - */ -void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold) { - if (!wm) return; - - wm->accel_threshold = threshold; -} - - -/** - * @brief Try to resync with the wiimote by starting a new handshake. - * - * @param wm Pointer to a wiimote_t structure. - */ -void wiiuse_resync(struct wiimote_t* wm) { - if (!wm) return; - - wm->handshake_state = 0; - wiiuse_handshake(wm, NULL, 0); -} - - -/** - * @brief Set the normal and expansion handshake timeouts. - * - * @param wm Array of wiimote_t structures. - * @param wiimotes Number of objects in the wm array. - * @param normal_timeout The timeout in milliseconds for a normal read. - * @param exp_timeout The timeout in millisecondsd to wait for an expansion handshake. - */ -void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout) { - #ifdef WIN32 - int i; - - if (!wm) return; - - for (i = 0; i < wiimotes; ++i) { - wm[i]->normal_timeout = normal_timeout; - wm[i]->exp_timeout = exp_timeout; - } - #endif -} diff --git a/cpp/wiiuse/src/wiiuse.h b/cpp/wiiuse/src/wiiuse.h deleted file mode 100644 index bd3c27f..0000000 --- a/cpp/wiiuse/src/wiiuse.h +++ /dev/null @@ -1,710 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * - * @brief API header file. - * - * If this file is included from inside the wiiuse source - * and not from a third party program, then wiimote_internal.h - * is also included which extends this file. - */ - -#ifndef WIIUSE_H_INCLUDED -#define WIIUSE_H_INCLUDED - -#ifdef _WIN32 - /* windows */ - #include -#else - /* nix */ - #include -#endif - -#ifdef WIIUSE_INTERNAL_H_INCLUDED - #define WCONST -#else - #define WCONST const -#endif - -/* led bit masks */ -#define WIIMOTE_LED_NONE 0x00 -#define WIIMOTE_LED_1 0x10 -#define WIIMOTE_LED_2 0x20 -#define WIIMOTE_LED_3 0x40 -#define WIIMOTE_LED_4 0x80 - -/* button codes */ -#define WIIMOTE_BUTTON_TWO 0x0001 -#define WIIMOTE_BUTTON_ONE 0x0002 -#define WIIMOTE_BUTTON_B 0x0004 -#define WIIMOTE_BUTTON_A 0x0008 -#define WIIMOTE_BUTTON_MINUS 0x0010 -#define WIIMOTE_BUTTON_ZACCEL_BIT6 0x0020 -#define WIIMOTE_BUTTON_ZACCEL_BIT7 0x0040 -#define WIIMOTE_BUTTON_HOME 0x0080 -#define WIIMOTE_BUTTON_LEFT 0x0100 -#define WIIMOTE_BUTTON_RIGHT 0x0200 -#define WIIMOTE_BUTTON_DOWN 0x0400 -#define WIIMOTE_BUTTON_UP 0x0800 -#define WIIMOTE_BUTTON_PLUS 0x1000 -#define WIIMOTE_BUTTON_ZACCEL_BIT4 0x2000 -#define WIIMOTE_BUTTON_ZACCEL_BIT5 0x4000 -#define WIIMOTE_BUTTON_UNKNOWN 0x8000 -#define WIIMOTE_BUTTON_ALL 0x1F9F - -/* nunchul button codes */ -#define NUNCHUK_BUTTON_Z 0x01 -#define NUNCHUK_BUTTON_C 0x02 -#define NUNCHUK_BUTTON_ALL 0x03 - -/* classic controller button codes */ -#define CLASSIC_CTRL_BUTTON_UP 0x0001 -#define CLASSIC_CTRL_BUTTON_LEFT 0x0002 -#define CLASSIC_CTRL_BUTTON_ZR 0x0004 -#define CLASSIC_CTRL_BUTTON_X 0x0008 -#define CLASSIC_CTRL_BUTTON_A 0x0010 -#define CLASSIC_CTRL_BUTTON_Y 0x0020 -#define CLASSIC_CTRL_BUTTON_B 0x0040 -#define CLASSIC_CTRL_BUTTON_ZL 0x0080 -#define CLASSIC_CTRL_BUTTON_FULL_R 0x0200 -#define CLASSIC_CTRL_BUTTON_PLUS 0x0400 -#define CLASSIC_CTRL_BUTTON_HOME 0x0800 -#define CLASSIC_CTRL_BUTTON_MINUS 0x1000 -#define CLASSIC_CTRL_BUTTON_FULL_L 0x2000 -#define CLASSIC_CTRL_BUTTON_DOWN 0x4000 -#define CLASSIC_CTRL_BUTTON_RIGHT 0x8000 -#define CLASSIC_CTRL_BUTTON_ALL 0xFEFF - -/* guitar hero 3 button codes */ -#define GUITAR_HERO_3_BUTTON_STRUM_UP 0x0001 -#define GUITAR_HERO_3_BUTTON_YELLOW 0x0008 -#define GUITAR_HERO_3_BUTTON_GREEN 0x0010 -#define GUITAR_HERO_3_BUTTON_BLUE 0x0020 -#define GUITAR_HERO_3_BUTTON_RED 0x0040 -#define GUITAR_HERO_3_BUTTON_ORANGE 0x0080 -#define GUITAR_HERO_3_BUTTON_PLUS 0x0400 -#define GUITAR_HERO_3_BUTTON_MINUS 0x1000 -#define GUITAR_HERO_3_BUTTON_STRUM_DOWN 0x4000 -#define GUITAR_HERO_3_BUTTON_ALL 0xFEFF - - -/* wiimote option flags */ -#define WIIUSE_SMOOTHING 0x01 -#define WIIUSE_CONTINUOUS 0x02 -#define WIIUSE_ORIENT_THRESH 0x04 -#define WIIUSE_INIT_FLAGS (WIIUSE_SMOOTHING | WIIUSE_ORIENT_THRESH) - -#define WIIUSE_ORIENT_PRECISION 100.0f - -/* expansion codes */ -#define EXP_NONE 0 -#define EXP_NUNCHUK 1 -#define EXP_CLASSIC 2 -#define EXP_GUITAR_HERO_3 3 -#define EXP_BALANCE_BOARD 4 - -/* IR correction types */ -typedef enum ir_position_t { - WIIUSE_IR_ABOVE, - WIIUSE_IR_BELOW -} ir_position_t; - -/** - * @brief Check if a button is pressed. - * @param dev Pointer to a wiimote_t or expansion structure. - * @param button The button you are interested in. - * @return 1 if the button is pressed, 0 if not. - */ -#define IS_PRESSED(dev, button) ((dev->btns & button) == button) - -/** - * @brief Check if a button is being held. - * @param dev Pointer to a wiimote_t or expansion structure. - * @param button The button you are interested in. - * @return 1 if the button is held, 0 if not. - */ -#define IS_HELD(dev, button) ((dev->btns_held & button) == button) - -/** - * @brief Check if a button is released on this event. \n\n - * This does not mean the button is not pressed, it means \n - * this button was just now released. - * @param dev Pointer to a wiimote_t or expansion structure. - * @param button The button you are interested in. - * @return 1 if the button is released, 0 if not. - * - */ -#define IS_RELEASED(dev, button) ((dev->btns_released & button) == button) - -/** - * @brief Check if a button has just been pressed this event. - * @param dev Pointer to a wiimote_t or expansion structure. - * @param button The button you are interested in. - * @return 1 if the button is pressed, 0 if not. - */ -#define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button)) - -/** - * @brief Return the IR sensitivity level. - * @param wm Pointer to a wiimote_t structure. - * @param lvl [out] Pointer to an int that will hold the level setting. - * If no level is set 'lvl' will be set to 0. - */ -#define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \ - do { \ - if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \ - else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \ - else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \ - else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \ - else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \ - else *lvl = 0; \ - } while (0) - -#define WIIUSE_USING_ACC(wm) ((wm->state & 0x020) == 0x020) -#define WIIUSE_USING_EXP(wm) ((wm->state & 0x040) == 0x040) -#define WIIUSE_USING_IR(wm) ((wm->state & 0x080) == 0x080) -#define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x100) == 0x100) - -#define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num) - -/* - * Largest known payload is 21 bytes. - * Add 2 for the prefix and round up to a power of 2. - */ -#define MAX_PAYLOAD 32 - -/* - * This is left over from an old hack, but it may actually - * be a useful feature to keep so it wasn't removed. - */ -#ifdef WIN32 - #define WIIMOTE_DEFAULT_TIMEOUT 10 - #define WIIMOTE_EXP_TIMEOUT 10 -#endif - -typedef unsigned char byte; -typedef char sbyte; - -struct wiimote_t; -struct vec3b_t; -struct orient_t; -struct gforce_t; - - -/** - * @brief Callback that handles a read event. - * - * @param wm Pointer to a wiimote_t structure. - * @param data Pointer to the filled data block. - * @param len Length in bytes of the data block. - * - * @see wiiuse_init() - * - * A registered function of this type is called automatically by the wiiuse - * library when the wiimote has returned the full data requested by a previous - * call to wiiuse_read_data(). - */ -typedef void (*wiiuse_read_cb)(struct wiimote_t* wm, byte* data, unsigned short len); - - -/** - * @struct read_req_t - * @brief Data read request structure. - */ -struct read_req_t { - wiiuse_read_cb cb; /**< read data callback */ - byte* buf; /**< buffer where read data is written */ - unsigned int addr; /**< the offset that the read started at */ - unsigned short size; /**< the length of the data read */ - unsigned short wait; /**< num bytes still needed to finish read */ - byte dirty; /**< set to 1 if not using callback and needs to be cleaned up */ - - struct read_req_t* next; /**< next read request in the queue */ -}; - - -/** - * @struct vec2b_t - * @brief Unsigned x,y byte vector. - */ -typedef struct vec2b_t { - byte x, y; -} vec2b_t; - - -/** - * @struct vec3b_t - * @brief Unsigned x,y,z byte vector. - */ -typedef struct vec3b_t { - byte x, y, z; -} vec3b_t; - - -/** - * @struct vec3f_t - * @brief Signed x,y,z float struct. - */ -typedef struct vec3f_t { - float x, y, z; -} vec3f_t; - - -/** - * @struct orient_t - * @brief Orientation struct. - * - * Yaw, pitch, and roll range from -180 to 180 degrees. - */ -typedef struct orient_t { - float roll; /**< roll, this may be smoothed if enabled */ - float pitch; /**< pitch, this may be smoothed if enabled */ - float yaw; - - float a_roll; /**< absolute roll, unsmoothed */ - float a_pitch; /**< absolute pitch, unsmoothed */ -} orient_t; - - -/** - * @struct gforce_t - * @brief Gravity force struct. - */ -typedef struct gforce_t { - float x, y, z; -} gforce_t; - - -/** - * @struct accel_t - * @brief Accelerometer struct. For any device with an accelerometer. - */ -typedef struct accel_t { - struct vec3b_t cal_zero; /**< zero calibration */ - struct vec3b_t cal_g; /**< 1g difference around 0cal */ - - float st_roll; /**< last smoothed roll value */ - float st_pitch; /**< last smoothed roll pitch */ - float st_alpha; /**< alpha value for smoothing [0-1] */ -} accel_t; - - -/** - * @struct ir_dot_t - * @brief A single IR source. - */ -typedef struct ir_dot_t { - byte visible; /**< if the IR source is visible */ - - unsigned int x; /**< interpolated X coordinate */ - unsigned int y; /**< interpolated Y coordinate */ - - short rx; /**< raw X coordinate (0-1023) */ - short ry; /**< raw Y coordinate (0-767) */ - - byte order; /**< increasing order by x-axis value */ - - byte size; /**< size of the IR dot (0-15) */ -} ir_dot_t; - - -/** - * @enum aspect_t - * @brief Screen aspect ratio. - */ -typedef enum aspect_t { - WIIUSE_ASPECT_4_3, - WIIUSE_ASPECT_16_9 -} aspect_t; - - -/** - * @struct ir_t - * @brief IR struct. Hold all data related to the IR tracking. - */ -typedef struct ir_t { - struct ir_dot_t dot[4]; /**< IR dots */ - byte num_dots; /**< number of dots at this time */ - - enum aspect_t aspect; /**< aspect ratio of the screen */ - - enum ir_position_t pos; /**< IR sensor bar position */ - - unsigned int vres[2]; /**< IR virtual screen resolution */ - int offset[2]; /**< IR XY correction offset */ - int state; /**< keeps track of the IR state */ - - int ax; /**< absolute X coordinate */ - int ay; /**< absolute Y coordinate */ - - int x; /**< calculated X coordinate */ - int y; /**< calculated Y coordinate */ - - float distance; /**< pixel distance between first 2 dots*/ - float z; /**< calculated distance */ -} ir_t; - - -/** - * @struct speaker_t - */ -typedef struct speaker_t { - byte format; - byte rate; - byte freq; - byte vol; -} speaker_t; - - -/** - * @struct joystick_t - * @brief Joystick calibration structure. - * - * The angle \a ang is relative to the positive y-axis into quadrant I - * and ranges from 0 to 360 degrees. So if the joystick is held straight - * upwards then angle is 0 degrees. If it is held to the right it is 90, - * down is 180, and left is 270. - * - * The magnitude \a mag is the distance from the center to where the - * joystick is being held. The magnitude ranges from 0 to 1. - * If the joystick is only slightly tilted from the center the magnitude - * will be low, but if it is closer to the outter edge the value will - * be higher. - */ -typedef struct joystick_t { - struct vec2b_t max; /**< maximum joystick values */ - struct vec2b_t min; /**< minimum joystick values */ - struct vec2b_t center; /**< center joystick values */ - - float ang; /**< angle the joystick is being held */ - float mag; /**< magnitude of the joystick (range 0-1) */ -} joystick_t; - - -/** - * @struct nunchuk_t - * @brief Nunchuk expansion device. - */ -typedef struct nunchuk_t { - struct accel_t accel_calib; /**< nunchuk accelerometer calibration */ - struct joystick_t js; /**< joystick calibration */ - - int* flags; /**< options flag (points to wiimote_t.flags) */ - - byte btns; /**< what buttons have just been pressed */ - byte btns_held; /**< what buttons are being held down */ - byte btns_released; /**< what buttons were just released this */ - - float orient_threshold; /**< threshold for orient to generate an event */ - int accel_threshold; /**< threshold for accel to generate an event */ - - struct vec3b_t accel; /**< current raw acceleration data */ - struct orient_t orient; /**< current orientation on each axis */ - struct gforce_t gforce; /**< current gravity forces on each axis */ -} nunchuk_t; - - -/** - * @struct classic_ctrl_t - * @brief Classic controller expansion device. - */ -typedef struct classic_ctrl_t { - short btns; /**< what buttons have just been pressed */ - short btns_held; /**< what buttons are being held down */ - short btns_released; /**< what buttons were just released this */ - - float r_shoulder; /**< right shoulder button (range 0-1) */ - float l_shoulder; /**< left shoulder button (range 0-1) */ - - struct joystick_t ljs; /**< left joystick calibration */ - struct joystick_t rjs; /**< right joystick calibration */ -} classic_ctrl_t; - - -/** - * @struct guitar_hero_3_t - * @brief Guitar Hero 3 expansion device. - */ -typedef struct guitar_hero_3_t { - short btns; /**< what buttons have just been pressed */ - short btns_held; /**< what buttons are being held down */ - short btns_released; /**< what buttons were just released this */ - - float whammy_bar; /**< whammy bar (range 0-1) */ - - struct joystick_t js; /**< joystick calibration */ -} guitar_hero_3_t; - - -/** - * @struct balance_board_data_t - * @brief Balance board l/r, t/b corner data data. - */ -typedef struct balance_board_data_t { - int tr; - int br; - int tl; - int bl; -} balance_board_data_t; - - -/** - * @struct balance_board_t - * @brief Balance board expansion device. - */ -typedef struct balance_board_t { - float tr; /** Top Right weight */ - float br; /** Bottom Right weight */ - float tl; /** Top Left weight */ - float bl; /** Bottom Left weight */ - struct balance_board_data_t raw; /** Raw actual values */ - struct balance_board_data_t cal_0; /** Calibration values at 0kg */ - struct balance_board_data_t cal_17; /** Calibration values at 17kg */ - struct balance_board_data_t cal_34; /** Calibration values at 34kg */ -} balance_board_t; - - -/** - * @struct expansion_t - * @brief Generic expansion device plugged into wiimote. - */ -typedef struct expansion_t { - int type; /**< type of expansion attached */ - - union { - struct nunchuk_t nunchuk; - struct classic_ctrl_t classic; - struct guitar_hero_3_t gh3; - struct balance_board_t bb; - }; -} expansion_t; - - -/** - * @enum win32_bt_stack_t - * @brief Available bluetooth stacks for Windows. - */ -typedef enum win_bt_stack_t { - WIIUSE_STACK_UNKNOWN, - WIIUSE_STACK_MS, - WIIUSE_STACK_BLUESOLEIL -} win_bt_stack_t; - - -/** - * @struct wiimote_state_t - * @brief Significant data from the previous event. - */ -typedef struct wiimote_state_t { - /* expansion_t */ - float exp_ljs_ang; - float exp_rjs_ang; - float exp_ljs_mag; - float exp_rjs_mag; - unsigned short exp_btns; - struct orient_t exp_orient; - struct vec3b_t exp_accel; - float exp_r_shoulder; - float exp_l_shoulder; - struct balance_board_data_t exp_bb_raw; - - /* ir_t */ - int ir_ax; - int ir_ay; - float ir_distance; - - struct orient_t orient; - unsigned short btns; - - struct vec3b_t accel; -} wiimote_state_t; - - -/** - * @enum WIIUSE_EVENT_TYPE - * @brief Events that wiiuse can generate from a poll. - */ -typedef enum WIIUSE_EVENT_TYPE { - WIIUSE_NONE = 0, - WIIUSE_EVENT, - WIIUSE_STATUS, - WIIUSE_CONNECT, - WIIUSE_DISCONNECT, - WIIUSE_UNEXPECTED_DISCONNECT, - WIIUSE_READ_DATA, - WIIUSE_NUNCHUK_INSERTED, - WIIUSE_NUNCHUK_REMOVED, - WIIUSE_CLASSIC_CTRL_INSERTED, - WIIUSE_CLASSIC_CTRL_REMOVED, - WIIUSE_GUITAR_HERO_3_CTRL_INSERTED, - WIIUSE_GUITAR_HERO_3_CTRL_REMOVED, - WIIUSE_BALANCE_BOARD_CTRL_INSERTED, - WIIUSE_BALANCE_BOARD_CTRL_REMOVED -} WIIUSE_EVENT_TYPE; - -/** - * @struct wiimote_t - * @brief Wiimote structure. - */ -typedef struct wiimote_t { - WCONST int unid; /**< user specified id */ - - #ifndef WIN32 - WCONST bdaddr_t bdaddr; /**< bt address */ - WCONST char bdaddr_str[18]; /**< readable bt address */ - WCONST int out_sock; /**< output socket */ - WCONST int in_sock; /**< input socket */ - #else - WCONST HANDLE dev_handle; /**< HID handle */ - WCONST OVERLAPPED hid_overlap; /**< overlap handle */ - WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */ - WCONST int timeout; /**< read timeout */ - WCONST byte normal_timeout; /**< normal timeout */ - WCONST byte exp_timeout; /**< timeout for expansion handshake */ - #endif - - WCONST int state; /**< various state flags */ - WCONST byte leds; /**< currently lit leds */ - WCONST float battery_level; /**< battery level */ - - WCONST int flags; /**< options flag */ - - WCONST byte handshake_state; /**< the state of the connection handshake */ - - WCONST struct read_req_t* read_req; /**< list of data read requests */ - WCONST struct accel_t accel_calib; /**< wiimote accelerometer calibration */ - WCONST struct expansion_t exp; /**< wiimote expansion device */ - - WCONST struct vec3b_t accel; /**< current raw acceleration data */ - WCONST struct orient_t orient; /**< current orientation on each axis */ - WCONST struct gforce_t gforce; /**< current gravity forces on each axis */ - - WCONST struct ir_t ir; /**< IR data */ - WCONST struct speaker_t speaker; /**< speaker */ - - WCONST unsigned short btns; /**< what buttons have just been pressed */ - WCONST unsigned short btns_held; /**< what buttons are being held down */ - WCONST unsigned short btns_released; /**< what buttons were just released this */ - - WCONST float orient_threshold; /**< threshold for orient to generate an event */ - WCONST int accel_threshold; /**< threshold for accel to generate an event */ - - WCONST struct wiimote_state_t lstate; /**< last saved state */ - - WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occured */ - WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */ -} wiimote; - - -/***************************************** - * - * Include API specific stuff - * - *****************************************/ - -#ifdef _WIN32 - #define WIIUSE_EXPORT_DECL __declspec(dllexport) - #define WIIUSE_IMPORT_DECL __declspec(dllimport) -#else - #define WIIUSE_EXPORT_DECL - #define WIIUSE_IMPORT_DECL -#endif - -#ifdef WIIUSE_COMPILE_LIB - #define WIIUSE_EXPORT WIIUSE_EXPORT_DECL -#else - #define WIIUSE_EXPORT WIIUSE_IMPORT_DECL -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* wiiuse.c */ -WIIUSE_EXPORT extern const char* wiiuse_version(); - -WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes); -WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes); -WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status); -WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds); -WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status); -WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, unsigned short len); -WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len); -WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm); -WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid); -WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable); -WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha); -WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type); -WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold); -WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout); -WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold); - -/* connect.c */ -WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout); -WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes); -WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm); - -/* events.c */ -WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes); - -/* ir.c */ -WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status); -WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y); -WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos); -WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect); -WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level); - -/* nunchuk.c */ -WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold); -WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold); - -/* speaker.c */ -WIIUSE_EXPORT extern void wiiuse_speaker_enable(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_disable(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_mute(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_unmute(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_activate(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_deactivate(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_format(struct wiimote_t* wm, byte format); -WIIUSE_EXPORT extern void wiiuse_speaker_volume(struct wiimote_t* wm, double vol); -WIIUSE_EXPORT extern void wiiuse_speaker_rate(struct wiimote_t* wm, byte rate, byte freq); -WIIUSE_EXPORT extern void wiiuse_speaker_config(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_data(struct wiimote_t* wm, byte* data, int len); - -#ifdef __cplusplus -} -#endif - - -#endif /* WIIUSE_H_INCLUDED */ - diff --git a/cpp/wiiuse/src/wiiuse_internal.h b/cpp/wiiuse/src/wiiuse_internal.h deleted file mode 100644 index fb623e3..0000000 --- a/cpp/wiiuse/src/wiiuse_internal.h +++ /dev/null @@ -1,229 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * @brief General internal wiiuse stuff. - * - * Since Wiiuse is a library, wiiuse.h is a duplicate - * of the API header. - * - * The code that would normally go in that file, but - * which is not needed by third party developers, - * is put here. - * - * So wiiuse_internal.h is included by other files - * internally, wiiuse.h is included only here. - */ - -#ifndef WIIUSE_INTERNAL_H_INCLUDED -#define WIIUSE_INTERNAL_H_INCLUDED - -#ifndef WIN32 - #include /* htons() */ - #include -#endif - -#include "definitions.h" - -/* wiiuse version */ -#define WIIUSE_VERSION "0.12" - -/******************** - * - * Wiimote internal codes - * - ********************/ - -/* Communication channels */ -#define WM_OUTPUT_CHANNEL 0x11 -#define WM_INPUT_CHANNEL 0x13 - -#define WM_SET_REPORT 0x50 - -/* commands */ -#define WM_CMD_LED 0x11 -#define WM_CMD_REPORT_TYPE 0x12 -#define WM_CMD_RUMBLE 0x13 -#define WM_CMD_IR 0x13 -#define WM_CMD_CTRL_STATUS 0x15 -#define WM_CMD_WRITE_DATA 0x16 -#define WM_CMD_READ_DATA 0x17 -#define WM_CMD_IR_2 0x1A - -/* input report ids */ -#define WM_RPT_CTRL_STATUS 0x20 -#define WM_RPT_READ 0x21 -#define WM_RPT_WRITE 0x22 -#define WM_RPT_BTN 0x30 -#define WM_RPT_BTN_ACC 0x31 -#define WM_RPT_BTN_ACC_IR 0x33 -#define WM_RPT_BTN_EXP 0x34 -#define WM_RPT_BTN_ACC_EXP 0x35 -#define WM_RPT_BTN_IR_EXP 0x36 -#define WM_RPT_BTN_ACC_IR_EXP 0x37 -#define WM_RPT_BALANCE_BOARD 0x40 - -#define WM_BT_INPUT 0x01 -#define WM_BT_OUTPUT 0x02 - -/* Identify the wiimote device by its class */ -#define WM_DEV_CLASS_0 0x04 -#define WM_DEV_CLASS_1 0x25 -#define WM_DEV_CLASS_2 0x00 -#define WM_VENDOR_ID 0x057E -#define WM_PRODUCT_ID 0x0306 - -/* controller status stuff */ -#define WM_MAX_BATTERY_CODE 0xC8 - -/* offsets in wiimote memory */ -#define WM_MEM_OFFSET_CALIBRATION 0x16 -#define WM_EXP_MEM_BASE 0x04A40000 -#define WM_EXP_MEM_ENABLE1 0x04A400F0 -#define WM_EXP_MEM_ENABLE2 0x04A400FB -#define WM_EXP_MEM_CALIBR 0x04A40020 - -#define WM_REG_IR 0x04B00030 -#define WM_REG_IR_BLOCK1 0x04B00000 -#define WM_REG_IR_BLOCK2 0x04B0001A -#define WM_REG_IR_MODENUM 0x04B00033 - -/* ir block data */ -#define WM_IR_BLOCK1_LEVEL1 "\x02\x00\x00\x71\x01\x00\x64\x00\xfe" -#define WM_IR_BLOCK2_LEVEL1 "\xfd\x05" -#define WM_IR_BLOCK1_LEVEL2 "\x02\x00\x00\x71\x01\x00\x96\x00\xb4" -#define WM_IR_BLOCK2_LEVEL2 "\xb3\x04" -#define WM_IR_BLOCK1_LEVEL3 "\x02\x00\x00\x71\x01\x00\xaa\x00\x64" -#define WM_IR_BLOCK2_LEVEL3 "\x63\x03" -#define WM_IR_BLOCK1_LEVEL4 "\x02\x00\x00\x71\x01\x00\xc8\x00\x36" -#define WM_IR_BLOCK2_LEVEL4 "\x35\x03" -#define WM_IR_BLOCK1_LEVEL5 "\x07\x00\x00\x71\x01\x00\x72\x00\x20" -#define WM_IR_BLOCK2_LEVEL5 "\x1f\x03" - -#define WM_IR_TYPE_BASIC 0x01 -#define WM_IR_TYPE_EXTENDED 0x03 - -/* controller status flags for the first message byte */ -/* bit 1 is unknown */ -#define WM_CTRL_STATUS_BYTE1_ATTACHMENT 0x02 -#define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED 0x04 -#define WM_CTRL_STATUS_BYTE1_IR_ENABLED 0x08 -#define WM_CTRL_STATUS_BYTE1_LED_1 0x10 -#define WM_CTRL_STATUS_BYTE1_LED_2 0x20 -#define WM_CTRL_STATUS_BYTE1_LED_3 0x40 -#define WM_CTRL_STATUS_BYTE1_LED_4 0x80 - -/* aspect ratio */ -#define WM_ASPECT_16_9_X 660 -#define WM_ASPECT_16_9_Y 370 -#define WM_ASPECT_4_3_X 560 -#define WM_ASPECT_4_3_Y 420 - - -/** - * Expansion stuff - */ - -/* encrypted expansion id codes (located at 0x04A400FC) */ -#define EXP_ID_CODE_NUNCHUK 0xA4200000 -#define EXP_ID_CODE_CLASSIC_CONTROLLER 0xA4200101 -#define EXP_ID_CODE_GUITAR 0xA4200103 -#define EXP_ID_CODE_BALANCE_BOARD 0xA4200402 - -#define EXP_HANDSHAKE_LEN 224 - -/******************** - * - * End Wiimote internal codes - * - ********************/ - -/* wiimote state flags - (some duplicated in wiiuse.h)*/ -#define WIIMOTE_STATE_DEV_FOUND 0x0001 -#define WIIMOTE_STATE_HANDSHAKE 0x0002 /* actual connection exists but no handshake yet */ -#define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x0004 /* actual connection exists but no handshake yet */ -#define WIIMOTE_STATE_CONNECTED 0x0008 -#define WIIMOTE_STATE_RUMBLE 0x0010 -#define WIIMOTE_STATE_ACC 0x0020 -#define WIIMOTE_STATE_EXP 0x0040 -#define WIIMOTE_STATE_IR 0x0080 -#define WIIMOTE_STATE_SPEAKER 0x0100 -#define WIIMOTE_STATE_IR_SENS_LVL1 0x0200 -#define WIIMOTE_STATE_IR_SENS_LVL2 0x0400 -#define WIIMOTE_STATE_IR_SENS_LVL3 0x0800 -#define WIIMOTE_STATE_IR_SENS_LVL4 0x1000 -#define WIIMOTE_STATE_IR_SENS_LVL5 0x2000 - -#define WIIMOTE_INIT_STATES (WIIMOTE_STATE_IR_SENS_LVL3) - -/* macro to manage states */ -#define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s)) -#define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s)) -#define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s)) -#define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s)) - -#define WIIMOTE_IS_FLAG_SET(wm, s) ((wm->flags & (s)) == (s)) -#define WIIMOTE_ENABLE_FLAG(wm, s) (wm->flags |= (s)) -#define WIIMOTE_DISABLE_FLAG(wm, s) (wm->flags &= ~(s)) -#define WIIMOTE_TOGGLE_FLAG(wm, s) ((wm->flags & (s)) ? WIIMOTE_DISABLE_FLAG(wm, s) : WIIMOTE_ENABLE_FLAG(wm, s)) - -#define NUNCHUK_IS_FLAG_SET(wm, s) ((*(wm->flags) & (s)) == (s)) - -/* misc macros */ -#define WIIMOTE_ID(wm) (wm->unid) -#define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED)) - -/* - * Smooth tilt calculations are computed with the - * exponential moving average formula: - * St = St_last + (alpha * (tilt - St_last)) - * alpha is between 0 and 1 - */ -#define WIIUSE_DEFAULT_SMOOTH_ALPHA 0.07f - -#define SMOOTH_ROLL 0x01 -#define SMOOTH_PITCH 0x02 - -#include "wiiuse.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* not part of the api */ -int wiiuse_set_report_type(struct wiimote_t* wm); -void wiiuse_send_next_pending_read_request(struct wiimote_t* wm); -int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len); -int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int offset, unsigned short len); - -#ifdef __cplusplus -} -#endif - -#endif /* WIIUSE_INTERNAL_H_INCLUDED */ diff --git a/cpp/wiiusej/.cproject b/cpp/wiiusej/.cproject deleted file mode 100644 index 1cd015a..0000000 --- a/cpp/wiiusej/.cproject +++ /dev/null @@ -1,177 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/wiiusej/.project b/cpp/wiiusej/.project deleted file mode 100644 index ef22ffd..0000000 --- a/cpp/wiiusej/.project +++ /dev/null @@ -1,71 +0,0 @@ - - - cpp.wiiusej - - - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - clean,full,incremental, - - - ?name? - - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.buildArguments - - - - org.eclipse.cdt.make.core.buildCommand - make - - - org.eclipse.cdt.make.core.buildLocation - ${workspace_loc:/WiiuseJ/Debug} - - - org.eclipse.cdt.make.core.contents - org.eclipse.cdt.make.core.activeConfigSettings - - - org.eclipse.cdt.make.core.enableAutoBuild - false - - - org.eclipse.cdt.make.core.enableCleanBuild - true - - - org.eclipse.cdt.make.core.enableFullBuild - true - - - org.eclipse.cdt.make.core.stopOnError - true - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - true - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - org.eclipse.cdt.core.cnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - org.eclipse.cdt.core.ccnature - - diff --git a/cpp/wiiusej/Debug/copy.bat b/cpp/wiiusej/Debug/copy.bat deleted file mode 100644 index 8ce62ea..0000000 --- a/cpp/wiiusej/Debug/copy.bat +++ /dev/null @@ -1 +0,0 @@ -copy wiiusej.dll ..\..\..\java\wiiusej\wiiusej.dll \ No newline at end of file diff --git a/cpp/wiiusej/Release/copy.bat b/cpp/wiiusej/Release/copy.bat deleted file mode 100644 index 8ce62ea..0000000 --- a/cpp/wiiusej/Release/copy.bat +++ /dev/null @@ -1 +0,0 @@ -copy wiiusej.dll ..\..\..\java\wiiusej\wiiusej.dll \ No newline at end of file diff --git a/cpp/wiiusej/Release/wiiusej.dll b/cpp/wiiusej/Release/wiiusej.dll deleted file mode 100644 index c50c645..0000000 Binary files a/cpp/wiiusej/Release/wiiusej.dll and /dev/null differ diff --git a/cpp/wiiusej/include/wiiuse.h b/cpp/wiiusej/include/wiiuse.h deleted file mode 100644 index bd3c27f..0000000 --- a/cpp/wiiusej/include/wiiuse.h +++ /dev/null @@ -1,710 +0,0 @@ -/* - * wiiuse - * - * Written By: - * Michael Laforest < para > - * Email: < thepara (--AT--) g m a i l [--DOT--] com > - * - * Copyright 2006-2007 - * - * This file is part of wiiuse. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * $Header$ - * - */ - -/** - * @file - * - * @brief API header file. - * - * If this file is included from inside the wiiuse source - * and not from a third party program, then wiimote_internal.h - * is also included which extends this file. - */ - -#ifndef WIIUSE_H_INCLUDED -#define WIIUSE_H_INCLUDED - -#ifdef _WIN32 - /* windows */ - #include -#else - /* nix */ - #include -#endif - -#ifdef WIIUSE_INTERNAL_H_INCLUDED - #define WCONST -#else - #define WCONST const -#endif - -/* led bit masks */ -#define WIIMOTE_LED_NONE 0x00 -#define WIIMOTE_LED_1 0x10 -#define WIIMOTE_LED_2 0x20 -#define WIIMOTE_LED_3 0x40 -#define WIIMOTE_LED_4 0x80 - -/* button codes */ -#define WIIMOTE_BUTTON_TWO 0x0001 -#define WIIMOTE_BUTTON_ONE 0x0002 -#define WIIMOTE_BUTTON_B 0x0004 -#define WIIMOTE_BUTTON_A 0x0008 -#define WIIMOTE_BUTTON_MINUS 0x0010 -#define WIIMOTE_BUTTON_ZACCEL_BIT6 0x0020 -#define WIIMOTE_BUTTON_ZACCEL_BIT7 0x0040 -#define WIIMOTE_BUTTON_HOME 0x0080 -#define WIIMOTE_BUTTON_LEFT 0x0100 -#define WIIMOTE_BUTTON_RIGHT 0x0200 -#define WIIMOTE_BUTTON_DOWN 0x0400 -#define WIIMOTE_BUTTON_UP 0x0800 -#define WIIMOTE_BUTTON_PLUS 0x1000 -#define WIIMOTE_BUTTON_ZACCEL_BIT4 0x2000 -#define WIIMOTE_BUTTON_ZACCEL_BIT5 0x4000 -#define WIIMOTE_BUTTON_UNKNOWN 0x8000 -#define WIIMOTE_BUTTON_ALL 0x1F9F - -/* nunchul button codes */ -#define NUNCHUK_BUTTON_Z 0x01 -#define NUNCHUK_BUTTON_C 0x02 -#define NUNCHUK_BUTTON_ALL 0x03 - -/* classic controller button codes */ -#define CLASSIC_CTRL_BUTTON_UP 0x0001 -#define CLASSIC_CTRL_BUTTON_LEFT 0x0002 -#define CLASSIC_CTRL_BUTTON_ZR 0x0004 -#define CLASSIC_CTRL_BUTTON_X 0x0008 -#define CLASSIC_CTRL_BUTTON_A 0x0010 -#define CLASSIC_CTRL_BUTTON_Y 0x0020 -#define CLASSIC_CTRL_BUTTON_B 0x0040 -#define CLASSIC_CTRL_BUTTON_ZL 0x0080 -#define CLASSIC_CTRL_BUTTON_FULL_R 0x0200 -#define CLASSIC_CTRL_BUTTON_PLUS 0x0400 -#define CLASSIC_CTRL_BUTTON_HOME 0x0800 -#define CLASSIC_CTRL_BUTTON_MINUS 0x1000 -#define CLASSIC_CTRL_BUTTON_FULL_L 0x2000 -#define CLASSIC_CTRL_BUTTON_DOWN 0x4000 -#define CLASSIC_CTRL_BUTTON_RIGHT 0x8000 -#define CLASSIC_CTRL_BUTTON_ALL 0xFEFF - -/* guitar hero 3 button codes */ -#define GUITAR_HERO_3_BUTTON_STRUM_UP 0x0001 -#define GUITAR_HERO_3_BUTTON_YELLOW 0x0008 -#define GUITAR_HERO_3_BUTTON_GREEN 0x0010 -#define GUITAR_HERO_3_BUTTON_BLUE 0x0020 -#define GUITAR_HERO_3_BUTTON_RED 0x0040 -#define GUITAR_HERO_3_BUTTON_ORANGE 0x0080 -#define GUITAR_HERO_3_BUTTON_PLUS 0x0400 -#define GUITAR_HERO_3_BUTTON_MINUS 0x1000 -#define GUITAR_HERO_3_BUTTON_STRUM_DOWN 0x4000 -#define GUITAR_HERO_3_BUTTON_ALL 0xFEFF - - -/* wiimote option flags */ -#define WIIUSE_SMOOTHING 0x01 -#define WIIUSE_CONTINUOUS 0x02 -#define WIIUSE_ORIENT_THRESH 0x04 -#define WIIUSE_INIT_FLAGS (WIIUSE_SMOOTHING | WIIUSE_ORIENT_THRESH) - -#define WIIUSE_ORIENT_PRECISION 100.0f - -/* expansion codes */ -#define EXP_NONE 0 -#define EXP_NUNCHUK 1 -#define EXP_CLASSIC 2 -#define EXP_GUITAR_HERO_3 3 -#define EXP_BALANCE_BOARD 4 - -/* IR correction types */ -typedef enum ir_position_t { - WIIUSE_IR_ABOVE, - WIIUSE_IR_BELOW -} ir_position_t; - -/** - * @brief Check if a button is pressed. - * @param dev Pointer to a wiimote_t or expansion structure. - * @param button The button you are interested in. - * @return 1 if the button is pressed, 0 if not. - */ -#define IS_PRESSED(dev, button) ((dev->btns & button) == button) - -/** - * @brief Check if a button is being held. - * @param dev Pointer to a wiimote_t or expansion structure. - * @param button The button you are interested in. - * @return 1 if the button is held, 0 if not. - */ -#define IS_HELD(dev, button) ((dev->btns_held & button) == button) - -/** - * @brief Check if a button is released on this event. \n\n - * This does not mean the button is not pressed, it means \n - * this button was just now released. - * @param dev Pointer to a wiimote_t or expansion structure. - * @param button The button you are interested in. - * @return 1 if the button is released, 0 if not. - * - */ -#define IS_RELEASED(dev, button) ((dev->btns_released & button) == button) - -/** - * @brief Check if a button has just been pressed this event. - * @param dev Pointer to a wiimote_t or expansion structure. - * @param button The button you are interested in. - * @return 1 if the button is pressed, 0 if not. - */ -#define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button)) - -/** - * @brief Return the IR sensitivity level. - * @param wm Pointer to a wiimote_t structure. - * @param lvl [out] Pointer to an int that will hold the level setting. - * If no level is set 'lvl' will be set to 0. - */ -#define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \ - do { \ - if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \ - else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \ - else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \ - else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \ - else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \ - else *lvl = 0; \ - } while (0) - -#define WIIUSE_USING_ACC(wm) ((wm->state & 0x020) == 0x020) -#define WIIUSE_USING_EXP(wm) ((wm->state & 0x040) == 0x040) -#define WIIUSE_USING_IR(wm) ((wm->state & 0x080) == 0x080) -#define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x100) == 0x100) - -#define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num) - -/* - * Largest known payload is 21 bytes. - * Add 2 for the prefix and round up to a power of 2. - */ -#define MAX_PAYLOAD 32 - -/* - * This is left over from an old hack, but it may actually - * be a useful feature to keep so it wasn't removed. - */ -#ifdef WIN32 - #define WIIMOTE_DEFAULT_TIMEOUT 10 - #define WIIMOTE_EXP_TIMEOUT 10 -#endif - -typedef unsigned char byte; -typedef char sbyte; - -struct wiimote_t; -struct vec3b_t; -struct orient_t; -struct gforce_t; - - -/** - * @brief Callback that handles a read event. - * - * @param wm Pointer to a wiimote_t structure. - * @param data Pointer to the filled data block. - * @param len Length in bytes of the data block. - * - * @see wiiuse_init() - * - * A registered function of this type is called automatically by the wiiuse - * library when the wiimote has returned the full data requested by a previous - * call to wiiuse_read_data(). - */ -typedef void (*wiiuse_read_cb)(struct wiimote_t* wm, byte* data, unsigned short len); - - -/** - * @struct read_req_t - * @brief Data read request structure. - */ -struct read_req_t { - wiiuse_read_cb cb; /**< read data callback */ - byte* buf; /**< buffer where read data is written */ - unsigned int addr; /**< the offset that the read started at */ - unsigned short size; /**< the length of the data read */ - unsigned short wait; /**< num bytes still needed to finish read */ - byte dirty; /**< set to 1 if not using callback and needs to be cleaned up */ - - struct read_req_t* next; /**< next read request in the queue */ -}; - - -/** - * @struct vec2b_t - * @brief Unsigned x,y byte vector. - */ -typedef struct vec2b_t { - byte x, y; -} vec2b_t; - - -/** - * @struct vec3b_t - * @brief Unsigned x,y,z byte vector. - */ -typedef struct vec3b_t { - byte x, y, z; -} vec3b_t; - - -/** - * @struct vec3f_t - * @brief Signed x,y,z float struct. - */ -typedef struct vec3f_t { - float x, y, z; -} vec3f_t; - - -/** - * @struct orient_t - * @brief Orientation struct. - * - * Yaw, pitch, and roll range from -180 to 180 degrees. - */ -typedef struct orient_t { - float roll; /**< roll, this may be smoothed if enabled */ - float pitch; /**< pitch, this may be smoothed if enabled */ - float yaw; - - float a_roll; /**< absolute roll, unsmoothed */ - float a_pitch; /**< absolute pitch, unsmoothed */ -} orient_t; - - -/** - * @struct gforce_t - * @brief Gravity force struct. - */ -typedef struct gforce_t { - float x, y, z; -} gforce_t; - - -/** - * @struct accel_t - * @brief Accelerometer struct. For any device with an accelerometer. - */ -typedef struct accel_t { - struct vec3b_t cal_zero; /**< zero calibration */ - struct vec3b_t cal_g; /**< 1g difference around 0cal */ - - float st_roll; /**< last smoothed roll value */ - float st_pitch; /**< last smoothed roll pitch */ - float st_alpha; /**< alpha value for smoothing [0-1] */ -} accel_t; - - -/** - * @struct ir_dot_t - * @brief A single IR source. - */ -typedef struct ir_dot_t { - byte visible; /**< if the IR source is visible */ - - unsigned int x; /**< interpolated X coordinate */ - unsigned int y; /**< interpolated Y coordinate */ - - short rx; /**< raw X coordinate (0-1023) */ - short ry; /**< raw Y coordinate (0-767) */ - - byte order; /**< increasing order by x-axis value */ - - byte size; /**< size of the IR dot (0-15) */ -} ir_dot_t; - - -/** - * @enum aspect_t - * @brief Screen aspect ratio. - */ -typedef enum aspect_t { - WIIUSE_ASPECT_4_3, - WIIUSE_ASPECT_16_9 -} aspect_t; - - -/** - * @struct ir_t - * @brief IR struct. Hold all data related to the IR tracking. - */ -typedef struct ir_t { - struct ir_dot_t dot[4]; /**< IR dots */ - byte num_dots; /**< number of dots at this time */ - - enum aspect_t aspect; /**< aspect ratio of the screen */ - - enum ir_position_t pos; /**< IR sensor bar position */ - - unsigned int vres[2]; /**< IR virtual screen resolution */ - int offset[2]; /**< IR XY correction offset */ - int state; /**< keeps track of the IR state */ - - int ax; /**< absolute X coordinate */ - int ay; /**< absolute Y coordinate */ - - int x; /**< calculated X coordinate */ - int y; /**< calculated Y coordinate */ - - float distance; /**< pixel distance between first 2 dots*/ - float z; /**< calculated distance */ -} ir_t; - - -/** - * @struct speaker_t - */ -typedef struct speaker_t { - byte format; - byte rate; - byte freq; - byte vol; -} speaker_t; - - -/** - * @struct joystick_t - * @brief Joystick calibration structure. - * - * The angle \a ang is relative to the positive y-axis into quadrant I - * and ranges from 0 to 360 degrees. So if the joystick is held straight - * upwards then angle is 0 degrees. If it is held to the right it is 90, - * down is 180, and left is 270. - * - * The magnitude \a mag is the distance from the center to where the - * joystick is being held. The magnitude ranges from 0 to 1. - * If the joystick is only slightly tilted from the center the magnitude - * will be low, but if it is closer to the outter edge the value will - * be higher. - */ -typedef struct joystick_t { - struct vec2b_t max; /**< maximum joystick values */ - struct vec2b_t min; /**< minimum joystick values */ - struct vec2b_t center; /**< center joystick values */ - - float ang; /**< angle the joystick is being held */ - float mag; /**< magnitude of the joystick (range 0-1) */ -} joystick_t; - - -/** - * @struct nunchuk_t - * @brief Nunchuk expansion device. - */ -typedef struct nunchuk_t { - struct accel_t accel_calib; /**< nunchuk accelerometer calibration */ - struct joystick_t js; /**< joystick calibration */ - - int* flags; /**< options flag (points to wiimote_t.flags) */ - - byte btns; /**< what buttons have just been pressed */ - byte btns_held; /**< what buttons are being held down */ - byte btns_released; /**< what buttons were just released this */ - - float orient_threshold; /**< threshold for orient to generate an event */ - int accel_threshold; /**< threshold for accel to generate an event */ - - struct vec3b_t accel; /**< current raw acceleration data */ - struct orient_t orient; /**< current orientation on each axis */ - struct gforce_t gforce; /**< current gravity forces on each axis */ -} nunchuk_t; - - -/** - * @struct classic_ctrl_t - * @brief Classic controller expansion device. - */ -typedef struct classic_ctrl_t { - short btns; /**< what buttons have just been pressed */ - short btns_held; /**< what buttons are being held down */ - short btns_released; /**< what buttons were just released this */ - - float r_shoulder; /**< right shoulder button (range 0-1) */ - float l_shoulder; /**< left shoulder button (range 0-1) */ - - struct joystick_t ljs; /**< left joystick calibration */ - struct joystick_t rjs; /**< right joystick calibration */ -} classic_ctrl_t; - - -/** - * @struct guitar_hero_3_t - * @brief Guitar Hero 3 expansion device. - */ -typedef struct guitar_hero_3_t { - short btns; /**< what buttons have just been pressed */ - short btns_held; /**< what buttons are being held down */ - short btns_released; /**< what buttons were just released this */ - - float whammy_bar; /**< whammy bar (range 0-1) */ - - struct joystick_t js; /**< joystick calibration */ -} guitar_hero_3_t; - - -/** - * @struct balance_board_data_t - * @brief Balance board l/r, t/b corner data data. - */ -typedef struct balance_board_data_t { - int tr; - int br; - int tl; - int bl; -} balance_board_data_t; - - -/** - * @struct balance_board_t - * @brief Balance board expansion device. - */ -typedef struct balance_board_t { - float tr; /** Top Right weight */ - float br; /** Bottom Right weight */ - float tl; /** Top Left weight */ - float bl; /** Bottom Left weight */ - struct balance_board_data_t raw; /** Raw actual values */ - struct balance_board_data_t cal_0; /** Calibration values at 0kg */ - struct balance_board_data_t cal_17; /** Calibration values at 17kg */ - struct balance_board_data_t cal_34; /** Calibration values at 34kg */ -} balance_board_t; - - -/** - * @struct expansion_t - * @brief Generic expansion device plugged into wiimote. - */ -typedef struct expansion_t { - int type; /**< type of expansion attached */ - - union { - struct nunchuk_t nunchuk; - struct classic_ctrl_t classic; - struct guitar_hero_3_t gh3; - struct balance_board_t bb; - }; -} expansion_t; - - -/** - * @enum win32_bt_stack_t - * @brief Available bluetooth stacks for Windows. - */ -typedef enum win_bt_stack_t { - WIIUSE_STACK_UNKNOWN, - WIIUSE_STACK_MS, - WIIUSE_STACK_BLUESOLEIL -} win_bt_stack_t; - - -/** - * @struct wiimote_state_t - * @brief Significant data from the previous event. - */ -typedef struct wiimote_state_t { - /* expansion_t */ - float exp_ljs_ang; - float exp_rjs_ang; - float exp_ljs_mag; - float exp_rjs_mag; - unsigned short exp_btns; - struct orient_t exp_orient; - struct vec3b_t exp_accel; - float exp_r_shoulder; - float exp_l_shoulder; - struct balance_board_data_t exp_bb_raw; - - /* ir_t */ - int ir_ax; - int ir_ay; - float ir_distance; - - struct orient_t orient; - unsigned short btns; - - struct vec3b_t accel; -} wiimote_state_t; - - -/** - * @enum WIIUSE_EVENT_TYPE - * @brief Events that wiiuse can generate from a poll. - */ -typedef enum WIIUSE_EVENT_TYPE { - WIIUSE_NONE = 0, - WIIUSE_EVENT, - WIIUSE_STATUS, - WIIUSE_CONNECT, - WIIUSE_DISCONNECT, - WIIUSE_UNEXPECTED_DISCONNECT, - WIIUSE_READ_DATA, - WIIUSE_NUNCHUK_INSERTED, - WIIUSE_NUNCHUK_REMOVED, - WIIUSE_CLASSIC_CTRL_INSERTED, - WIIUSE_CLASSIC_CTRL_REMOVED, - WIIUSE_GUITAR_HERO_3_CTRL_INSERTED, - WIIUSE_GUITAR_HERO_3_CTRL_REMOVED, - WIIUSE_BALANCE_BOARD_CTRL_INSERTED, - WIIUSE_BALANCE_BOARD_CTRL_REMOVED -} WIIUSE_EVENT_TYPE; - -/** - * @struct wiimote_t - * @brief Wiimote structure. - */ -typedef struct wiimote_t { - WCONST int unid; /**< user specified id */ - - #ifndef WIN32 - WCONST bdaddr_t bdaddr; /**< bt address */ - WCONST char bdaddr_str[18]; /**< readable bt address */ - WCONST int out_sock; /**< output socket */ - WCONST int in_sock; /**< input socket */ - #else - WCONST HANDLE dev_handle; /**< HID handle */ - WCONST OVERLAPPED hid_overlap; /**< overlap handle */ - WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */ - WCONST int timeout; /**< read timeout */ - WCONST byte normal_timeout; /**< normal timeout */ - WCONST byte exp_timeout; /**< timeout for expansion handshake */ - #endif - - WCONST int state; /**< various state flags */ - WCONST byte leds; /**< currently lit leds */ - WCONST float battery_level; /**< battery level */ - - WCONST int flags; /**< options flag */ - - WCONST byte handshake_state; /**< the state of the connection handshake */ - - WCONST struct read_req_t* read_req; /**< list of data read requests */ - WCONST struct accel_t accel_calib; /**< wiimote accelerometer calibration */ - WCONST struct expansion_t exp; /**< wiimote expansion device */ - - WCONST struct vec3b_t accel; /**< current raw acceleration data */ - WCONST struct orient_t orient; /**< current orientation on each axis */ - WCONST struct gforce_t gforce; /**< current gravity forces on each axis */ - - WCONST struct ir_t ir; /**< IR data */ - WCONST struct speaker_t speaker; /**< speaker */ - - WCONST unsigned short btns; /**< what buttons have just been pressed */ - WCONST unsigned short btns_held; /**< what buttons are being held down */ - WCONST unsigned short btns_released; /**< what buttons were just released this */ - - WCONST float orient_threshold; /**< threshold for orient to generate an event */ - WCONST int accel_threshold; /**< threshold for accel to generate an event */ - - WCONST struct wiimote_state_t lstate; /**< last saved state */ - - WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occured */ - WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */ -} wiimote; - - -/***************************************** - * - * Include API specific stuff - * - *****************************************/ - -#ifdef _WIN32 - #define WIIUSE_EXPORT_DECL __declspec(dllexport) - #define WIIUSE_IMPORT_DECL __declspec(dllimport) -#else - #define WIIUSE_EXPORT_DECL - #define WIIUSE_IMPORT_DECL -#endif - -#ifdef WIIUSE_COMPILE_LIB - #define WIIUSE_EXPORT WIIUSE_EXPORT_DECL -#else - #define WIIUSE_EXPORT WIIUSE_IMPORT_DECL -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* wiiuse.c */ -WIIUSE_EXPORT extern const char* wiiuse_version(); - -WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes); -WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes); -WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status); -WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds); -WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status); -WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, unsigned short len); -WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len); -WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm); -WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid); -WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable); -WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha); -WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type); -WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold); -WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout); -WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold); - -/* connect.c */ -WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout); -WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes); -WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm); - -/* events.c */ -WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes); - -/* ir.c */ -WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status); -WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y); -WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos); -WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect); -WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level); - -/* nunchuk.c */ -WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold); -WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold); - -/* speaker.c */ -WIIUSE_EXPORT extern void wiiuse_speaker_enable(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_disable(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_mute(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_unmute(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_activate(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_deactivate(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_format(struct wiimote_t* wm, byte format); -WIIUSE_EXPORT extern void wiiuse_speaker_volume(struct wiimote_t* wm, double vol); -WIIUSE_EXPORT extern void wiiuse_speaker_rate(struct wiimote_t* wm, byte rate, byte freq); -WIIUSE_EXPORT extern void wiiuse_speaker_config(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_speaker_data(struct wiimote_t* wm, byte* data, int len); - -#ifdef __cplusplus -} -#endif - - -#endif /* WIIUSE_H_INCLUDED */ - diff --git a/cpp/wiiusej/lib/wiiuse.lib b/cpp/wiiusej/lib/wiiuse.lib deleted file mode 100644 index b9cc79d..0000000 Binary files a/cpp/wiiusej/lib/wiiuse.lib and /dev/null differ diff --git a/cpp/wiiusej/src/wiiusej_WiiUseApi.c b/cpp/wiiusej/src/wiiusej_WiiUseApi.c deleted file mode 100644 index fe3b4a8..0000000 --- a/cpp/wiiusej/src/wiiusej_WiiUseApi.c +++ /dev/null @@ -1,768 +0,0 @@ -/** - * This file is part of WiiuseJ. - * - * WiiuseJ is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * WiiuseJ 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. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WiiuseJ. If not, see . - */ -#ifndef WIN32 -#include -#endif - -#include "wiiusej_WiiUseApi.h" -#include "wiiuse.h" -/* - * These are some identifiers for wiimotes - * - * See below in main() for what they are used for. - */ -#define WIIMOTE_STATE_RUMBLE 0x0010 -#define WIIMOTE_STATE_CONNECTED 0x0008 -#define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s)) -#define WIIMOTE_IS_FLAG_SET(wm, s) ((wm->flags & (s)) == (s)) -#define WIIUSE_GET_IR_SENSITIVITY_CORRECTED(wm, lvl) \ - do { \ - if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \ - else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \ - else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \ - else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \ - else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \ - else *lvl = 0; \ - } while (0) - -/********************* VARIABLES DECLARATIONS *****************************/ - -/* - * Make a temp array of wiimote ids. - * Here I only anticipate connecting up to - * two wiimotes. Each wiimote connected - * will get one of these ids. - */ -static wiimote** wiimotes; -static int nbMaxWiimotes; - -/****************** GENERAL FUNCTIONS DEFINITIONS *************************/ - -/** - * Connect to a wiimote or wiimotes once an address is known. - * @param nbWiimotes The number of wiimotes. - * @return The number of wiimotes that successfully connected. - */ -JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_connect -(JNIEnv *env, jobject obj, jint nbWiimotes) { - return wiiuse_connect(wiimotes, nbWiimotes); -} - -/** - * Find a wiimote or wiimotes. - * @param nbMaxWiimotes The number of wiimotes. - * @param timeout The number of seconds before the search times out. - * @return The number of wiimotes found. - */ -JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_find -(JNIEnv *env, jobject obj, jint nbMaxWiimotes, jint timeout) { - return wiiuse_find(wiimotes, nbMaxWiimotes, timeout); -} - -/** - * Initialize an array of wiimote structures (for the C side of the library). - * @param nbPossibleWiimotes size of the array. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_init -(JNIEnv *env, jobject obj, jint nbPossibleWiimotes) { - wiimotes = wiiuse_init(nbPossibleWiimotes); - nbMaxWiimotes = nbPossibleWiimotes; -} - -/** - * Close connection to the wiimote with the given id. - * - * @param id the id of the wiimote to disconnect.Must be 1 or 2. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_closeConnection -(JNIEnv *env, jobject obj, jint id) { - wiiuse_disconnect(wiimotes[id]); -} - -/** - * Get unique id of a wiimote in the wiimotes array. - * Please make sure you call an existing index with a - * wiimote initialized at this index, - * other wise you'll get a wrong value. - * @param index index of the wiimote in the wiimotes array. - */ -JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_getUnId -(JNIEnv *env, jobject obj, jint index) { - return wiimotes[index]->unid; -} - -/** - * Shutdown api. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_cleanUp -(JNIEnv *env, jobject obj) { - wiiuse_cleanup(wiimotes, nbMaxWiimotes); -} - -/** - * Activate rumble for the wiimote with the given id. - * @param id the id of the wiimote.Must be 1 or 2. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateRumble -(JNIEnv *env, jobject obj, jint id) { - wiiuse_rumble(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 1); -} - -/** - * Deactivate rumble for the wiimote with the given id. - * @param id the id of the wiimote.Must be 1 or 2. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateRumble -(JNIEnv *env, jobject obj, jint id) { - wiiuse_rumble(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0); -} - -/** - * Activate IR TRacking for the wiimote with the given id. - * @param id the id of the wiimote. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateIRTracking -(JNIEnv *env, jobject obj, jint id) { - wiiuse_set_ir(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 1); -} - -/** - * Deactivate IR TRacking for the wiimote with the given id. - * @param id the id of the wiimote.Must be 1 or 2. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateIRTracking -(JNIEnv *env, jobject obj, jint id) { - wiiuse_set_ir(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0); -} - -/** - * Activate Motion Sensing for the wiimote with the given id. - * @param id the id of the wiimote.Must be 1 or 2. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateMotionSensing -(JNIEnv *env, jobject obj, jint id) { - wiiuse_motion_sensing(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 1); -} - -/** - * Deactivate Motion Sensing for the wiimote with the given id. - * @param id the id of the wiimote.Must be 1 or 2. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateMotionSensing -(JNIEnv *env, jobject obj, jint id) { - wiiuse_motion_sensing(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0); -} - -/** - * Set wiimote leds status. - * @param id the id of the wiimote concerned - * @param led1 status of led1: True=ON, False=OFF - * @param led2 status of led2: True=ON, False=OFF - * @param led3 status of led3: True=ON, False=OFF - * @param led4 status of led4: True=ON, False=OFF - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setLeds -(JNIEnv *env, jobject obj, jint id, jboolean led1, jboolean led2, jboolean led3, jboolean led4) { - int leds = 0; - - if (led1) leds |= WIIMOTE_LED_1; - if (led2) leds |= WIIMOTE_LED_2; - if (led3) leds |= WIIMOTE_LED_3; - if (led4) leds |= WIIMOTE_LED_4; - - wiiuse_set_leds(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), leds); -} - -/** - * Set how many degrees an angle must change to generate an event. - * @param id id of the wiimote concerned - * @param thresh minimum angle detected by an event - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setOrientThreshold -(JNIEnv *env, jobject obj, jint id, jfloat thresh) { - wiiuse_set_orient_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), thresh); -} - -/** - * Set how much acceleration must change to generate an event. - * @param id id of the wiimote concerned - * @param val minimum value detected by an event - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAccelThreshold -(JNIEnv *env, jobject obj, jint id, jint val) { - wiiuse_set_accel_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), val); -} - -/** - * Set alpha smoothing parameter for the given id. - * @param id id of the wiimote concerned - * @param value alpha smoothing value - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAlphaSmoothing -(JNIEnv *env, jobject obj, jint id, jfloat val) { - wiiuse_set_smooth_alpha(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), val); -} - -/** - * Try to resync with the wiimote by starting a new handshake. - * @param id id of the wiimote concerned - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_reSync -(JNIEnv *env, jobject obj, jint id) { - wiiuse_resync(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); -} - -/** - * Make the the accelerometers give smoother results. - * This is set by default. - * @param id the id of the wiimote concerned - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSmoothing -(JNIEnv *env, jobject obj, jint id) { - wiiuse_set_flags(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_SMOOTHING, 0); -} - -/** - * Make the the accelerometers give raw results. - * @param id the id of the wiimote concerned - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSmoothing -(JNIEnv *env, jobject obj, jint id) { - wiiuse_set_flags(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0, WIIUSE_SMOOTHING); -} - -/** - * Make the wiimote generate an event each time we poll. - * Not set by default. - * @param id the id of the wiimote concerned - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateContinuous -(JNIEnv *env, jobject obj, jint id) { - wiiuse_set_flags(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_CONTINUOUS, 0); -} - -/** - * Make the wiimote generate an event only when there is one. - * (default behavior) - * @param id the id of the wiimote concerned - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateContinuous -(JNIEnv *env, jobject obj, jint id) { - wiiuse_set_flags(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0, WIIUSE_CONTINUOUS); -} - -/** - * Notify wiiuse that your screen has an aspect ratio of 4/3. - * @param id the id of the wiimote concerned - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio43 -(JNIEnv *env, jobject obj, jint id) { - wiiuse_set_aspect_ratio(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_ASPECT_4_3); -} - -/** - * Notify wiiuse that your screen has an aspect ratio of 16/9. - * @param id the id of the wiimote concerned - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio169 -(JNIEnv *env, jobject obj, jint id) { - wiiuse_set_aspect_ratio(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_ASPECT_4_3); -} - -/** - * Notify wiiuse that the sensor bar is above your screen. - * @param id the id of the wiimote concerned - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarAboveScreen -(JNIEnv *env, jobject obj, jint id) { - wiiuse_set_ir_position(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_IR_ABOVE); -} - -/** - * Notify wiiuse that the sensor bar is below your screen. - * @param id the id of the wiimote concerned - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarBelowScreen -(JNIEnv *env, jobject obj, jint id) { - wiiuse_set_ir_position(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_IR_BELOW); -} - -/** - * Set virtual screen resolution. It is used to automatically - * compute the position of a cursor on this virtual screen - * using the sensor bar. These results come in the IREvent. - * @param id the id of the wiimote concerned - * @param x x resolution. - * @param y y resolution. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setVirtualScreenResolution -(JNIEnv *env, jobject obj, jint id, jint x, jint y) { - wiiuse_set_ir_vres(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), x, y); -} - -/** - * Get status from the wiimotes and send it through call backs. - * - * @param id the id of the wiimote. Must be 1 or 2. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_getStatus -(JNIEnv *env, jobject obj, jint id) { - wiiuse_status(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); -} - -/** - * Set the normal and expansion handshake timeouts. - * - * @param id - * the id of the wiimote concerned. - * @param normalTimeout - * The timeout in milliseconds for a normal read. - * @param expansionTimeout - * The timeout in millisecondsd to wait for an expansion - * handshake. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setTimeout -(JNIEnv *env, jobject obj, jint id, jshort normalTimeout, jshort expansionTimeout) { - wiiuse_set_timeout(wiimotes, nbMaxWiimotes, (byte) normalTimeout, (byte) expansionTimeout); -} - -/** - * Set the IR sensitivity. - * - * @param id - * the id of the wiimote concerned. - * @param level - * 1-5, same as Wii system sensitivity setting. If the level is < - * 1, then level will be set to 1. If the level is > 5, then - * level will be set to 5. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setIrSensitivity -(JNIEnv *env, jobject obj, jint id, jint level) { - wiiuse_set_ir_sensitivity(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), level); -} - -/** - * Set how many degrees an angle must change to generate an event for the nunchuk. - * @param id id of the wiimote concerned - * @param thresh minimum angle detected by an event - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukOrientationThreshold -(JNIEnv *env, jobject obj, jint id, jfloat thresh) { - wiiuse_set_nunchuk_orient_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), thresh); -} - -/** - * Set how much acceleration must change to generate an event for the nunchuk. - * @param id id of the wiimote concerned - * @param val minimum value detected by an event - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukAccelerationThreshold -(JNIEnv *env, jobject obj, jint id, jint val) { - wiiuse_set_nunchuk_accel_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), val); -} - -/** - * Force the bluetooth stack type.(useful only for windows) - * - * @param bluetoothStackType - * must be WiiUseApi.WIIUSE_STACK_UNKNOWN or WiiUseApi.WIIUSE_STACK_MS or - * WiiUseApi.WIIUSE_STACK_BLUESOLEIL. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_windowsSetBluetoothStack -(JNIEnv *env, jobject obj, jint bluetoothStackType) { - if (bluetoothStackType == 0) { - wiiuse_set_bluetooth_stack(wiimotes, nbMaxWiimotes, WIIUSE_STACK_UNKNOWN); - } else if (bluetoothStackType == 1) { - wiiuse_set_bluetooth_stack(wiimotes, nbMaxWiimotes, WIIUSE_STACK_MS); - } else if (bluetoothStackType == 2) { - wiiuse_set_bluetooth_stack(wiimotes, nbMaxWiimotes, WIIUSE_STACK_BLUESOLEIL); - } -} - -/** - * Get status and values from the wiimotes and send it through callbacks. - * @param wim the wiimote object to fill with the datas. - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll -(JNIEnv *env, jobject obj, jobject gath) { - /* Variables Declarations */ - int i, a; - short leds = 0; - jclass cls = (*env)->GetObjectClass(env, gath); - jmethodID mid; - - //printf("avant poll, nbMaxwiimotes : %i \n",nbMaxWiimotes); - if (wiiuse_poll(wiimotes, nbMaxWiimotes)) { - /* - * This happens if something happened on any wiimote. - * So go through each one and check if anything happened. - */ - //printf("il y a des events\n"); - for (i=0; i < nbMaxWiimotes; ++i) { - //printf("recupe events wiimote : %i\n",nbMaxWiimotes); - switch (wiimotes[i]->event) { - case WIIUSE_EVENT: - /* a generic event occured */ - - //printf("Generic event\n"); - mid = (*env)->GetMethodID(env, cls, "prepareWiiMoteEvent", "(ISSS)V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid, wiimotes[i]->btns, - wiimotes[i]->btns_released, wiimotes[i]->btns_held); - /* - * If IR tracking is enabled then print the coordinates - * on the virtual screen that the wiimote is pointing to. - * - * Also make sure that we see at least 1 dot. - */ - if (WIIUSE_USING_IR(wiimotes[i])) { - //printf("IR event\n"); - - WIIUSE_GET_IR_SENSITIVITY_CORRECTED(wiimotes[i], &a); - - mid = (*env)->GetMethodID(env, cls, "prepareIRevent", "(IIFIIIIIISSSF)V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid, - wiimotes[i]->ir.x, wiimotes[i]->ir.y, wiimotes[i]->ir.z, - wiimotes[i]->ir.ax, wiimotes[i]->ir.ay, - wiimotes[i]->ir.vres[0], wiimotes[i]->ir.vres[1], - wiimotes[i]->ir.offset[0], wiimotes[i]->ir.offset[1], - wiimotes[i]->ir.pos, wiimotes[i]->ir.aspect, - a , wiimotes[i]->ir.distance); - - mid = (*env)->GetMethodID(env, cls, "addIRPointToPreparedWiiMoteEvent", - "(IISSS)V"); - if (mid == 0) { - return; - } - /* go through each of the 4 possible IR sources */ - for (a=0; a < 4; a++) { - /* check if the source is visible */ - if (wiimotes[i]->ir.dot[a].visible) { - (*env)->CallVoidMethod(env, gath, mid, - wiimotes[i]->ir.dot[a].x, wiimotes[i]->ir.dot[a].y, - wiimotes[i]->ir.dot[a].rx, wiimotes[i]->ir.dot[a].ry, - wiimotes[i]->ir.dot[a].size); - } - } - } - - /* Motion Sensing */ - if (WIIUSE_USING_ACC(wiimotes[i])) { - //printf("acc event\n"); - /* set orientation and gravity force */ - mid = (*env)->GetMethodID(env, cls, - "addMotionSensingValues", "(FIZFFFFFFFFFSSS)V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid, - wiimotes[i]->orient_threshold, wiimotes[i]->accel_threshold, - WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_SMOOTHING), wiimotes[i]->accel_calib.st_alpha, - wiimotes[i]->orient.roll, wiimotes[i]->orient.pitch, wiimotes[i]->orient.yaw, - wiimotes[i]->orient.a_roll, wiimotes[i]->orient.a_pitch, - wiimotes[i]->gforce.x, wiimotes[i]->gforce.y, wiimotes[i]->gforce.z, - wiimotes[i]->accel.x, wiimotes[i]->accel.y, wiimotes[i]->accel.z); - } - - /* Expansions support support*/ - if (WIIUSE_USING_EXP(wiimotes[i])) { - /* Nunchuk support */ - if (wiimotes[i]->exp.type == EXP_NUNCHUK) { - /* put nunchuk values in wiimote generic event */ - mid = (*env)->GetMethodID(env, cls, - "addNunchunkEventToPreparedWiimoteEvent", "(SSSFIZFFFFFFFFFSSSFFSSSSSS)V"); - if (mid == 0) { - return; - } - struct nunchuk_t* nc = (nunchuk_t*)&wiimotes[i]->exp.nunchuk; - - (*env)->CallVoidMethod(env, gath, mid, - /* buttons */ - nc->btns,nc->btns_released,nc->btns_held, - /* motion sensing */ - nc->orient_threshold,nc->accel_threshold, - WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_SMOOTHING),nc->accel_calib.st_alpha, - nc->orient.roll, nc->orient.pitch, nc->orient.yaw, - nc->orient.a_roll, nc->orient.a_pitch, - nc->gforce.x, nc->gforce.y, nc->gforce.z, - nc->accel.x, nc->accel.y, nc->accel.z, - /* joystick */ - nc->js.ang,nc->js.mag, - nc->js.max.x,nc->js.max.y, - nc->js.min.x,nc->js.min.y, - nc->js.center.x,nc->js.center.y); - } else if (wiimotes[i]->exp.type == EXP_GUITAR_HERO_3) { - /* put guitar hero values in wiimote generic event */ - mid = (*env)->GetMethodID(env, cls, - "addGuitarHeroEventToPreparedWiimoteEvent", "(SSSFFFSSSSSS)V"); - if (mid == 0) { - return; - } - struct guitar_hero_3_t* gh = (guitar_hero_3_t*)&wiimotes[i]->exp.gh3; - - (*env)->CallVoidMethod(env, gath, mid, - /* buttons */ - gh->btns,gh->btns_released,gh->btns_held, - /* whammy bar */ - gh->whammy_bar, - /* joystick */ - gh->js.ang,gh->js.mag, - gh->js.max.x,gh->js.max.y, - gh->js.min.x,gh->js.min.y, - gh->js.center.x,gh->js.center.y); - } else if (wiimotes[i]->exp.type == EXP_CLASSIC) { - /* put classic controller values in wiimote generic event */ - mid = (*env)->GetMethodID(env, cls, - "addClassicControllerEventToPreparedWiimoteEvent", "(SSSFFFFSSSSSSFFSSSSSS)V"); - if (mid == 0) { - return; - } - struct classic_ctrl_t* cl = (classic_ctrl_t*)&wiimotes[i]->exp.classic; - - (*env)->CallVoidMethod(env, gath, mid, - /* buttons */ - cl->btns,cl->btns_released,cl->btns_held, - /* shoulder buttons */ - cl->r_shoulder,cl->l_shoulder, - /* joystick left*/ - cl->ljs.ang,cl->ljs.mag, - cl->ljs.max.x,cl->ljs.max.y, - cl->ljs.min.x,cl->ljs.min.y, - cl->ljs.center.x,cl->ljs.center.y, - /* joystick right */ - cl->rjs.ang,cl->rjs.mag, - cl->rjs.max.x,cl->rjs.max.y, - cl->rjs.min.x,cl->rjs.min.y, - cl->rjs.center.x,cl->rjs.center.y); - } else if (wiimotes[i]->exp.type == EXP_BALANCE_BOARD) { - /* put balance board values in wiimote generic event */ - mid = (*env)->GetMethodID(env, cls, - "addBalanceBoardEventToPreparedWiimoteEvent", "(FFFF)V"); - if (mid == 0) { - return; - } - struct balance_board_t* bb = (balance_board_t*)&wiimotes[i]->exp.bb; - (*env)->CallVoidMethod(env, gath, mid, - /* weight */ - bb->tr, - bb->br, - bb->bl, - bb->tl); - } - } - - /* add generic event to java object used to gather events in c environment */ - mid = (*env)->GetMethodID(env, cls, "addWiimoteEvent", "()V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid); - break; - - case WIIUSE_DISCONNECT: - /* the wiimote disconnected */ - mid = (*env)->GetMethodID(env, cls, "addDisconnectionEvent", "(I)V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); - break; - - case WIIUSE_UNEXPECTED_DISCONNECT: - /* the wimote disconnected */ - mid = (*env)->GetMethodID(env, cls, "addDisconnectionEvent", "(I)V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); - break; - - case WIIUSE_NUNCHUK_INSERTED: - /* the nunchuk was just connected */ - mid = (*env)->GetMethodID(env, cls, "addNunchukInsertedEvent", "(I)V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); - break; - - case WIIUSE_NUNCHUK_REMOVED: - /* the nunchuk disconnected */ - mid = (*env)->GetMethodID(env, cls, "addNunchukRemovedEvent", "(I)V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); - break; - - case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED: - /* the guitar hero was just connected */ - mid = (*env)->GetMethodID(env, cls, "addGuitarHeroInsertedEvent", "(I)V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); - break; - - case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED: - /* the guitar hero disconnected */ - mid = (*env)->GetMethodID(env, cls, "addGuitarHeroRemovedEvent", "(I)V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); - break; - - case WIIUSE_CLASSIC_CTRL_INSERTED: - /* the classic controller was just connected */ - mid = (*env)->GetMethodID(env, cls, "addClassicControllerInsertedEvent", "(I)V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); - break; - - case WIIUSE_CLASSIC_CTRL_REMOVED: - /* the classic controller disconnected */ - mid = (*env)->GetMethodID(env, cls, "addClassicControllerRemovedEvent", "(I)V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); - break; - - case WIIUSE_BALANCE_BOARD_CTRL_INSERTED: - /* the balance board was just connected */ - mid = (*env)->GetMethodID(env, cls, "addBalanceBoardInsertedEvent", "(I)V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); - break; - - case WIIUSE_BALANCE_BOARD_CTRL_REMOVED: - /* the balance board disconnected */ - mid = (*env)->GetMethodID(env, cls, "addBalanceBoardRemovedEvent", "(I)V"); - if (mid == 0) { - return; - } - (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); - break; - - case WIIUSE_STATUS: - /* a status event occured */ - mid = (*env)->GetMethodID(env, cls, "addStatusEvent", "(IZFSZIZZZZ)V"); - if (mid == 0) { - return; - } - /* LEDS */ - if (WIIUSE_IS_LED_SET(wiimotes[i], 1)) leds += 1; - if (WIIUSE_IS_LED_SET(wiimotes[i], 2)) leds += 2; - if (WIIUSE_IS_LED_SET(wiimotes[i], 3)) leds += 4; - if (WIIUSE_IS_LED_SET(wiimotes[i], 4)) leds += 8; - - (*env)->CallVoidMethod(env, gath, mid, - wiimotes[i]->unid, WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_CONNECTED), - wiimotes[i]->battery_level, leds, WIIUSE_USING_SPEAKER(wiimotes[i]), - wiimotes[i]->exp.type,WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_RUMBLE), - WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_CONTINUOUS), - WIIUSE_USING_IR(wiimotes[i]),WIIUSE_USING_ACC(wiimotes[i])); - break; - - default: - break; - } - } - } -} - -/* Calibration * -JNIEXPORT jshortArray JNICALL Java_wiiusej_WiiUseApi_getCalibration -(JNIEnv *env, jobject obj, jint id) { - struct wiimote_t wm = *wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id); - jshort calibration[6] = { - wm.accel_calib.cal_zero.x, - wm.accel_calib.cal_zero.y, - wm.accel_calib.cal_zero.z, - wm.accel_calib.cal_g.x, - wm.accel_calib.cal_g.y, - wm.accel_calib.cal_g.z}; - jshortArray jShorts = (*env)->NewShortArray(env, 6); - (*env)->SetShortArrayRegion(env, jShorts, 0, 6, calibration); - return jShorts; -}*/ - -/** - * Speaker - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_enableSpeaker(JNIEnv *env, jobject obj, jint id) { - wiiuse_speaker_enable(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); -} - -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_disableSpeaker(JNIEnv *env, jobject obj, jint id){ - wiiuse_speaker_disable(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); -} - -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_muteSpeaker(JNIEnv *env, jobject obj, jint id) { - wiiuse_speaker_mute(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); -} - -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_unmuteSpeaker(JNIEnv *env, jobject obj, jint id) { - wiiuse_speaker_unmute(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); -} - -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSpeaker(JNIEnv *env, jobject obj, jint id) { - wiiuse_speaker_activate(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); -} - -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSpeaker(JNIEnv *env, jobject obj, jint id) { - wiiuse_speaker_deactivate(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); -} - -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerFormat(JNIEnv *env, jobject obj, jint id, jbyte format) { - wiiuse_speaker_format(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), format); -} - -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerRate(JNIEnv *env, jobject obj, jint id, jbyte rate, jbyte freq) { - wiiuse_speaker_rate(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), rate, freq); -} - -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerVolume(JNIEnv *env, jobject obj, jint id, jdouble vol) { - wiiuse_speaker_volume(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), vol); -} - -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerConfig(JNIEnv *env, jobject obj, jint id) { - wiiuse_speaker_config(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); -} - -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_streamSpeakerData(JNIEnv *env, jobject obj, jint id, jbyteArray jbArray) { - jbyte *jbData = (*env)->GetByteArrayElements(env, jbArray, JNI_FALSE); - /* Todo: Check for data loss by using signed vs unsigned bytes */ - int len = (int) (*env)->GetArrayLength(env, jbArray); - /*byte data[len]; - int i = 0; - for (i = 0; i < len; ++i) { - data[i] = (byte) jbData[i]; - }*/ - wiiuse_speaker_data(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), (byte*) jbData, len); - (*env)->ReleaseByteArrayElements(env, jbArray, jbData, JNI_FALSE); -} diff --git a/cpp/wiiusej/src/wiiusej_WiiUseApi.h b/cpp/wiiusej/src/wiiusej_WiiUseApi.h deleted file mode 100644 index aeed446..0000000 --- a/cpp/wiiusej/src/wiiusej_WiiUseApi.h +++ /dev/null @@ -1,364 +0,0 @@ -#include - -/* Header for class wiiusej_WiiUseApi */ -#ifndef _Included_wiiusej_WiiUseApi -#define _Included_wiiusej_WiiUseApi -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: wiiusej_WiiUseApi - * Method: connect - * Signature: (I)I - */ -JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_connect - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: find - * Signature: (II)I - */ -JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_find - (JNIEnv *, jobject, jint, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: init - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_init - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: closeConnection - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_closeConnection - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: getUnId - * Signature: (I)I - */ -JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_getUnId - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: cleanUp - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_cleanUp - (JNIEnv *, jobject); - -/* - * Class: wiiusej_WiiUseApi - * Method: activateRumble - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateRumble - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: deactivateRumble - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateRumble - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: activateIRTracking - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateIRTracking - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: deactivateIRTracking - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateIRTracking - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: activateMotionSensing - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateMotionSensing - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: deactivateMotionSensing - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateMotionSensing - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: setLeds - * Signature: (IZZZZ)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setLeds - (JNIEnv *, jobject, jint, jboolean, jboolean, jboolean, jboolean); - -/* - * Class: wiiusej_WiiUseApi - * Method: setOrientThreshold - * Signature: (IF)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setOrientThreshold - (JNIEnv *, jobject, jint, jfloat); - -/* - * Class: wiiusej_WiiUseApi - * Method: setAccelThreshold - * Signature: (II)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAccelThreshold - (JNIEnv *, jobject, jint, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: setAlphaSmoothing - * Signature: (IF)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAlphaSmoothing - (JNIEnv *, jobject, jint, jfloat); - -/* - * Class: wiiusej_WiiUseApi - * Method: reSync - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_reSync - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: activateSmoothing - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSmoothing - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: deactivateSmoothing - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSmoothing - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: activateContinuous - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateContinuous - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: deactivateContinuous - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateContinuous - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: setScreenRatio43 - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio43 - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: setScreenRatio169 - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio169 - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: setSensorBarAboveScreen - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarAboveScreen - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: setSensorBarBelowScreen - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarBelowScreen - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: setVirtualScreenResolution - * Signature: (III)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setVirtualScreenResolution - (JNIEnv *, jobject, jint, jint, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: getStatus - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_getStatus - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: setTimeout - * Signature: (ISS)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setTimeout - (JNIEnv *, jobject, jint, jshort, jshort); - -/* - * Class: wiiusej_WiiUseApi - * Method: setIrSensitivity - * Signature: (II)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setIrSensitivity - (JNIEnv *, jobject, jint, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: setNunchukOrientationThreshold - * Signature: (IF)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukOrientationThreshold - (JNIEnv *, jobject, jint, jfloat); - -/* - * Class: wiiusej_WiiUseApi - * Method: setNunchukAccelerationThreshold - * Signature: (II)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukAccelerationThreshold - (JNIEnv *, jobject, jint, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: windowsSetBluetoothStack - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_windowsSetBluetoothStack - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: specialPoll - * Signature: (Lwiiusej/wiiusejevents/utils/EventsGatherer;)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll - (JNIEnv *, jobject, jobject); - -/* - * Class: wiiusej_WiiUseApi - * Method: enableSpeaker - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_enableSpeaker - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: disableSpeaker - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_disableSpeaker - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: muteSpeaker - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_muteSpeaker - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: unmuteSpeaker - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_unmuteSpeaker - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: activateSpeaker - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSpeaker - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: deactivateSpeaker - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSpeaker - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: setSpeakerFormat - * Signature: (IB)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerFormat - (JNIEnv *, jobject, jint, jbyte); - -/* - * Class: wiiusej_WiiUseApi - * Method: setSpeakerRate - * Signature: (II)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerRate - (JNIEnv *, jobject, jint, jbyte, jbyte); - -/* - * Class: wiiusej_WiiUseApi - * Method: setSpeakerVolume - * Signature: (ID)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerVolume - (JNIEnv *, jobject, jint, jdouble); - -/* - * Class: wiiusej_WiiUseApi - * Method: setSpeakerConfig - * Signature: (IBID)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerConfig - (JNIEnv *, jobject, jint); - -/* - * Class: wiiusej_WiiUseApi - * Method: streamSpeakerData - * Signature: (I[B)V - */ -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_streamSpeakerData - (JNIEnv *, jobject, jint, jbyteArray); - -#ifdef __cplusplus -} -#endif -#endif