I am trying to bind this C function using PInvoke.
bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode);
Here is the PInvoke signature.
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiTextBox(Rectangle bounds,
string text,
int textSize,
bool freeEdit);
When I try to use it the string does not get modified. I tried passing it as ref but it crashes with attempted to read or write protected memory when I try to use it.
stringis immutable. Try creating aStringBuilderand pass that instead.DllImportor setup custom marshalling for your string, like here learn.microsoft.com/en-us/dotnet/framework/interop/…StringBuilderinstead ofString? be creaful with encoding:CharSet = CharSet.UnicodeorCharSet = CharSet.AnsiStringBuilder.