Mattias, Thanks. That worked like a charm. So, string's are OK for input (to Win32 API functions), but StringBuilder's are needed for output.
As you could probably tell, this particular API call is a once-per-app occurrence, so I'm more concerned with compatibility than performance. However, I'm obviously not going to be running this on anything older than Win98, so I suppose CharSet.Auto is better in any case. Bill On Sat, 18 May 2002 20:14:21 +0200, Mattias =?iso-8859-1?Q?Sj=F6gren?= <[EMAIL PROTECTED]> wrote: >Bill, > >For output string buffers, you should use a StringBuilder parameter, not >string. > >Explicitly calling the ANSI versions of APIs is bad for performance on NT >based systems. It's better if you let the runtime decide which version to >call by using CharSet.Auto. > >[DllImport("kernel32.dll", CharSet=CharSet.Auto)] >public static extern int GetPrivateProfileString( > string lpApplicationName, string lpKeyName, string lpDefault, > System.Text.StringBuilder lpReturnedString, int nSize, string lpFileName); > >-- > >StringBuilder buffer = new StringBuilder( intSize ); >intDummy = GetPrivateProfileString( "DBLocation", "Path", null, buffer, >buffer.Capacity, strINIPath ); >strDBLocation = buffer.ToString(); > > >Mattias > >=== >Mattias Sjögren >[EMAIL PROTECTED] > >You can read messages from the DOTNET archive, unsubscribe from DOTNET, or >subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.