merge the formfield patch from ooo-build
[ooovba.git] / sal / systools / win32 / uwinapi / EnumProcesses.cpp
blob567ee32e08e4312ff99d74134d59d35423cca320
1 #include "macros.h"
2 #include <tlhelp32.h>
4 IMPLEMENT_THUNK( psapi, WINDOWS, BOOL, WINAPI, EnumProcesses, ( LPDWORD lpProcesses, DWORD cbSize, LPDWORD lpcbCopied ) )
6 BOOL fSuccess = FALSE;
7 HANDLE hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
9 if ( IsValidHandle( hSnapshot ) )
11 PROCESSENTRY32 pe;
13 if ( lpcbCopied )
14 *lpcbCopied = 0;
16 pe.dwSize = sizeof(pe);
17 if ( Process32First( hSnapshot, &pe ) )
19 fSuccess = TRUE;
21 while ( cbSize >= sizeof(*lpProcesses) )
23 *(lpProcesses++) = pe.th32ProcessID;
24 if ( lpcbCopied )
25 *lpcbCopied += sizeof(*lpProcesses);
26 cbSize -= sizeof(*lpProcesses);
28 if ( !Process32Next( hSnapshot, &pe ) )
29 break;
33 CloseHandle( hSnapshot );
35 else
36 SetLastError( ERROR_INVALID_HANDLE );
38 return fSuccess;