Skip to content

Instantly share code, notes, and snippets.

@keijiro
Created January 25, 2022 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keijiro/1cc523ef17f9904d718edc145de407e6 to your computer and use it in GitHub Desktop.
Save keijiro/1cc523ef17f9904d718edc145de407e6 to your computer and use it in GitHub Desktop.
#if HOGEHOGE
struct FullName
{
[MarshalAs(UnmanagedType.LPStr)] public string first;
[MarshalAs(UnmanagedType.LPStr)] public string last;
}
[DllImport(_dll)]
static extern uint get_full_length(in FullName name);
void RunFullNameTest()
=> Debug.Log(get_full_length(
new FullName { first = "Keijiro", last = "Takahashi" }));
#else
struct FullName
{
public IntPtr first;
public IntPtr last;
}
[DllImport(_dll)]
static extern uint get_full_length(in FullName name);
void RunFullNameTest()
{
var p1 = Marshal.StringToHGlobalAnsi("Keijiro");
var p2 = Marshal.StringToHGlobalAnsi("Takahashi");
Debug.Log(get_full_length(new FullName { first = p1, last = p2 }));
Marshal.FreeHGlobal(p1);
Marshal.FreeHGlobal(p2);
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment