Skip to content

Instantly share code, notes, and snippets.

@betaEncoder
Created September 30, 2014 07:09
Show Gist options
  • Save betaEncoder/a5c06dfa310ca7e9c539 to your computer and use it in GitHub Desktop.
Save betaEncoder/a5c06dfa310ca7e9c539 to your computer and use it in GitHub Desktop.
C#でwin32API等を呼び出す時に構造体をmarshal時にアンマネージド変数のようにパッキングしてもらう覚書き
using System.Runtime.InteropServices;
// 構造体の中身をきっちりパッキングする
[StructLayout(LayoutKind.Sequential)]
struct message
{
public byte foo;
public byte bar;
public uint16 boo;
// 構造体に配列を含めたいとき
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 240)]
public byte[] dataArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment