CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    INI files question

    I want to know which is the purpose of an INI file. I'm making an app with VB6.0 - SQL server7.0. I know that some apps have an INI file which contains password, and other parametres..

    I would like to know more about INI files and his utilities. I want to know which are the typical the things you put in an INI file and how to use thems.

    I suppose that using them I can get some advantage in my app. isn't it???

    Any advice will be greatly apreciatted.

    Nauj





  2. #2
    Join Date
    Jan 2000
    Posts
    19

    Re: INI files question

    Hi,

    INI files are great but some say not quite as great as the regestry. INI files are used to store information in such as the users name or background colour of the program. Its not a good idea to use INI files to store User Names and Passwords as anybody can access an INI file and see what the password is. To use INI files you need to know the two API calls:

    GetPrivateProfileString
    WritePrivateProfileString

    As you may have probably guessed GetPrivateProfileString is used to read INI files and the latter is used to write to INI files. Here is an example that I have taken from some place:


    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 it helps!!!



  3. #3
    Join Date
    Jan 2000
    Posts
    45

    Re: INI files question

    you no, you can write to ".dat" files also, and you cant read them unless you open it with notepad


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

Featured