Read Registry Entry with VB 6.0 and RAPI

N

NerdRunner

I have been scouring the newsgroups and Microsoft's website and have
not come across a simple example of reading a value from the registry
on the PocketPC. I have created the following procedure...

Dim iretval As Long
Dim lngResult As Long
Dim lngKeyPointer As Long
Dim lpData(1000) As Byte
Dim lpType As Long
Dim lpcbData As Long
Dim key As String
Dim subKey As String
Dim lpValue As Long

Dim Value As String
iretval = ConnectRapi()

key = "Comm\AsyncMac"
subKey = "DisplayName"

lngResult = CeRegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, 0,
lngKeyPointer)
If lngResult <> 0 Then
iretval = DisconnectRapi()
Exit Sub
End If
lngResult = CeRegQueryValueEx(lngKeyPointer, subKey, 0, lpType,
lpData(0), lpcbData)

**lngResult is always 2 never 0**

If lngResult = 0 Then
Value = UnicodeToAnsiByte(lpData)
MsgBox Value
End If

iretval = DisconnectRapi()

I have verified that the key exists and that it has a value in the
registry.

I wish to ultimately use this to determine what version of the .NET CF
is installed on the handheld, but one thing at a time.

I would greatly appreciate anyone pointing out what I am doing wrong
and why my code does not work.

Sean M. Severson
 
P

Philip Sheard

You have to convert your strings to Unicode. The CeRegOpenKeyEx is probably
opening some gobbledigook subkey that you created yourself. Then surprise,
surprise you get a key not found.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top