Page 1 of 1

Question about definition of PROCESSENTRY32 structure

Posted: Wed Jan 23, 2008 1:14 am
by Tipperton
The PROCESSENTRY32 structure is defined as:

Code: Select all

Structure PROCESSENTRY32
  dwSize.l
  cntUsage.l
  th32ProcessID.l
  th32DefaultHeapID.l
  th32ModuleID.l
  cntThreads.l
  th32ParentProcessID.l
  pcPriClassBase.l
  dwFlags.l
  szExeFile.c[260]
EndStructure
I'm curious if there was some specific reason why the szExeFile entry was defined as character array instead of a fixed length string, like this:

Code: Select all

szExeFile.s{260}
As a string it would have allowed direct use with PB's string functions, like this:

Code: Select all

UCase(Trim(ProcEntry32\szExeFile))
As a character array you have to first convert it to a string, like this:

Code: Select all

UCase(Trim(PeekS(@ProcEntry32\szExeFile)))
Not that big a deal, just curious.

Posted: Wed Jan 23, 2008 1:27 am
by pdwyer
I wonder what happens in unicode mode when the size of a .c changes?

MS has it as

Code: Select all


typedef struct tagPROCESSENTRY32 {
  DWORD dwSize;
  DWORD cntUsage;
  DWORD th32ProcessID;
  ULONG_PTR th32DefaultHeapID;
  DWORD th32ModuleID;
  DWORD cntThreads;
  DWORD th32ParentProcessID;
  LONG pcPriClassBase;
  DWORD dwFlags;
  TCHAR szExeFile[MAX_PATH];
} PROCESSENTRY32, 
So a string should work but MSDN doesn't talk about unicode for that structure.

Posted: Wed Jan 23, 2008 1:43 am
by Tipperton
Ah!

That could be the reason why they did it that way, then in a unicode mode program you could do:

Code: Select all

UCase(Trim(PeekS(@ProcEntry32\szExeFile, -1, #PB_Ascii)))
You might still be able to do this if it's defined as a string, but I'm not 100% sure of that.