Recent

Author Topic: [Solved] Enumprocesses in Windows API not supported?  (Read 12749 times)

TyneBridges

  • Full Member
  • ***
  • Posts: 143
    • Personal blog
[Solved] Enumprocesses in Windows API not supported?
« on: March 22, 2013, 05:40:05 pm »
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.
« Last Edit: March 23, 2013, 04:30:44 pm by JohnSaltwell »
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

Deepaak

  • Sr. Member
  • ****
  • Posts: 445
Re: Enumprocesses in Windows API not supported?
« Reply #1 on: March 22, 2013, 08:00:23 pm »
have you tried including

JwaWindows in your unit section
Holiday season is online now. :-)

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Enumprocesses in Windows API not supported?
« Reply #2 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).

Chronos

  • Full Member
  • ***
  • Posts: 214
    • PascalClassLibrary
Re: Enumprocesses in Windows API not supported?
« Reply #3 on: March 22, 2013, 08:50:16 pm »
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

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Enumprocesses in Windows API not supported?
« Reply #4 on: March 23, 2013, 06:59:01 am »
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.

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_Programming_Tips#Code_snippets) so posterity need not do the same digging that you did...

Thanks a lot ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Deepaak

  • Sr. Member
  • ****
  • Posts: 445
Re: Enumprocesses in Windows API not supported?
« Reply #5 on: March 23, 2013, 08:30:20 am »

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;
Holiday season is online now. :-)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Enumprocesses in Windows API not supported?
« Reply #6 on: March 23, 2013, 08:56:30 am »

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';
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: Enumprocesses in Windows API not supported?
« Reply #7 on: March 23, 2013, 12:58:34 pm »
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.

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
« Last Edit: March 23, 2013, 01:00:22 pm by theo »

TyneBridges

  • Full Member
  • ***
  • Posts: 143
    • Personal blog
Re: Enumprocesses in Windows API not supported?
« Reply #8 on: March 23, 2013, 03:21:53 pm »
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.

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_Programming_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.
« Last Edit: March 23, 2013, 04:36:38 pm by JohnSaltwell »
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

TyneBridges

  • Full Member
  • ***
  • Posts: 143
    • Personal blog
Re: Enumprocesses in Windows API not supported?
« Reply #9 on: March 23, 2013, 04:37:19 pm »
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.

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.
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: [Solved] Enumprocesses in Windows API not supported?
« Reply #10 on: March 23, 2013, 06:08:46 pm »
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.

It works here even under Linux with Project Options set to TargetOS Win64.

 

TinyPortal © 2005-2018