DWORD dwPID[100] = {NULL};
DWORD* ptr = dwPID;
DWORD cbNeeded = NULL;
EnumProcesses(ptr, 100, &cbNeeded);
/*
BOOL WINAPI EnumProcesses(
__out DWORD *pProcessIds,
__in DWORD cb,
__out DWORD *pBytesReturned
);
*/
DWORD dwPID[100] = { NULL };
DWORD Returned = NULL;
if( !EnumProcesses( &dwPID[0], sizeof( DWORD )*100, &Returned ) )
printf("Error: 0x%.8x\n", GetLastError() );
DWORD GetProcessPID(string name)
{
DWORD ProcPid = NULL;
char FileName[100] = {NULL};
DWORD dwPID[100] = {NULL};
DWORD Returned = NULL;
if(!EnumProcesses(&dwPID[0], 100, &Returned))
{
MessageBoxA(NULL, "Error", "Injector", MB_OK);
}
else
{
for (int i=0; i<100; i++)
{
HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwPID[i]);
GetModuleBaseNameA(hProc, NULL, FileName, 100);
CloseHandle(hProc);
if (!(_stricmp(FileName, name.c_str())))
{
ProcPid = dwPID[i];
}
}
Sleep(50);
return ProcPid;
}
return NULL;
}
DWORD *dwPID = new DWORD[100]; // it could be that your stack grows too large for the windows function to work properly, try dynamic allocation.