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 - 2 Years.
-
2 - 3 Years.
-
3 - 4 Years.
-
Over 5 Years!
-
Dec 10th, 2001, 08:49 AM
#1
Thread Starter
New Member
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!'
-
Dec 10th, 2001, 10:55 AM
#2
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?
-
Dec 10th, 2001, 06:03 PM
#3
Thread Starter
New Member
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!'
-
Dec 11th, 2001, 12:30 PM
#4
Frenzied Member
VB Code:
Public Function RegEnumKeys(ByVal eRoot As WIN32_REG_ROOT_KEYS, ByVal sSubkey As String, ByRef EnumKeys As Variant) As Long
On Error GoTo ERR_EnumRegKeys
Dim lRet As Long
Dim lCtr As Long
Dim hKey As Long
Dim lKeyCount As Long
Dim lKeyLen As Long
Dim sKeyName As String
Dim uFiletime As FILETIME
Dim Keys() As String
'*********************************************
'* Open the specified key in query mode . . .
'*********************************************
hKey = OpenKey(HKEY_LOCAL_MACHINE, sSubkey, , KEY_QUERY_VALUE)
If hKey = 0 Then
Err.Raise REGISTRY_ERROR_CODE.CannotOpenKey
End If
'**********************************************************
'* Get the amount of keys, and maximum length of keys . . .
'**********************************************************
lRet = RegQueryInfoKeyA(hKey, vbNullString, 0&, 0&, lKeyCount, lKeyLen, 0&, 0&, 0&, 0&, 0&, uFiletime)
If lRet <> ERROR_SUCCESS Then
Err.Raise REGISTRY_ERROR_CODE.CannotDetermineKeyInfo
End If
Call RegCloseKey(hKey)
'*************************************
'* Open key for enumeration mode . . .
'*************************************
hKey = OpenKey(HKEY_LOCAL_MACHINE, sSubkey, , KEY_ENUMERATE_SUB_KEYS)
If hKey = 0 Then
Err.Raise REGISTRY_ERROR_CODE.CannotOpenKey
End If
ReDim Keys(lKeyCount)
'************************************************
'* Cycle through all keys, adding to array . . .
'************************************************
For lCtr = 0 To lKeyCount - 1
sKeyName = String(lKeyLen + 1, " ")
lRet = RegEnumKeyExA(hKey, lCtr, sKeyName, Len(sKeyName), 0&, vbNullString, 0&, uFiletime)
If lRet <> ERROR_SUCCESS Then
Err.Raise REGISTRY_ERROR_CODE.CannotEnumerateKey
End If
Keys(lCtr) = Trim(sKeyName)
Next
EnumKeys = Keys
RegEnumKeys = ERROR_SUCCESS
Erase Keys
Exit Function
ERR_EnumRegKeys:
Call RegCloseKey(hKey)
EnumKeys = Null
RegEnumKeys = Err.Number
Erase Keys
End Function
Is this what you are looking for?
You will need to fill in the standard constants, and error codes etc
-
Dec 11th, 2001, 12:33 PM
#5
Frenzied Member
oops
I assume you mean ini files. I thought you meant the registry
Apologies
-
Dec 11th, 2001, 09:10 PM
#6
Thread Starter
New Member
I appreciate it any way ;-)
^Jasper^
http://insecureinc.cjb.net
'Long Live The United States!'
-
Dec 11th, 2001, 10:12 PM
#7
New Member
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
-
Dec 11th, 2001, 10:49 PM
#8
Thread Starter
New Member
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!'
-
Dec 12th, 2001, 01:52 AM
#9
New Member
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
-
Dec 12th, 2001, 08:26 AM
#10
Thread Starter
New Member
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!'
-
Dec 17th, 2001, 02:45 PM
#11
Here is all I could find for Keys. I hope it helps.
VB Code:
'The GetPrivateProfileInt function retrieves an integer associated with a key in the specified
'section of an initialization file. Note This function is provided only for compatibility with
'16-bit Windows-based applications. Win32-based applications should store initialization
'information in the registry.
'Visit his site at [url]http://members.fortunecity.com/rbnwares1[/url]
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 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
Private Sub Form_Load()
'Sample for reading a numbers directly on the INI file
'Write a number 55 on the sample.ini to be read
WritePrivateProfileString "Sample", "Sample", "55", App.Path & "\sample.ini"
'Then, read the stored number
'No need to convert the value returned
MsgBox GetPrivateProfileInt("Sample", "Sample", 0, App.Path & "\sample.ini")
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|