|
-
Jul 10th, 2006, 11:06 AM
#1
[RESOLVED] Registy Setvalue Works in 2k/xp Not in 9X
Hello !
VB Code:
Public Sub SearchString()
regkey = "Software\My Software"
strname = Form1.text1.Text
lngresult = RegOpenKeyEx(HKEY_CURRENT_USER, regkey, REG_SZ, keyallaccess, path)
If lngresult = 0 Then
lngresult=RegSetValueEx (path, "Search Now", 0, REG_SZ, ByVal strname, Len(strname)
End If
lngresult = RegCloseKey(path)
Exit Sub
Now assume Text1 has no text. A blank text box.
when we execute SearchString() the Strname will be > strname=""
Problem is :
RegSetValueEx returns 87 in Windows98Se. So the function fail to set the value data.
RegSetValueEx returns 0 successfully on XP and 2K.
Friends! What is the problem?
-
Jul 10th, 2006, 04:22 PM
#2
Re: Registy Setvalue Works in 2k/xp Not in 9X
The problem is that if strname is an empty string then Len(strname) would be 0. Which means that you want to store 0 bytes of a REG_SZ type, but that type is null terminated and the last argument should be the size of the string including the terminating null character. So try to add 1 to Len(strname).
-
Jul 10th, 2006, 04:41 PM
#3
Re: Registy Setvalue Works in 2k/xp Not in 9X
 Originally Posted by Fazi
strname = Form1.text1.Text
VB Code:
strname = Form1.text1.Text & vbNullChar 'Note how a null character must be appended to the string.
-
Jul 10th, 2006, 04:59 PM
#4
Re: Registy Setvalue Works in 2k/xp Not in 9X
That is not really necassary since VB will convert the string you pass to a null terminating string. However, as I already mentioned RegSetValueEx requires to get the length of the string including the terminating null character so you can simply add 1 to the last argument.
-
Jul 10th, 2006, 11:25 PM
#5
Re: Registy Setvalue Works in 2k/xp Not in 9X
Hai jacim and schoolbus driver !!
Jacim i tried your solution.
VB Code:
lngresult=RegSetValueEx (path, "Search Now", 0, REG_SZ, ByVal strname, Len(strname) + 1)
Result : 98SE Shows NO MERCY. .87 Returned
if i debug.print strptr(strname) in 98se the debug windw out puts 0. so strname uses no memory. if iam corrct.
'thanks bush mobile for strptr, it is somthing new for me..
So i tried this way
VB Code:
strname = Form1.text1.Text
if strname="" then strname=chr$(0)
....
....
lngresult=RegSetValueEx (path, "Search Now", 0, REG_SZ, ByVal strname, Len(strname) + 1)
....
...
98SE Is happy and returned 0 :-)
the debug.print shown strptr(strname) somthing assume like 1909809 (not remember the numbers exactly. i am in xp now)
so i assume strname uses memory.
So jacim and others... Shall i go ahead using this way ?
-
Jul 11th, 2006, 03:30 AM
#6
Re: Registy Setvalue Works in 2k/xp Not in 9X
 Originally Posted by Fazi
So jacim and others... Shall i go ahead using this way ?
Yes, I think so. There is another possibility that will remove the "Search Now" key and its value if you do not need it:-
VB Code:
regkey = "Software\My Software"
strname = Form1.text1.Text
lngresult = RegOpenKeyEx(HKEY_CURRENT_USER, regkey, REG_SZ, KEYALLACCESS, path)
If Trim(strname) = "" Then
lngresult = RegDeleteValue(path, "Search Now")
Else
lngresult = RegSetValueEx(path, "Search Now", 0, REG_SZ, ByVal strname, Len(strname) + 1)
End If
lngresult = RegCloseKey(path)
-
Jul 11th, 2006, 09:07 AM
#7
Re: Registy Setvalue Works in 2k/xp Not in 9X
Hai jacim and schoolbusdriver
Thank you for the contributions !!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|