Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. getting ini value

getting ini value

Scheduled Pinned Locked Moved C#
jsonquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 589870
    wrote on last edited by
    #1

    hi, i am using api GetPrivateProfileString(string section, string key, string def, string retVal, int size, string filePath); which is not working for me but if i declare 4th arguement as stringBuilder then it works fine but i want to keep it string.wat to do?

    OriginalGriffO P 2 Replies Last reply
    0
    • U User 589870

      hi, i am using api GetPrivateProfileString(string section, string key, string def, string retVal, int size, string filePath); which is not working for me but if i declare 4th arguement as stringBuilder then it works fine but i want to keep it string.wat to do?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Strings are immutable - this is a return parameter so you must supply a changeable type. You just convert from StringBuilder to string via StringBuilder.ToString when you need it. I would suggest though, that you look at .NET app.Config files instead, as .INI files are a little old style...

      I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in. Apathy Error: Don't bother striking any key.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • U User 589870

        hi, i am using api GetPrivateProfileString(string section, string key, string def, string retVal, int size, string filePath); which is not working for me but if i declare 4th arguement as stringBuilder then it works fine but i want to keep it string.wat to do?

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Whenever I use P/Invoke I write a method to wrap the API method:

            \[
                System.Runtime.InteropServices.DllImportAttribute 
                ( 
                    "Kernel32" 
                , 
                    SetLastError=true 
                , 
                    EntryPoint="GetPrivateProfileString" 
                )
            \]
            private unsafe static extern uint
            API\_GetPrivateProfileString
            (
                string lpAppName        
            ,
                string lpKeyName        
            ,
                string lpDefault        
            ,
                byte\*  lpReturnedString 
            ,
                int    nSize            
            ,
                string lpFileName
            ) ;
        
            public unsafe static int
            GetPrivateProfileString
            (
                string     lpAppName        
            ,
                string     lpKeyName        
            ,
                string     lpDefault        
            ,
                out string lpReturnedString 
            ,
                int        nSize            
            ,
                string     lpFileName
            )
            {
                int    result ;
                byte\[\] temp   = new byte \[ nSize \] ;
        
                fixed ( byte\* ptemp = temp )
                {
                    result = (int) API\_GetPrivateProfileString
                    (
                        lpAppName        
                    ,
                        lpKeyName        
                    ,
                        lpDefault        
                    ,
                        ptemp            
                    ,
                        nSize            
                    ,
                        lpFileName
                    ) ;
                }
        
                lpReturnedString = System.Text.Encoding.Unicode.GetString ( temp ).Substring ( 0 , result ) ;
        
                return ( result ) ;
            }
        

        I wrote this for someone else when I was just learning C#, I don't use it. I use XML for configuration files.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups