Visual Basic > API and Miscellaneous
How to retrieve a Pocket PC device's name
How to retrieve a Pocket PC device's name 'All DLLs are installed with ActiveSync Public Const HKEY_CLASSES_ROOT = &H80000000 Public Const HKEY_CURRENT_USER = &H80000001 Public Const HKEY_LOCAL_MACHINE = &H80000002 Public Const ERROR_SUCCESS = 0 Public Const REG_DWORD = 4 '32-bit number. Public Const REG_SZ = 1 Type RAPIINIT cbsize As Long heRapiInit As Long hrRapiInit As Long End Type Declare Function CeRapiUninit Lib "rapi.dll" () As Long Declare Function CeRapiInitEx Lib "rapi.dll" ( _ pRapiInit As RAPIINIT) As Long Declare Function CeRegOpenKeyEx Lib "rapi.dll" ( _ ByVal hkey As Long, _ ByVal lpSubKey As Long, _ ByVal ulOptions As Long, _ ByVal samDesired As Long, _ phkResult As Long) As Long Declare Function CeRegQueryValueEx Lib "rapi.dll" ( _ ByVal hkey As Long, _ ByVal lpValueName As Long, _ ByVal lpReserved As Long, _ lpType As Long, _ ByVal lpdata As Long, _ lpcbData As Long) As Long Declare Function CeRegQueryValueExLong Lib "rapi.dll" _ Alias "CeRegQueryValueEx" ( _ ByVal hkey As Long, _ ByVal lpValueName As Long, _ ByVal lpReserved As Long, _ lpType As Long, _ lpdata As Long, _ lpcbData As Long) As Long Declare Function CeRegQueryValueExString Lib "rapi.dll" _ Alias "CeRegQueryValueEx" ( _ ByVal hkey As Long, _ ByVal lpValueName As Long, _ ByVal lpReserved As Long, _ lpType As Long, _ ByVal lpdata As Long, _ lpcbData As Long) As Long Declare Function CeRegCloseKey Lib "rapi.dll" ( _ ByVal hkey As Long) As Long Function GetDeviceName() As String ' Read the registry on the CE device Dim lret As Long Dim phkResult As Long Dim lpType As Long Dim lpdata As String Dim lpvalue As Long Dim lpcbData As Long Dim data As String Dim key As String Dim lpdwdisposition As Long Dim value As String GetDeviceName = "" key = "Ident" lret = ConnectRAPI() lret = CeRegOpenKeyEx(HKEY_LOCAL_MACHINE, StrPtr(key), _ 0, 0, phkResult) If lret <> ERROR_SUCCESS Then Else value = "Name" lret = CeRegQueryValueEx(phkResult, StrPtr(value), _ 0, lpType, 0, lpcbData) Select Case lpType ' -- For strings Case REG_SZ: ' Allocate string space lpdata = Space(lpcbData) ' Query the string value lret = CeRegQueryValueExString(phkResult, StrPtr(value), _ CLng(0), lpType, StrPtr(lpdata), lpcbData) If lret = ERROR_SUCCESS Then GetDeviceName = Trim(Left(lpdata, lpcbData - 1)) Else GetDeviceName = "" End If If InStr(1, GetDeviceName, Chr(0)) > 0 Then GetDeviceName = Left(GetDeviceName, InStr(1, GetDeviceName, Chr(0)) - 1) End If '-- For DWORDS Case REG_DWORD: lret = CeRegQueryValueExLong(phkResult, StrPtr(value), _ CLng(0), lpType, lpvalue, lpcbData) If lret = ERROR_SUCCESS Then MsgBox lpvalue ' -- All other data types not supported Case Else lret = -1 End Select End If lret = DisconnectRAPI() End Function Function ConnectRapi() As Long ' Initialize RAPI Dim lcon As Long Dim lRapiInit As RAPIINIT With lRapiInit .cbsize = Len(lRapiInit) .heRapiInit = 0 .hrRapiInit = 0 End With lcon = CeRapiInitEx(lRapiInit) ConnectRapi = lcon End Function Function DisconnectRapi() As Long Dim lcon As Long lcon = CeRapiUninit DisconnectRapi = lcon End Function
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows