Skip to content

Instantly share code, notes, and snippets.

@txdv
Last active November 16, 2016 07:15
Show Gist options
  • Save txdv/ff2b572478913e66fcf99a46895200c1 to your computer and use it in GitHub Desktop.
Save txdv/ff2b572478913e66fcf99a46895200c1 to your computer and use it in GitHub Desktop.
Example
using System;
using System.Runtime.InteropServices;
public class MainClass
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private struct ModuleInputData
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 260)]
public unsafe fixed char name[260];
public uint pid;
}
public unsafe static void Main(string[] args)
{
ModuleInputData data;
var arg = args[0];
fixed (char* ptr = arg)
{
for (int i = 0; i < 260; i++) {
char chr = *(ptr + i);
if (chr == '\0') {
break;
}
data.name[i] = chr;
}
data.name[0] = ptr[0];
}
}
}
main.exe: main.cs
mcs /unsafe main.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment