Just a quick post for today. I needed to use the LPPROCESS_INFORMATION C type from managed code today, so I poped over to PInvoke.net to see if there was any information on it. There was a definition for PROCESS_INFORMATION, but nothing on LPPROCESS_INFORMATION (well, yes there is now ... but that's because I put it there 🙂 ).
Anyway, here's a quick snippet on going from PROCESS_INFORMATION to LPPROCESS_INFORMATION in managed code. (Since I don't like capitals and underscores in my C#, I've renamed PROCESS_INFORMATION to ProcessInformation). Next week I'll blog more about why I needed this.
public struct ProcessInformation
public IntPtr hProcess;
public IntPtr hThread;
public uint dwProcessId;
public uint dwThreadId;
ProcessInformation procInfo = new ProcessInformation();
GCHandle procInfoHandle = GCHandle.Alloc(procInfo, GCHandleType.Pinned);
IntPtr lpprocessInformation = procInfoHandle.AddrOfPinnedObject();
// ... code that needs to use the LPPROCESS_INFORMATION ...
Note that you can't use the C# using construct with a GCHandle, since GCHandles do not implement IDisposable, so you need to use a try ... finally construct.