G
Guest
I want to get some infomation in the smartphone registry ,so I use the
RegQueryValueEx function to access the registry value ,but a question occur
,the function alway fail in the first time call,but will get the correct
Value in the second time.I'm a VB.net programmer ,I declare the function as
the follow cpde:
<DllImport("coredll.dll")> _
Public Shared Function RegQueryValueEx(ByVal hKey As Int32, _
ByVal lpValueName As String, _
ByVal lpReserved As Int32, _
ByRef lpType As Int32, _
ByVal lpData As Text.StringBuilder, _
ByRef lpcbData As Int32 _
) As Int32 ' Note that if you
declare the lpData parameter as String, you must pass it By Value.
End Function
and use it as following:
Public Function fnRegQueryValueToStringBuilder(ByVal ni_strValueName As
String, Optional ByRef ni_i32ValueType As Int32 = 0) As Text.StringBuilder
REM å–得指定注册表键的值
Dim ti32tempa As Int32
Dim ti32ValueType As Int32, ti32Datalength As Int32
Dim tobjValueData As New Text.StringBuilder(255)
'Error occur here.Below line alway fail,even I give the tobjValueData
enought space!
ti32tempa = RegQueryValueEx(Me.InnerRegKeyHandle, ni_strValueName, 0,
ni_i32ValueType, tobjValueData, ti32Datalength)
使用第一次读得的数æ®é•¿åº¦å†è¯»ä¸€æ¬¡å¯ä»¥ç¡®ä¿å¾—到æ£ç¡®çš„结果,但䏿˜Žç™½ä¸ºä»€ä¹ˆç¬¬ä¸€æ¬¡è¯»æ— 论如何总是出错
tobjValueData.Capacity = ti32Datalength
'now ,this time the code will work perfectly .why ?
ti32tempa = RegQueryValueEx(Me.InnerRegKeyHandle, ni_strValueName, 0,
ni_i32ValueType, tobjValueData, ti32Datalength)
If ti32tempa = 0 Then
'tobjValueData.Length = ti32Datalength
Return (tobjValueData)
Else
Return Nothing
End If
End Function
Who can tell me the reason why I get this error ,thanks a lot!
RegQueryValueEx function to access the registry value ,but a question occur
,the function alway fail in the first time call,but will get the correct
Value in the second time.I'm a VB.net programmer ,I declare the function as
the follow cpde:
<DllImport("coredll.dll")> _
Public Shared Function RegQueryValueEx(ByVal hKey As Int32, _
ByVal lpValueName As String, _
ByVal lpReserved As Int32, _
ByRef lpType As Int32, _
ByVal lpData As Text.StringBuilder, _
ByRef lpcbData As Int32 _
) As Int32 ' Note that if you
declare the lpData parameter as String, you must pass it By Value.
End Function
and use it as following:
Public Function fnRegQueryValueToStringBuilder(ByVal ni_strValueName As
String, Optional ByRef ni_i32ValueType As Int32 = 0) As Text.StringBuilder
REM å–得指定注册表键的值
Dim ti32tempa As Int32
Dim ti32ValueType As Int32, ti32Datalength As Int32
Dim tobjValueData As New Text.StringBuilder(255)
'Error occur here.Below line alway fail,even I give the tobjValueData
enought space!
ti32tempa = RegQueryValueEx(Me.InnerRegKeyHandle, ni_strValueName, 0,
ni_i32ValueType, tobjValueData, ti32Datalength)
使用第一次读得的数æ®é•¿åº¦å†è¯»ä¸€æ¬¡å¯ä»¥ç¡®ä¿å¾—到æ£ç¡®çš„结果,但䏿˜Žç™½ä¸ºä»€ä¹ˆç¬¬ä¸€æ¬¡è¯»æ— 论如何总是出错
tobjValueData.Capacity = ti32Datalength
'now ,this time the code will work perfectly .why ?
ti32tempa = RegQueryValueEx(Me.InnerRegKeyHandle, ni_strValueName, 0,
ni_i32ValueType, tobjValueData, ti32Datalength)
If ti32tempa = 0 Then
'tobjValueData.Length = ti32Datalength
Return (tobjValueData)
Else
Return Nothing
End If
End Function
Who can tell me the reason why I get this error ,thanks a lot!