View Poll Results: How long have you been coding in VB?

Voters
3. You may not vote on this poll
  • Less then 1 Year!

    1 33.33%
  • 1 - 2 Years.

    0 0%
  • 2 - 3 Years.

    0 0%
  • 3 - 4 Years.

    0 0%
  • Over 5 Years!

    2 66.67%
Results 1 to 11 of 11

Thread: GetPrivateProfileStringkeys

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Moriarty, New Mexico (USA!)
    Posts
    9

    Exclamation GetPrivateProfileStringkeys

    I'm having trouble with the GetPrivateProfileStringKeys API Call.
    Here is the declaretion:

    Declare Function GetPrivateProfileStringKeys& Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName$, ByVal lpszKey&, ByVal lpszDefault$, ByVal lpszReturnBuffer$, ByVal cchReturnBuffer&, ByVal lpszFile$)

    If you have information or code how to use this function i would appreciate it, or just a full module with all the INI API Calls with comments.

    What I want to do is list all the Keys in an INI under the 'Application' Templates.

    'Example:
    [Templates]
    Name1=blah
    Name2=blah
    Name3=blag

    and add each of the 'Keys' to a listbox.

    Thanks for your time!
    ^Jasper^
    http://insecureinc.cjb.net
    'Long Live The United States!'

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I search MSDN, and several VB sites, including the API sites that I know of, and found 0 results on GetPrivateProfileStringKeys.

    Where did you find this?

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Moriarty, New Mexico (USA!)
    Posts
    9
    It was in a module from site, I forgot the site tho. That would explain why it dosn't work ;-). Do you have any ideas on how to receive all the key names under a '[Templates]'?
    ^Jasper^
    http://insecureinc.cjb.net
    'Long Live The United States!'

  4. #4
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    VB Code:
    1. Public Function RegEnumKeys(ByVal eRoot As WIN32_REG_ROOT_KEYS, ByVal sSubkey As String, ByRef EnumKeys As Variant) As Long
    2.  
    3.     On Error GoTo ERR_EnumRegKeys
    4.    
    5.     Dim lRet As Long
    6.     Dim lCtr As Long
    7.     Dim hKey As Long
    8.     Dim lKeyCount As Long
    9.     Dim lKeyLen As Long
    10.     Dim sKeyName As String
    11.     Dim uFiletime As FILETIME
    12.     Dim Keys() As String
    13.    
    14.     '*********************************************
    15.     '* Open the specified key in query mode . . .
    16.     '*********************************************
    17.     hKey = OpenKey(HKEY_LOCAL_MACHINE, sSubkey, , KEY_QUERY_VALUE)
    18.     If hKey = 0 Then
    19.         Err.Raise REGISTRY_ERROR_CODE.CannotOpenKey
    20.     End If
    21.  
    22.     '**********************************************************
    23.     '* Get the amount of keys, and maximum length of keys . . .
    24.     '**********************************************************
    25.     lRet = RegQueryInfoKeyA(hKey, vbNullString, 0&, 0&, lKeyCount, lKeyLen, 0&, 0&, 0&, 0&, 0&, uFiletime)
    26.     If lRet <> ERROR_SUCCESS Then
    27.         Err.Raise REGISTRY_ERROR_CODE.CannotDetermineKeyInfo
    28.     End If
    29.     Call RegCloseKey(hKey)
    30.    
    31.     '*************************************
    32.     '* Open key for enumeration mode . . .
    33.     '*************************************
    34.     hKey = OpenKey(HKEY_LOCAL_MACHINE, sSubkey, , KEY_ENUMERATE_SUB_KEYS)
    35.     If hKey = 0 Then
    36.         Err.Raise REGISTRY_ERROR_CODE.CannotOpenKey
    37.     End If
    38.    
    39.     ReDim Keys(lKeyCount)
    40.    
    41.     '************************************************
    42.     '* Cycle through all keys, adding to array . . .
    43.     '************************************************
    44.     For lCtr = 0 To lKeyCount - 1
    45.        
    46.         sKeyName = String(lKeyLen + 1, " ")
    47.        
    48.         lRet = RegEnumKeyExA(hKey, lCtr, sKeyName, Len(sKeyName), 0&, vbNullString, 0&, uFiletime)
    49.         If lRet <> ERROR_SUCCESS Then
    50.             Err.Raise REGISTRY_ERROR_CODE.CannotEnumerateKey
    51.         End If
    52.        
    53.         Keys(lCtr) = Trim(sKeyName)
    54.        
    55.     Next
    56.    
    57.     EnumKeys = Keys
    58.     RegEnumKeys = ERROR_SUCCESS
    59.     Erase Keys
    60.    
    61.     Exit Function
    62.  
    63. ERR_EnumRegKeys:
    64.  
    65.     Call RegCloseKey(hKey)
    66.     EnumKeys = Null
    67.     RegEnumKeys = Err.Number
    68.     Erase Keys
    69.    
    70. End Function

    Is this what you are looking for?

    You will need to fill in the standard constants, and error codes etc

  5. #5
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    oops

    I assume you mean ini files. I thought you meant the registry

    Apologies

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Moriarty, New Mexico (USA!)
    Posts
    9
    I appreciate it any way ;-)
    ^Jasper^
    http://insecureinc.cjb.net
    'Long Live The United States!'

  7. #7
    New Member
    Join Date
    Nov 2001
    Posts
    6

    Re: GetPrivateProfileStringkeys

    Originally posted by jasper_punx0r
    I'm having trouble with the GetPrivateProfileStringKeys API Call.
    Here is the declaretion:

    Declare Function GetPrivateProfileStringKeys& Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName$, ByVal lpszKey&, ByVal lpszDefault$, ByVal lpszReturnBuffer$, ByVal cchReturnBuffer&, ByVal lpszFile$)

    If you have information or code how to use this function i would appreciate it, or just a full module with all the INI API Calls with comments.

    What I want to do is list all the Keys in an INI under the 'Application' Templates.

    'Example:
    [Templates]
    Name1=blah
    Name2=blah
    Name3=blag

    and add each of the 'Keys' to a listbox.

    Thanks for your time!

    i did not find an api by the name getprivateprofilestringkeys but i certainly can help you out with getprivateprofilestring api

    here is a sample code

    Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long


    Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    Private Sub Form_Load()

    Dim Ret As String, NC As Long
    'Write the setting to the file (c:\test.ini) under
    ' Project1 -> Keyname
    WritePrivateProfileString App.Title, "KeyName", "This is the value", "c:\test.ini"
    'Create a buffer
    Ret = String(255, 0)
    'Retrieve the string
    NC = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\test.ini")
    'NC is the number of characters copied to the buffer
    If NC <> 0 Then Ret = Left$(Ret, NC)
    'Show our string
    MsgBox Ret
    'Delete the file
    Kill "c:\test.ini"
    End Sub

    i hope this is helpful

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Moriarty, New Mexico (USA!)
    Posts
    9
    thanks, but us there any way to 'loop' through all the keynames? and return them?
    ^Jasper^
    http://insecureinc.cjb.net
    'Long Live The United States!'

  9. #9
    New Member
    Join Date
    Nov 2001
    Posts
    6
    hi there
    try this code - i hope this solves your problem

    Private Declare Function GetPrivateProfileSectionNames Lib "kernel32.dll" Alias "GetPrivateProfileSectionNamesA" (ByVal lpszReturnBuffer As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    Private Sub Form_Load()
    Dim szBuf As String, Length As Integer
    Dim SectionArr() As String, m As Integer
    szBuf = String$(255, 0)
    Length = GetPrivateProfileSectionNames(szBuf, 255, vbNullChar)
    szBuf = Left$(szBuf, Length)
    SectionArr = Split(szBuf, vbNullChar)
    For m = 0 To UBound(SectionArr)
    List1.AddItem SectionArr(m)
    Next m
    End Sub

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Moriarty, New Mexico (USA!)
    Posts
    9
    I can use that too =). I probalyl would of asked how to do that later on. This returns all the Section names, and is there one to return the KeyNames? (IE: GetPrivateProfileKeyNames()?)
    ^Jasper^
    http://insecureinc.cjb.net
    'Long Live The United States!'

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Here is all I could find for Keys. I hope it helps.
    VB Code:
    1. 'The GetPrivateProfileInt function retrieves an integer associated with a key in the specified
    2. 'section of an initialization file. Note  This function is provided only for compatibility with
    3. '16-bit Windows-based applications. Win32-based applications should store initialization
    4. 'information in the registry.
    5.  
    6. 'This sample was submitted by Robin ([email protected])
    7. 'Visit his site at [url]http://members.fortunecity.com/rbnwares1[/url]
    8. Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    9. Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
    10. Private Sub Form_Load()
    11. 'Sample for reading a numbers directly on the INI file
    12.  
    13.     'Write a number 55 on the sample.ini to be read
    14.     WritePrivateProfileString "Sample", "Sample", "55", App.Path & "\sample.ini"
    15.  
    16.     'Then, read the stored number
    17.     'No need to convert the value returned
    18.     MsgBox GetPrivateProfileInt("Sample", "Sample", 0, App.Path & "\sample.ini")
    19. 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