I am using C# + Silk4NET. I need to get remote machine process information with using module32first method.
How it should be declared? I've tried to declare it as follow:
[Dll("kernel32.dll")]
public interfaces IKernel32Functions
{
Int64 CreateToolhelp32Snapshot(int dwFlags, int th32ProcessID);
int Module32First(long hSnapshot, ref API.ApiFunc.MODULEENTRY32 lpme);
}
[StructLayout(LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public struct MODULEENTRY32
{
public uint dwSize;
public uint th32ModuleID;
public uint th32ProcessID;
public uint GlblcntUsage;
public uint ProccntUsage;
public long modBaseAddr;
public uint modBaseSize;
public long hModule;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string szModule;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szExePath;
}
I call it as follow:
IKernel32Functions kernel32Caller = DllCall.CreateAgentDllCall<IKernel32Functions>();
long snapshot = kernel32Caller.CreateToolhelp32Snapshot(0x00000008, 5792);
ApiFunc.MODULEENTRY32 me32 = new ApiFunc.MODULEENTRY32();
int result = kernel32Caller.Module32First(snapshot, ref me32);
And get "Cannot serialize MODULEENTRY32". I tried to use ArrayList instead of MODULEENTRY32 struct and IntPtr, but I could not get anything.
How Module32First() method should be declared and what type should be used for getting MODULEENTRY32 instance ?