PDA

Click to See Complete Forum and Search --> : Registry doesn't need crap!


jovton
Nov 24th, 2000, 06:48 AM
My VB program writes garbage to the windows registry.
Shouldn't do this.

Can anyone please look at my code, and tell me what's wrong?
(Asume constants and APIs are already declared...)


Public Sub Main()
Dim KeyHandle As Long, result As Long, _
StrDir As String * MAX_PATH, _
NewStrDir as String

Result = GetSystemDirectory(StrDir, MAX_PATH)
NewStrDir = Left(StrDir, Result) & "\server.exe"
Result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0&, KEY_ALL_ACCESS, KeyHandle)
Result = RegSetValueEx(KeyHandle, "myserver", 0, REG_SZ, NewStrDir, CLng(Len(NewStrDir) + 1))
Result = RegCloseKey(KeyHandle)
Load frmMainServer
' Bla Bla Bla Bla
End Sub


Is it something to do with Unicode and ANSI?

I will be using my program on Windows NT and Windows 95, 98 also.
These include from 95 - Millennium, NT 4.0 - 2000.

thnx 4 helping.

(sorry, for the format. 'twas quick) 8-)

kedaman
Nov 24th, 2000, 11:34 AM
might have to do, you could try convert it from unicode:

NewStrDir =strconv(NewStrDir ,vbfromunicode)

jovton
Nov 24th, 2000, 01:48 PM
thanx kedaman.

but i found out my real problem.

where i said

Result = RegSetValueEx(KeyHandle, "myserver", 0, REG_SZ, NewStrDir, CLng(Len(NewStrDir) + 1))

It should have been

Result = RegSetValueEx(KeyHandle, "myserver", 0, REG_SZ, ByVal NewStrDir, CLng(Len(NewStrDir) + 1))

just needed a ByVal.

hope you other guys not run into same problem.

thanx again, kedman.