getting ini value
-
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?
-
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?
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.
-
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?
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.