c# - How to read ASCII control characters from INI -


i'm calling following native api read/write ini files

[dllimport("kernel32.dll")] private static extern int getprivateprofilestring(    // ini read         string section,         string key,         string def,         stringbuilder retval,         int size,         string filepath); [dllimport("kernel32.dll")] private static extern long writeprivateprofilestring(  // ini write         string section,         string key,         string val,         string filepath);  public string readini(string sectionstring, string keystring, string filepathstring)  {     stringbuilder temp = new stringbuilder(200000);     int = getprivateprofilestring(sectionstring, keystring, "", temp, temp.capacity, filepathstring);     return temp.tostring(); }          // write (section, key, data, file path) public void writeini( string sectionstring, string keystring, string datastring, string filepathstring)  {     writeprivateprofilestring(sectionstring, keystring, datastring, filepathstring); } 

reading/writing ini files works above code.

when try read ascii control chars, such 0x02 (stx) , 0x03 (etx), read function returns empty string. writing control characters works perfectly.

normally, i'd avoid using native apis read/write ini or better yet, avoid using ini files altogether, old legacy application i'm fixing that need function work in current form.

how can make getprivateprofilestring read ascii control characters?

i think problem @ writing ini. must use code writing ini file :

//writing ini file  string pfilename = "test.ini" string w_text = "[" + psection + "]" + environment.newline +                                  pkey + "=" + pdefvalue; system.io.file.writealltext(pfilename, w_text, encoding.utf8); 

you can read ini file above codes :

//reading ini file  pfilename="test.ini"; inidocument w_ini = new inidocument(pfilename, inifiletype.windowsstyle); iconfigsource w_source = new iniconfigsource(w_ini); return w_source.configs[psection].get(pkey); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -