Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8165527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:33:41+00:00 2026-06-06T19:33:41+00:00

I find it very easy to write to a INI file, but am having

  • 0

I find it very easy to write to a INI file, but am having some trouble in retrieving the data from an already created INI file.

I am using this function:

    Public Declare Unicode Function GetPrivateProfileString Lib "kernel32" _
    Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As String, ByVal lpDefault As String, _
    ByVal lpReturnedString As String, ByVal nSize As Int32, _
    ByVal lpFileName As String) As Int32

If I have an INI file called ‘c:\temp\test.ini’, with the following data:

[testApp]
KeyName=keyValue
KeyName2=keyValue2

How can I retrieve the values of KeyName and KeyName2?

I have tried this code, with no success:

    Dim strData As String
    GetPrivateProfileString("testApp", "KeyName", "Nothing", strData, Len(strData), "c:\temp\test.ini")
    MsgBox(strData)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:33:42+00:00Added an answer on June 6, 2026 at 7:33 pm

    Going to the Pinvoke.Net Web site and modifying their example worked, their Function declaration is different.

    Modified Example

    Imports System.Runtime.InteropServices
    Imports System.Text
    Module Module1
        Private Declare Auto Function GetPrivateProfileString Lib "kernel32" (ByVal lpAppName As String, _
                ByVal lpKeyName As String, _
                ByVal lpDefault As String, _
                ByVal lpReturnedString As StringBuilder, _
                ByVal nSize As Integer, _
                ByVal lpFileName As String) As Integer
    
        Sub Main()
    
            Dim res As Integer
            Dim sb As StringBuilder
    
            sb = New StringBuilder(500)
            res = GetPrivateProfileString("testApp", "KeyName", "", sb, sb.Capacity, "c:\temp\test.ini")
            Console.WriteLine("GetPrivateProfileStrng returned : " & res.ToString())
            Console.WriteLine("KeyName is : " & sb.ToString())
            Console.ReadLine();
    
        End Sub
    End Module
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this question is very easy, but I can't find the answer anywhere.
This is hopefully very easy to do, but I can't find any doco on
There is probably a very easy solution to my problem but I couldn't find
I find myself very frequently wanting to write reusable strings with parameter placeholders in
I've been thinking of this question very long, but really couldn't find the answer
I'm very bad with regular expressions and cannot find how to write the pattern
With jquery it's very easy to insert some element inside another element using the
I know this should be easy to find via google, but I can't seem
This sounds very easy, however I couldn't find it anywhere in the docs. How
this might be a very simple question, but I could not find an answer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.