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

This entry was posted on Wednesday, March 1st, 2006 at 02:49 and is filed under C++. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.