R
rocio
I wrote a key to the registry of my PPC using the OpenNETCF.Win32 utility (this is a VB.NET program that runs in the PPC itself). This key is but the Device ID that I also get using RAPI in VB.NET. I store this id in \HKEY_LOCAL_MACHINE\HARDWARE\UUID\DeviceID=123-456-789
where the value for DeviceID is the actual id of my PPC.
I verified that this entry is indeed in the registry by reading the subkey "HARDWARE\UUID" with OpenNETCF.Win32.Registry.LocalMachine.OpenSubKey("HARDWARE\UUID").GetValue("DeviceID") .
Now from a desktop application (aka vb6 now), I need to read this value to identify the PPC I'm conecting to. I'm using the RAPI functions: CeRegOpenKey and CeRegQueryValueEx.
CeRegOpenKey opens the registry at HKEY_LOCAL_MACHINE and returns a handle that is used by CeRegQueryValueEx. CeRegQueryValueEx runs successfully, I can confirm that it reads a string value of size 72 bytes ....... but the actual value it reads is empty:
Public 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
Public Function GetCERegistryValue(ByRef hkey As Long, ByRef value As String) As Long
Dim subkey As String
Dim lpData(1000) As Byte
Dim cbData As Long
Dim lptype As Long
subkey = "DeviceID"
GetCERegistryValue = CeRegQueryValueEx(hkey, StrPtr(subkey), 0, lptype, lpData(0), cbData)
If GetCERegistryValue <> ERROR_SUCCESS Then
value = UnicodeToAnsiByte(lpData)
Exit Function
Else
value = UnicodeToAnsiByte(lpData)
End If
End Function
Private Function UnicodeToAnsiByte(bString() As Byte) As String
Dim index As Integer
Dim stemp As String
stemp = ""
While Not (bString(index) = 0 And bString(index + 1) = 0)
stemp = stemp & Chr(bString(index))
index = index + 2
Wend
UnicodeToAnsiByte = stemp
End Function
I put a breakdown at the red line to see what is stored in the variables lptype, lpData, and cbData.
lpData should store the value of DeviceID, but it does not. It returns an empty array. However, lptype is set to 1, which means it read a "null terminated string", and cbdata is set to 72, or 72 bytes for whatever it read (this is the actual value of the ID = E60A00E6-105F-E135-0038-0050BFE45CE5)
what am I doing wrong here? any ideas?
where the value for DeviceID is the actual id of my PPC.
I verified that this entry is indeed in the registry by reading the subkey "HARDWARE\UUID" with OpenNETCF.Win32.Registry.LocalMachine.OpenSubKey("HARDWARE\UUID").GetValue("DeviceID") .
Now from a desktop application (aka vb6 now), I need to read this value to identify the PPC I'm conecting to. I'm using the RAPI functions: CeRegOpenKey and CeRegQueryValueEx.
CeRegOpenKey opens the registry at HKEY_LOCAL_MACHINE and returns a handle that is used by CeRegQueryValueEx. CeRegQueryValueEx runs successfully, I can confirm that it reads a string value of size 72 bytes ....... but the actual value it reads is empty:
Public 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
Public Function GetCERegistryValue(ByRef hkey As Long, ByRef value As String) As Long
Dim subkey As String
Dim lpData(1000) As Byte
Dim cbData As Long
Dim lptype As Long
subkey = "DeviceID"
GetCERegistryValue = CeRegQueryValueEx(hkey, StrPtr(subkey), 0, lptype, lpData(0), cbData)
If GetCERegistryValue <> ERROR_SUCCESS Then
value = UnicodeToAnsiByte(lpData)
Exit Function
Else
value = UnicodeToAnsiByte(lpData)
End If
End Function
Private Function UnicodeToAnsiByte(bString() As Byte) As String
Dim index As Integer
Dim stemp As String
stemp = ""
While Not (bString(index) = 0 And bString(index + 1) = 0)
stemp = stemp & Chr(bString(index))
index = index + 2
Wend
UnicodeToAnsiByte = stemp
End Function
I put a breakdown at the red line to see what is stored in the variables lptype, lpData, and cbData.
lpData should store the value of DeviceID, but it does not. It returns an empty array. However, lptype is set to 1, which means it read a "null terminated string", and cbdata is set to 72, or 72 bytes for whatever it read (this is the actual value of the ID = E60A00E6-105F-E135-0038-0050BFE45CE5)
what am I doing wrong here? any ideas?