Tim Van Wassenhove home

This snippet uses GetPrivateProfileString that is available in kernel32.dll. Apparently microsoft has decided to remove this useful function from the dotnet api.

[DllImport("kernel32", SetLastError=true)]
extern int GetPrivateProfileString(
String ^pSection,
String ^pKey,
String ^pDefault,
StringBuilder ^pValue,
int pBufferLen,
String ^pFile
);

StringBuilder ^buf = gcnew StringBuilder(256);
GetPrivateProfileString(
"logsection",
"file",
"default",
buf,
buf->Capacity,
"example.ini"
);

std::string \_log\_file = new string(
(char*) Marshal::StringToHGlobalAnsi(logf).ToPointer()
);