Passing string buffers to API calls
I recently had to make some API calls that passed a string buffer. Here's what I came up with:
[DllImport("msi", CharSet=CharSet.Auto)]
private static extern int MsiRecordGetString(IntPtr recordhandle,
int Field, string ValueBuffer, ref int len);
string buffer = new string(' ', 250);
int bufSize=buf.Length;
rv = MsiRecordGetString(hRec, x, buffer, ref bufSize);
Console.Write(buf.Substring(0, bufSize));
Does it sound about right?
Another question is when to use IntPtr instead of int?

0 Comments:
Post a Comment
<< Home