Hello Pelle
just playing around with JOB_OBJECTS.
The declaration
BOOL WINAPI IsProcessInJob (HANDLE,HANDLE,PBOOL);
is missing in Winbase.h.
(Definition too)
senseless Examplecode
#include <stdio.h>
// For JOB-Objects ...
#define _WIN32_WINNT 0x0500
#include <windows.h>
// for Processenumeration
#include <tlhelp32.h>
#define ErrorText(e,t) printf("%d %s\n",e,t)
static int ExistsAssociatedProcs(HANDLE hJob)
{
int hasProcs = TRUE; /* This is the save assument */
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if ( hSnapshot != INVALID_HANDLE_VALUE )
{
/* We got a snapshot with the processlist */
PROCESSENTRY32 pe;
BOOL proc_found;
// fill up its size
pe.dwSize = sizeof pe;
proc_found = Process32First(hSnapshot,&pe);
if ( proc_found )
{
hasProcs = FALSE; /* HERE we assume no processes associated to the job */
do
{
HANDLE hProcess;
printf("Process ID : %08X\n",pe.th32ProcessID);
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,pe.th32ProcessID);
if ( hProcess )
{
BOOL is_associated;
if ( IsProcessInJob(hProcess,hJob,&is_associated) ) // <<< NOT DECLARED
{
if ( is_associated )
{
hasProcs = TRUE; /* At least one process is associated */
break;
/* NOTREACHED */
}
}
else
ErrorText(GetLastError(),"IsProcessInJob");
if ( !CloseHandle(hProcess) )
ErrorText(GetLastError(),"CloseHandle Process ?");
}
pe.dwSize = sizeof pe;
proc_found = Process32Next(hSnapshot,&pe);
}
while ( proc_found );
}
else
ErrorText(GetLastError(),"Process32First: No entries found ?");
// close snapshot handle
if ( !CloseHandle(hSnapshot) )
ErrorText(GetLastError(),"CloseHandle in Snapshothandle");
}
else
ErrorText(GetLastError(),"CreateToolhelp32Snapshot");
return hasProcs;
}
int main( void )
{
ExistsAssociatedProcs((HANDLE)1);
return 0;
}
By the way,
there is another missing Declaration/Definition
BOOL WINAPI CreateJobSet (ULONG,PJOB_SET_ARRAY,ULONG);
but I didnĀ“t use it and don't know the functionality.