Get Current Process ID within calling EXE
Posted: Tue Dec 16, 2008 8:07 pm
Ok, I wrote this following function to return the current process id from within the calling EXE, however, I don't like having to open a window to do it since it is in a non-windowed app. Granted, it does work, but does anyone have a non-window method to do this?
Code: Select all
Procedure.l CurrentProcessId()
Protected lRetVal.l, lWindowId.l, lWinId.l, lProcId.l, lThreadId.l
lRetVal.l = 0
lWindowId = OpenWindow(#PB_Any, 100, 200, 195, 260, "_CURRENT_PROCESS_WINDOW_", #PB_Window_Invisible)
If (lWindowId)
lWinId = WindowID(lWindowId)
lThreadId = GetWindowThreadProcessId_(lWinId,@lProcId)
lRetVal.l = lProcId
CloseWindow(lWindowId.l)
EndIf
ProcedureReturn lRetVal.l
EndProcedure
Debug CurrentProcessId()