GetPrivateProfileString

  • Thread starter Thread starter Lalasa
  • Start date Start date
L

Lalasa

I got GetPrivateProfileString to work using interop, but there is
something that is bugging me.

This is the syntax provided on Pinvoke.net
[DllImport("kernel32.dll")]
static extern uint GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
uint nSize,
string lpFileName);


Why should lpReturnedString be a StringBuilder type?
Why doesn't the syntax below work?

[DllImport("kernel32.dll")]
static extern uint GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
[MarshalAs(UnmanagedType.LPTStr)] string lpReturnedString,
uint nSize,
string lpFileName);

MSDN documentation is as below:

DWORD GetPrivateProfileString(
LPCTSTR lpAppName,
LPCTSTR lpKeyName,
LPCTSTR lpDefault,
LPTSTR lpReturnedString,
DWORD nSize,
LPCTSTR lpFileName
);


Thanks,
Lalasa.
 
Why should lpReturnedString be a StringBuilder type?
Why doesn't the syntax below work?

Because it's an output parameter which is changed by the called
function. Strings are immutable and can't be changed.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

use GetPrivateProfileString 2
GetProfileItem. 7
GetPrivateProfileString 5
Reading an INI file 18
How is it work? 4
Reading INI File 1
GetPrivateProfileString 2
ini file 2 2

Back
Top