Hi,
I am calling "GetPrivateProfileString" function to
retrieve some key/value from my ini file in C# code.
I have used the DllImport Method to import the function
from Kernel32.dll.
For some reason, when i call this, it does not seem to
work. In the same scenario , another API function from the
same dll called "MoveFile" works. I am putting my code
below. Please advise.
namespace Localization
{
class ReadINI
{
[DllImport
("kernel32",EntryPoint="GetPrivateProfileString",ExactSpell
ing=false, CharSet=CharSet.Auto,SetLastError=true)]
public static extern long GetPrivateProfileString(string
Section, string Key, string Default, string KeyValue ,long
Size , string INIFileName);
[DllImport
("kernel32",EntryPoint="MoveFile",ExactSpelling=false,
CharSet=CharSet.Auto,SetLastError=true)]
public static extern bool MoveFile(string srcfile,
string destfile);
}
When I try to call it from Main() it looks like this.
static void Main()
{
long x;
string sKeyvalue;
string Ldir;
long xval;
xval=0;
Ldir="C:\\windows\\Localisation.ini";
sKeyvalue="";
x = ReadINI.GetPrivateProfileString
("English","001","NotFound",sKeyvalue,xval,Ldir);
}
What could be the problem ??
Regards
Sonu
Mattias Sj?gren - 21 Aug 2003 14:59 GMT
> [DllImport
>("kernel32",EntryPoint="GetPrivateProfileString",ExactSpell
>ing=false, CharSet=CharSet.Auto,SetLastError=true)]
> public static extern long GetPrivateProfileString(string
>Section, string Key, string Default, string KeyValue ,long
>Size , string INIFileName);
The return type and the type of the Size parameter should be (u)int,
not long. The KeyValue parameter should be a StringBuilder, not a
string.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Sonu - 26 Aug 2003 11:55 GMT
Hi Mattias,
Thanx a lot. :) U did solve my problem.
Regards
Sonu
>-----Original Message-----
>
>> [DllImport
("kernel32",EntryPoint="GetPrivateProfileString",ExactSpell
>>ingúlse, CharSet=CharSet.Auto,SetLastError=true)]
>> public static extern long GetPrivateProfileString(string
[quoted text clipped - 6 lines]
>
>Mattias