1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 03:28:20 +02:00

BfpProcess_WaitFor, BeefCon shutdown fix

This commit is contained in:
Brian Fiete 2024-10-21 09:13:26 -04:00
parent 6a14bb55b5
commit c8dda5d1d9
5 changed files with 79 additions and 6 deletions

View file

@ -180,6 +180,7 @@ BFP_EXPORT bool BFP_CALLTYPE BfpProcess_IsRemoteMachine(const char* machineName)
BFP_EXPORT BfpProcess* BFP_CALLTYPE BfpProcess_GetById(const char* machineName, int processId, BfpProcessResult* outResult);
BFP_EXPORT void BFP_CALLTYPE BfpProcess_Enumerate(const char* machineName, BfpProcess** outProcesses, int* inOutProcessesSize, BfpProcessResult* outResult);
BFP_EXPORT void BFP_CALLTYPE BfpProcess_Release(BfpProcess* process);
BFP_EXPORT int BFP_CALLTYPE BfpProcess_GetExitCode(BfpProcess* process, BfpProcessResult* outResult);
BFP_EXPORT void BFP_CALLTYPE BfpProcess_GetMainWindowTitle(BfpProcess* process, char* outTitle, int* inOutTitleSize, BfpProcessResult* outResult);
BFP_EXPORT void BFP_CALLTYPE BfpProcess_GetProcessName(BfpProcess* process, char* outName, int* inOutNameSize, BfpProcessResult* outResult);
BFP_EXPORT int BFP_CALLTYPE BfpProcess_GetProcessId(BfpProcess* process);

View file

@ -858,6 +858,11 @@ BFP_EXPORT void BFP_CALLTYPE BfpProcess_Release(BfpProcess* process)
NOT_IMPL;
}
BFP_EXPORT bool BFP_CALLTYPE BfpProcess_WaitFor(BfpProcess* process, int waitMS, int* outExitCode, BfpProcessResult* outResult)
{
NOT_IMPL;
}
BFP_EXPORT void BFP_CALLTYPE BfpProcess_GetMainWindowTitle(BfpProcess* process, char* outTitle, int* inOutTitleSize, BfpProcessResult* outResult)
{
NOT_IMPL;

View file

@ -1285,7 +1285,15 @@ struct BfpProcess
{
int mProcessId;
SYSTEM_PROCESS_INFORMATION* mInfo;
HANDLE mProcess;
String mImageName;
BfpProcess()
{
mProcessId = -1;
mInfo = NULL;
mProcess = 0;
}
};
BFP_EXPORT bool BFP_CALLTYPE BfpProcess_IsRemoteMachine(const char* machineName)
@ -1295,16 +1303,16 @@ BFP_EXPORT bool BFP_CALLTYPE BfpProcess_IsRemoteMachine(const char* machineName)
BFP_EXPORT BfpProcess* BFP_CALLTYPE BfpProcess_GetById(const char* machineName, int processId, BfpProcessResult* outResult)
{
HANDLE hProc = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, processId);
HANDLE hProc = ::OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, processId);
if (hProc == NULL)
{
OUTRESULT(BfpProcessResult_NotFound);
return NULL;
}
::CloseHandle(hProc);
}
BfpProcess* process = new BfpProcess();
process->mProcessId = processId;
process->mProcess = hProc;
process->mInfo = NULL;
return process;
}
@ -1395,9 +1403,34 @@ BFP_EXPORT void BFP_CALLTYPE BfpProcess_Release(BfpProcess* process)
{
if (process->mInfo != NULL)
free(process->mInfo);
if (process->mProcess != NULL)
::CloseHandle(process->mProcess);
delete process;
}
BFP_EXPORT bool BFP_CALLTYPE BfpProcess_WaitFor(BfpProcess* process, int waitMS, int* outExitCode, BfpProcessResult* outResult)
{
if (process->mProcess == NULL)
{
OUTRESULT(BfpProcessResult_NotFound);
return false;
}
if (::WaitForSingleObject(process->mProcess, waitMS) != WAIT_OBJECT_0)
{
OUTRESULT(BfpProcessResult_NotFound);
return false;
}
DWORD errorCode = 0;
GetExitCodeProcess(process->mProcess, &errorCode);
if (outExitCode != NULL)
*outExitCode = (int)errorCode;
OUTRESULT(BfpProcessResult_Ok);
return true;
}
//struct EnumWndData
//{
// HWND mBestHandle;