[Solved] Enumprocesses in Windows API not supported? lazarus / 34-Windows ---------------------------------------------------------------------- TyneBridges · 2013-03-22 16:40 Hopefully an easy question...I'm trying to use some code from Delphi in Lazarus. I have "Uses Windows" in my declarations, and other Windows API functions compile and work successfully. However, the following Code: [Select]EnumProcesses(@PIDList, ListSize, cbNeeded); gives the error "Identifier not found: EnumProcesses". Is Lazarus' support for the Windows API only partial? If so, is there another call I can use to get process ID numbers? I have hunted around to try to answer this myself, but can't find any reference to this call in the documentation or in Google searches - so, if the declaration is in a unit I haven't installed, I don't know which one. Thanks for any help. ---------------------------------------------------------------------- Deepaak · 2013-03-22 19:00 have you tried including JwaWindows in your unit section ---------------------------------------------------------------------- ChrisF · 2013-03-22 19:31 This one is a part of Psapi.h: PsAPI.pas in Delphi. But it seems that FPC/Lazarus doesn't have such a file. As proposed by deepaak99, you can use Jedi for it (seems to be declared in the jwapsapi.pas file). ---------------------------------------------------------------------- Chronos · 2013-03-22 19:50 Or if multiplatform variant not exists you can do-it-yourself and declare it by yourself: type   LPDWORD = PDWORD; function EnumProcesses(lpidProcess: LPDWORD; cb: DWORD; var cbNeeded:   DWORD): BOOL; stdcall; external 'PSAPI.dll'; ---------------------------------------------------------------------- BigChimp · 2013-03-23 05:59 Quote from: JohnSaltwell on March 22, 2013, 05:40:05 pmI have hunted around to try to answer this myself, but can't find any reference to this call in the documentation or in Google searches - so, if the declaration is in a unit I haven't installed, I don't know which one. Grepping (or whatever search tool you use) through the FPC source code can work very well. The documentation certainly does not cover all units yet. If you have some more info (or just confirmation that it works), could you add a snippet here: http://wiki.lazarus.freepascal.org/Windows_Pro gramming_Tips#Code_snippets) so posterity need not do the same digging that you did... Thanks a lot ---------------------------------------------------------------------- Deepaak · 2013-03-23 07:30 Quote from: ChrisF on March 22, 2013, 08:31:16 pm This one is a part of Psapi.h: PsAPI.pas in Delphi. But it seems that FPC/Lazarus doesn't have such a file. As proposed by deepaak99, you can use Jedi for it (seems to be declared in the jwapsapi.pas file). yes, JwaPsApi will do. It contains Code: [Select]function EnumProcesses(lpidProcess: LPDWORD; cb: DWORD; var cbNeeded: DWORD): BOOL; stdcall; ---------------------------------------------------------------------- BigChimp · 2013-03-23 07:56 Quote from: ChrisF on March 22, 2013, 08:31:16 pm This one is a part of Psapi.h: PsAPI.pas in Delphi. But it seems that FPC/Lazarus doesn't have such a file. As proposed by deepaak99, you can use Jedi for it (seems to be declared in the jwapsapi.pas file). Well, it may not have psapi.pas but it does have jwapsapi.pas: Code: [Select]C:\Development\fpctrunk\packages>grep -i --recursive EnumProcesses * winunits-jedi/src/jwapsapi.pas:function EnumProcesses(lpidProcess: LPDWORD; cb: DWORD; var cbNeeded: DWORD): BOOL; stdcall; winunits-jedi/src/jwapsapi.pas:{$EXTERNALSYM EnumProcesses} winunits-jedi/src/jwapsapi.pas:  _EnumProcesses: Pointer; winunits-jedi/src/jwapsapi.pas:function EnumProcesses; winunits-jedi/src/jwapsapi.pas:  GetProcedureAddress(_EnumProcesses, PsapiLib, ' EnumProcesses'); winunits-jedi/src/jwapsapi.pas:        JMP     [_EnumProcesses] winunits-jedi/src/jwapsapi.pas:function EnumProcesses; external PsapiLib name 'E numProcesses'; ---------------------------------------------------------------------- theo · 2013-03-23 11:58 Quote from: JohnSaltwell on March 22, 2013, 05:40:05 pmI have hunted around to try to answer this myself, but can't find any reference to this call in the documentation or in Google searches - so, if the declaration is in a unit I haven't installed, I don't know which one. A general hint: Lazarus has a wonderful but rather unknown feature: 1. Write the command (here EnumProcesses) in your code. 2. Try to compile 3. Right click on the error message in the message window 4. Select "Search identifier" 5. If necessary, select a scope 6. Lazarus will show the unit name if found. Or use the Code Browser from the "View" Menu ---------------------------------------------------------------------- TyneBridges · 2013-03-23 14:21 Quote from: BigChimp on March 23, 2013, 06:59:01 amQuote from: JohnSaltwell on March 22, 2013, 05:40:05 pmI have hunted around to try to answer this myself, but can't find any reference to this call in the documentation or in Google searches - so, if the declaration is in a unit I haven't installed, I don't know which one. Grepping (or whatever search tool you use) through the FPC source code can work very well. The documentation certainly does not cover all units yet. If you have some more info (or just confirmation that it works), could you add a snippet here: http://wiki.lazarus.freepascal.org/Windows_Pro gramming_Tips#Code_snippets) so posterity need not do the same digging that you did.. Thanks a lot Thanks - I have now got my program to compile again thanks to the advice here. For some reason, I've always struggled with grep. I can't remember the exact options I tried, but switching to C:\Lazarus and trying it early yesterday mainly gave lots of errors listing subfolders with "Access denied" - odd, since I'm an Admin on this PC, never see that error otherwise and have User Access Control switched off. ---------------------------------------------------------------------- TyneBridges · 2013-03-23 15:37 Quote from: theo on March 23, 2013, 12:58:34 pmQuote from: JohnSaltwell on March 22, 2013, 05:40:05 pmI have hunted around to try to answer this myself, but can't find any reference to this call in the documentation or in Google searches - so, if the declaration is in a unit I haven't installed, I don't know which one. A general hint: Lazarus has a wonderful but rather unknown feature: 1. Write the command (here EnumProcesses) in your code. 2. Try to compile 3. Right click on the error message in the message window 4. Select "Search identifier" 5. If necessary, select a scope 6. Lazarus will show the unit name if found. Or use the Code Browser from the "View" Menu Thanks - I did try something like that yesterday but just got "Declaration not found". Presumably that's something to do with Jedi units such as JwaPsApi being located outside the search scope...? I'll try to follow your instruction more carefully next time this occurs. ---------------------------------------------------------------------- theo · 2013-03-23 17:08 Quote from: JohnSaltwell on March 23, 2013, 04:37:19 pmThanks - I did try something like that yesterday but just got "Declaration not found". Presumably that's something to do with Jedi units such as JwaPsApi being located outside the search scope...? I'll try to follow your instruction more carefully next time this occurs. It works here even under Linux with Project Options set to TargetOS Win64.