Results 1 to 2 of 2

Thread: RegOpenKey(Ex)

  1. #1
    Guest

    Question

    Can anyone help me?
    I am trying to pull out system date format from the registry using API function calls, but can't even open key. I keep getting 161 error code (MessageId: ERROR_BAD_PATHNAME, MessageText:The specified path is invalid.)

    I am using the following code:

    Public fMainForm As frmMain
    Public sDataPath As String
    Public sDateFormat As String

    Public Const HKEY_CURRENT_USER = &H80000001
    Const KEY_QUERY_VALUE = &H1
    Const REG_SZ = 1

    Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
    "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
    ByVal ulOptions As Long, ByVal samDesired As Long, _
    phkResult As Long) As Long
    Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
    "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
    ByVal lpReserved As Long, lpType As Long, _
    lpData As Any, lpcbData As Long) As Long
    Public Declare Function RegCloseKey Lib "advapi32.dll" _
    (ByVal hKey As Long) As Long

    'let's retrieve the system date
    Public Sub GetKey() 'As String

    Dim sRegistryKey As String
    Dim nHKResult As Long
    Dim nErrKey As Long
    Dim sRtrnData As String
    Dim nRtrnSize As Long

    sRegistryKey = "\Control Panel\International"
    'open the key
    nErrKey = RegOpenKeyEx(HKEY_CURRENT_USER, sRegistryKey, 0&, _
    KEY_QUERY_VALUE, nHKResult)
    'retrieve value
    nErrKey = RegQueryValueEx(HKEY_CURRENT_USER, "sShortDate", _
    0&, REG_SZ, ByVal sRtrnData, nRtrnSize)

    'close the key
    nOpenRegKey = RegCloseKey(nHKResult)

    End Sub

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    You can use GetLocaleInfo to get date formats:
    Code:
    Option Explicit
    Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
    Private Const LOCALE_USER_DEFAULT = &H400
    Private Const LOCALE_SSHORTDATE = &H1F ' short date format string
    Private Const LOCALE_SLONGDATE = &H20 ' long date format string
    
    
    Private Sub Form_Load()
        Dim strLocale As String
        Dim lngRet As Long
        Dim strMsg As String
        
        'Get short date format
        strLocale = Space(255)
        lngRet = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strLocale, Len(strLocale))
        strLocale = Left(strLocale, lngRet - 1)
        
        strMsg = "Short Date Format: " & strLocale
        
        'Get long date format
        strLocale = Space(255)
        lngRet = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, strLocale, Len(strLocale))
        strLocale = Left(strLocale, lngRet - 1)
        
        strMsg = strMsg & vbCrLf & "Long Date Format: " & strLocale
        
        MsgBox strMsg
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width