Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Closing an other '.exe'
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00761170
Message ID:
00761569
Vues:
37
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)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform