Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Closing an other '.exe'
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00761170
Message ID:
00761569
Views:
38
Not even close to my patience's limit :)

GetWindowThreadProcessId returns an ID to a process, not process handle. That is why the EnumProcessModules returns zero.
If you call GetLastError right after this, most probably it returns code 6 that means ERROR_INVALID_HANDLE.

Try this code:
#DEFINE PROCESS_QUERY_INFORMATION 0x400
#DEFINE PROCESS_VM_READ 0x10

DECLARE INTEGER GetActiveWindow IN user32
DECLARE INTEGER GetLastError IN kernel32
DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject

DECLARE INTEGER OpenProcess IN kernel32;
	INTEGER dwAccess, INTEGER bHandle, INTEGER dwProcId

DECLARE INTEGER GetWindowThreadProcessId IN user32;
	INTEGER hWnd, INTEGER @lpdwProcId

DECLARE INTEGER EnumProcessModules IN psapi;
	INTEGER hProcess, STRING @lphModule,;
	INTEGER cb, INTEGER @cbNeeded

LOCAL hWindow, nProcessId, nThreadId, hProcess
STORE 0 TO nProcessId, nThreadId
hWindow = GetActiveWindow()
nThreadId = GetWindowThreadProcessId(hWindow, @nProcessId)

hProcess = OpenProcess(PROCESS_QUERY_INFORMATION+PROCESS_VM_READ,;
	0, nProcessId)

LOCAL cBuffer, nBufsize, nNeeded, nResult
nBufsize = 16384
cBuffer = Repli(Chr(0), nBufsize)
nNeeded = 0

IF EnumProcessModules(hProcess, @cBuffer, nBufsize, @nNeeded) = 0
	? 'Error code:', GetLastError()
ELSE
	? 'Modules for the process enumerated successfully'
ENDIF

= CloseHandle(hProcess)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform