> Thank you for your reply. I will prepare short program after the weekends.
>
[quoted text clipped - 16 lines]
> Microsoft may have for the bug described in the article I have referred to
> above is applicable in my case as well?

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jon,
I have solved my problem by inserting string strA = strB.Trim( ) statement
between several lines of code until I have pinpointed exact place where
"Trim( )" method starts failing.
The reason was an incorrect declaration of "GetPrivateProfileString" API -
[DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true,
EntryPoint = "GetPrivateProfileString", CallingConvention =
CallingConvention.StdCall )]
public extern static int GetPrivateProfileString( string section, string
key, string default, [Out, MarshalAsAttribute(UnmanagedType.LPTStr)] string
buffer, ref int size, string fileName );
which I used in the following way -
string fileName = "C:\\Windows\\file.ini";
string buffer = String.Empty;
int size = 0;
size = GetPrivateProfileString( "Section", "Key", "Default", buffer, ref
size, fileName );
version = new string( '\0', size );
GetPrivateProfileString( "Section", "Key ", "Default", buffer, ref size,
fileName );
After the last call the "buffer" variable did contain correctly read value
but all subsequent calls to String.Trim( ) method began to throw
‘ExecutionEngineException’.
Now I am using the following declaration -
[DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true,
EntryPoint = "GetPrivateProfileString", CallingConvention =
CallingConvention.StdCall )]
public extern static int GetPrivateProfileString( string section, string
key, string default, IntPtr buffer, ref int size, string fileName );
I would appreciate if you briefly explained what was wrong with the
declaration I had used in the first place.
Thank you for your help.
Eugene.
> > Thank you for your reply. I will prepare short program after the weekends.
> >
[quoted text clipped - 30 lines]
> type which isn't from it. You should be loading the assembly, then
> fetching the type from it, then creating an instance.)
Jon Skeet [C# MVP] - 20 Jun 2005 22:17 GMT
<snip>
> Now I am using the following declaration -
>
[quoted text clipped - 6 lines]
> I would appreciate if you briefly explained what was wrong with the
> declaration I had used in the first place.
Well, I don't know much about GetPrivateProfileString myself, but I
suspect that .NET thought it "owned" the memory which was being
referenced by your out parameter. I believe that *usually* when you
need to effectively get a string as an out parameter, you should pass
in a StringBuilder, but I'm afraid I'm really not an interop expert.
Sorry to pass the buck like this, but it's much better that you get
advice from someone who definitely knows their way around P/Invoke
better than me - I'd suggest asking on the .interop group.
You might also want to look at
http://www.codeproject.com/csharp/cs_ini.asp

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too