We help IT Professionals succeed at work.

syntax for setting value in registry VB6

jack niekerk
jack niekerk asked
on
how to set a value to registry in Vb6
got a error on setting a value to registry syntax

  'Change the keyboard type and show it
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Handles Button6.Click
        'Change the Registry entry for the required keyboard
        My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\ComfortSoftware\hvk", "KeyboardName", "Name of your chosen keyboard")
        'Open the keyboard
        Dim hWnd As Integer
        hWnd = FindWindow("TFirstForm", "hvkFirstForm")
        Call PostMessage(hWnd, WM_CSKEYBOARD, 1, 0)
    End Sub
keybod-set.png
Comment
Watch Question

Ryan ChongSoftware Team Lead

Commented:
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\ComfortSoftware\hvk", "KeyboardName", "Name of your chosen keyboard")

This seems like a VB.NET syntax to me and it's not compatible in classic VB6.

To do this in VB6, try refer to Registry Win APIs:

Windows Registry / Ini File Functions
http://www.thescarms.com/vbasic/registry.aspx

Author

Commented:
ok will dive into this  keep you up to date

Author

Commented:
ok this i found


Public Enum REG_TOPLEVEL_KEYS
 HKEY_CLASSES_ROOT = &H80000000
 HKEY_CURRENT_CONFIG = &H80000005
 HKEY_CURRENT_USER = &H80000001
 HKEY_DYN_DATA = &H80000006
 HKEY_LOCAL_MACHINE = &H80000002
 HKEY_PERFORMANCE_DATA = &H80000004
 HKEY_USERS = &H80000003
End Enum


Private Declare Function RegCreateKey Lib _
   "advapi32.dll" Alias "RegCreateKeyA" _
   (ByVal Hkey As Long, ByVal lpSubKey As _
   String, phkResult As Long) As Long

Private Declare Function RegCloseKey Lib _
   "advapi32.dll" (ByVal Hkey As Long) As Long

Private Declare Function RegSetValueEx Lib _
   "advapi32.dll" Alias "RegSetValueExA" _
   (ByVal Hkey As Long, ByVal _
   lpValueName As String, ByVal _
   Reserved As Long, ByVal dwType _
   As Long, lpData As Any, ByVal _
   cbData As Long) As Long

Private Const REG_SZ = 1

Const WM_CSKEYBOARD = &H400 + 192
Const WM_CSKEYBOARDMOVE = &H400 + 193
Const WM_CSKEYBOARDRESIZE = &H400 + 197
 
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
         ByVal lParam As Integer) As Integer
 
 
 Function writeStringToRegistry(Hkey As REG_TOPLEVEL_KEYS, strPath As String, strValue As String, strdata As String) As Boolean
 End Function

 'Change the keyboard type and show it
 'Change the Registry entry for the required keyboard
 '  WriteStringToRegistry("HKEY_CURRENT_USER\Software\ComfortSoftware\hvk", "KeyboardName", "Name of your chosen keyboard") as boolean
Private Sub cmdchange_Click()
     writeStringToRegistry("HKEY_CURRENT_USER\Software\ComfortSoftware\hvk", "KIOSKPADTABLET", "KioskSpecialtABLET") As Boolean
        Dim hWnd As Integer
        hWnd = FindWindow("TFirstForm", "hvkFirstForm")
        Call PostMessage(hWnd, WM_CSKEYBOARD, 1, 0)
End Sub


got only at runtime this error see attached please
error.png
Test your restores, not your backups...
Expert of the Year 2019
Top Expert 2016
Commented:
Try changing that line from:

    writeStringToRegistry("HKEY_CURRENT_USER\Software\ComfortSoftware\hvk", "KIOSKPADTABLET", "KioskSpecialtABLET") As Boolean

to:

    writeStringToRegistry("HKEY_CURRENT_USER\Software\ComfortSoftware\hvk", "KIOSKPADTABLET", "KioskSpecialtABLET")


»bp

Author

Commented:
It does work in windows 7   but not in windows 10
reported it to developer   https://hot-virtual-keyboard.com/    n[/u]o solution for it given
so we have to forget this package