Question about definition of PROCESSENTRY32 structure

Windows specific forum
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Question about definition of PROCESSENTRY32 structure

Post 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.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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.
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post 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.
Post Reply