Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
VB .NET upgrades that to:
Private Structure PROCESSENTRY32
Dim dwSize As Integer
Dim cntUsage As Integer
Dim th32ProcessID As Integer
Dim th32DefaultHeapID As Integer
Dim th32ModuleID As Integer
Dim cntThreads As Integer
Dim th32ParentProcessID As Integer
Dim pcPriClassBase As Integer
Dim dwFlags As Integer
<VBFixedString(MAX_PATH),System.Runtime.InteropSer vices.MarshalAs
(System.Runtime.InteropServices.UnmanagedType.ByVa lTStr,SizeConst:=MAX_PATH)
Public szExeFile As String
End Structure
As upgraded, the code runs as expected.
However, there are warning messages:
'UPGRADE_WARNING: Structure PROCESSENTRY32 may require marshalling
attributes to be passed as an argument in this Declare statement. Click for
more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1050"'
So following the instructions in the warning, I modified the structure to:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> Private
Structure PROCESSENTRY32
Dim dwSize As Integer
Dim cntUsage As Integer
Dim th32ProcessID As Integer
Dim th32DefaultHeapID As Integer
Dim th32ModuleID As Integer
Dim cntThreads As Integer
Dim th32ParentProcessID As Integer
Dim pcPriClassBase As Integer
Dim dwFlags As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_PATH)> Public
szExeFile As String
End Structure
This causes the code to not excute correctl;y because
Dim pe32 As PROCESSENTRY32
pe32.dwSize = Len(pe32)
Fails to set the correct size.
Without the marshalling changes, len(pe32) correctly returns 296.
With the marshalling changes. len(pe32) returns 40.
What needs to be done to correct this problem?
--
http://www.standards.com/; See Howard Kaikow's web site.