More marshalling…

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()
);

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>