Given:
[StructLayout(La youtKind.Sequen tial, CharSet=CharSet .Auto)]
private struct PROCESSENTRY32
{
public int dwSize;
public int cntUsage;
public int th32ProcessID;
public int th32DefaultHeap ID;
public int th32ModuleID;
public int cntThreads;
public int th32ParentProce ssID;
public int pcPriClassBase;
public int dwFlags;
[MarshalAs(Unman agedType.ByValT Str, SizeConst=MAX_P ATH)]
public char szExeFile;
}
and
PROCESSENTRY32 pe32 = new PROCESSENTRY32( );
I was using the following:
pe32.dwSize =sizeof(PROCESS ENTRY32);
But that returned the wrong value 40 instead of the correct value 296, as
MAX_PATH is 260.
So I tried the following:
pe32.dwSize = Marshal.SizeOf( PROCESSENTRY32) ;
Which results in the following error at build time:
D:\Visual Basic
Code\API\EnumPr ocesses\Code-GetUsageCount\C sharpGetUsageCo unt\Form1.cs(34 0):
'CsharpGetUsage Count.Form1.MOD ULEENTRY32' denotes a 'class' where a
'variable' was expected
So, I tried
pe32.dwSize = Marshal.SizeOf( pe32);
Alas, that ended up causing an exception, with the message:
"Type PROCESSENTRY32 can not be marshaled as an unmanaged structure; no
meaningful size or offset can be computed."
What do I need to do to correct the problem?
[StructLayout(La youtKind.Sequen tial, CharSet=CharSet .Auto)]
private struct PROCESSENTRY32
{
public int dwSize;
public int cntUsage;
public int th32ProcessID;
public int th32DefaultHeap ID;
public int th32ModuleID;
public int cntThreads;
public int th32ParentProce ssID;
public int pcPriClassBase;
public int dwFlags;
[MarshalAs(Unman agedType.ByValT Str, SizeConst=MAX_P ATH)]
public char szExeFile;
}
and
PROCESSENTRY32 pe32 = new PROCESSENTRY32( );
I was using the following:
pe32.dwSize =sizeof(PROCESS ENTRY32);
But that returned the wrong value 40 instead of the correct value 296, as
MAX_PATH is 260.
So I tried the following:
pe32.dwSize = Marshal.SizeOf( PROCESSENTRY32) ;
Which results in the following error at build time:
D:\Visual Basic
Code\API\EnumPr ocesses\Code-GetUsageCount\C sharpGetUsageCo unt\Form1.cs(34 0):
'CsharpGetUsage Count.Form1.MOD ULEENTRY32' denotes a 'class' where a
'variable' was expected
So, I tried
pe32.dwSize = Marshal.SizeOf( pe32);
Alas, that ended up causing an exception, with the message:
"Type PROCESSENTRY32 can not be marshaled as an unmanaged structure; no
meaningful size or offset can be computed."
What do I need to do to correct the problem?
Comment