Ver código fonte

BfpProcess_GetById pid check

Brian Fiete 11 meses atrás
pai
commit
4129c38bb2

+ 1 - 0
BeefySysLib/platform/PlatformInterface.h

@@ -172,6 +172,7 @@ enum BfpProcessResult
 	BfpProcessResult_Ok = BfpResult_Ok,
 	BfpProcessResult_UnknownError = BfpResult_UnknownError,
 	BfpProcessResult_InsufficientBuffer = BfpResult_InsufficientBuffer,
+	BfpProcessResult_NotFound = BfpResult_NotFound
 };
 
 BFP_EXPORT intptr BFP_CALLTYPE BfpProcess_GetCurrentId();

+ 9 - 2
BeefySysLib/platform/win/Platform.cpp

@@ -1295,6 +1295,13 @@ 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);
+	if (hProc == NULL)
+	{
+		OUTRESULT(BfpProcessResult_NotFound);
+		return NULL;
+	}	
+
 	BfpProcess* process = new BfpProcess();
 	process->mProcessId = processId;
 	process->mInfo = NULL;
@@ -1495,9 +1502,9 @@ BFP_EXPORT void BFP_CALLTYPE BfpProcess_GetProcessName(BfpProcess* process, char
 	if (process->mImageName.IsEmpty())
 	{
 		HANDLE hProc = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, process->mProcessId);
-		if (hProc == INVALID_HANDLE_VALUE)
+		if (hProc == NULL)
 		{
-			OUTRESULT(BfpProcessResult_UnknownError);
+			OUTRESULT(BfpProcessResult_NotFound);
 			return;
 		}
 		WCHAR wName[MAX_PATH] = { 0 };