Hi,
i was trying to port some C-Code to pascal and encountered with some weird error.
The C-Code is very simple:
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE) {
....
In pascal, the ported code returned an error at Process32First with GetLastError() 24 (BAD LENGTH).
I compared sizeof(PROCESSENTRY32) in visual studio with sizeof(PROCESSENTRY32) in pascal and noticed that in visual studio the size is 304 while on pascal it is 300.
This comes because of the struct:
tagPROCESSENTRY32 = record
dwSize: DWORD;
cntUsage: DWORD;
th32ProcessID: DWORD; // this process
th32DefaultHeapID: ULONG_PTR;
th32ModuleID: DWORD; // associated exe
cntThreads: DWORD;
th32ParentProcessID: DWORD; // this process's parent process
pcPriClassBase: LONG; // Base priority of process's threads
dwFlags: DWORD;
szExeFile: array [0..MAX_PATH - 1] of Char; // Path
end;
this:
th32DefaultHeapID: ULONG_PTR;
is at offset 0xC and not aligned to 8 bytes, which it has to be on x64. That's why it should be 8 byte aligned (+4).
This is either a bug, or I just don't know what I am doing.