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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. .ini files

.ini files

Scheduled Pinned Locked Moved C#
csharphelpquestion
2 Posts 2 Posters 7 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.
  • F Offline
    F Offline
    Fuhrer
    wrote on last edited by
    #1

    i want to read .ini files with c# i import using System.Runtime.InteropServices; and i wrote these [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); StringBuilder stb = new StringBuilder(250); GetPrivateProfileString("HATALAR", key, "", stb, 250, "C:\\Documents and Settings\\......."); i want to use stb it gives me no error but it can't find any thing.my path, key section are true.do i have to import something else? or what must i do?

    D 1 Reply Last reply
    0
    • F Fuhrer

      i want to read .ini files with c# i import using System.Runtime.InteropServices; and i wrote these [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); StringBuilder stb = new StringBuilder(250); GetPrivateProfileString("HATALAR", key, "", stb, 250, "C:\\Documents and Settings\\......."); i want to use stb it gives me no error but it can't find any thing.my path, key section are true.do i have to import something else? or what must i do?

      D Offline
      D Offline
      Dy
      wrote on last edited by
      #2

      There's nothing wrong with your code, I've just tried it (see below) and it works fine.

      using System.Text; // For StringBuilder
      using System.Runtime.InteropServices; // For DllImport

      // class declaration and all that jazz here

      	\[DllImport("kernel32")\]
      	private static extern int GetPrivateProfileString(string section,
      		string key, string def, StringBuilder retVal,
      		int size, string filePath);
      
      	StringBuilder stb = new StringBuilder(250);
      	private void Form1\_Load(object sender, System.EventArgs e)
      	{
      		GetPrivateProfileString("mySect", "item", "def\_", stb, 250, @"c:\\temp\\myfile.ini");
      		stb = stb; // a line for me to set a breakpoint in
      	}
      

      I set a breakpoint on the stb = stb; line, and used quick view to look at the object - my INI file data is there. Therefore... double check the path to your INI file, double check the INI file is in the correct format. My enable files looks like this:

      [mySect]
      item=notDEFAULT

      Hope that helps.


      - Dy

      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