Jump to content
PeterPanettone

Winapi.Windows.PROCESS_QUERY_LIMITED_INFORMATION not found

Recommended Posts

In my Delphi 12.2 Winapi.Windows.pas unit in Windows 11, the declaration for PROCESS_QUERY_LIMITED_INFORMATION ($1000) constant is missing. Does this mean that my Winapi.Windows.pas unit is potentially corrupted?

Edited by PeterPanettone

Share this post


Link to post
2 hours ago, PeterPanettone said:

Does this mean that my Winapi.Windows.pas unit is potentially corrupted?

Corrupted? Because of a missing declaration?

 

There are lots of stuff missing, at any given time, since new values, structures, and functions gets added to the Win32 API all the time and Embarcadero can't keep up.

 

PROCESS_QUERY_LIMITED_INFORMATION has been missing for ages. Just declare it locally and move on.

Share this post


Link to post

@PeterPanettone

If something of WinApi is missing, you can look at this and download the WINMD from getit: https://docwiki.embarcadero.com/RADStudio/Athens/en/What's_New#WinAPI_Delphi_Headers_from_WinMD_metadata

 

Like they told,

Quote

These new headers are much more extensive, covering all recent APIs compared to the set available in the core RTL.

Bye

 

P.S.:I use some of those headers to include some functionalities missing in Embarcadero WinApi.

Edited by DelphiUdIT

Share this post


Link to post

Hello DelphiUdIT,

Thanks for the hint. How would you reference PROCESS_QUERY_LIMITED_INFORMATION from WinMD?

 

I need to use it in this context:

  hProcess := Winapi.Windows.OpenProcess(
    PROCESS_QUERY_LIMITED_INFORMATION, // cannot be retrieved from Winapi.Windows
    False,
    ProcessID
  );

So I implemented it as  a local constant:

const
  {$IFNDEF PROCESS_QUERY_LIMITED_INFORMATION}
  PROCESS_QUERY_LIMITED_INFORMATION = $1000;
  {$ENDIF}

 

Share this post


Link to post

Ah, I've found it here:

 

C:\Users\<username>\Documents\Embarcadero\Studio\23.0\CatalogRepository\WindowsAPIfromWinMD-1.0\Windows.System.Threading.pas

 

Very nice!

 

Unfortunately, the GetIt installer does not add WindowsAPIfromWinMD-1.0 to the Library Path.

Edited by PeterPanettone

Share this post


Link to post
6 hours ago, PeterPanettone said:

So I implemented it as  a local constant:


const
  {$IFNDEF PROCESS_QUERY_LIMITED_INFORMATION}
  PROCESS_QUERY_LIMITED_INFORMATION = $1000;
  {$ENDIF}

 

That won't work, as PROCESS_QUERY_LIMITED_INFORMATION is not a conditional you can test with {$IFNDEF}. Use {$IF NOT DECLARED} instead:

{$IF NOT DECLARED(PROCESS_QUERY_LIMITED_INFORMATION)}
const
  PROCESS_QUERY_LIMITED_INFORMATION = $1000;
{$IFEND} 

 

Edited by Remy Lebeau

Share this post


Link to post
2 hours ago, Remy Lebeau said:

That won't work, as PROCESS_QUERY_LIMITED_INFORMATION is not a conditional you can test with {$IFNDEF}. Use {$IF NOT DECLARED} instead:


{$IF NOT DECLARED(PROCESS_QUERY_LIMITED_INFORMATION)}
const
  PROCESS_QUERY_LIMITED_INFORMATION = $1000;
{$IFEND} 

 

Hello Remy Lebeau,

 

Thank you for your answer. However, the Delphi 12.2 compiler seems to accept this as a conditional compilation:

 

image.thumb.png.2b25d550a944bb2c8abb54d17e3608ac.png

 

The code compiles without errors.

Edited by PeterPanettone

Share this post


Link to post
1 hour ago, PeterPanettone said:

Thank you for your answer. However, the Delphi 12.2 compiler seems to accept this as a conditional compilation:

 

image.thumb.png.2b25d550a944bb2c8abb54d17e3608ac.png

 

The code compiles without errors.

Edited 57 minutes ago by PeterPanettone

No, that is misuse between declaration and definition, use what Remy suggested.

 

IFDEF/IFNDEF about definition, literally defined, these are not for the code but for the compiler variables.

DECLARED()/NOT DECLARED() these about your code, namely anything that can be declared like consts, records, classes ....

 

It compile in your case because there is no defined directives (compiler directive) under that name.

 

Example:

var
  i: Integer;
  B: Integer;      // comment this and the compilation will fail
{$IF NOT DECLARED(B)}
  This should cause an error only if you comment or remove B from variables
{$IFEND}

 

Share this post


Link to post
10 hours ago, PeterPanettone said:

Unfortunately, the GetIt installer does not add WindowsAPIfromWinMD-1.0 to the Library Path.

That's fine with me, because then I copy all the units used as "uses" (NOT COMPONENTS) into the $BDSUSERDIR\Imports folder (in this case the WINMD folder)
And in the library paths I add that path (which is specific to the platform). In this way I have a single point (I repeat only for the uses, i.e. those units that represent a stand-alone functionality) under which there are all the "utilities" and that will be copied and maintained for each version of RAD STUDIO. I still have some files from almost twenty years ago that I still use (rarely, only for maintenance of old code ... with the new RAD).

"It's an ill wind that blows nobody any good" ... :classic_biggrin:

 

Bye

Share this post


Link to post
11 hours ago, Remy Lebeau said:

That won't work, as PROCESS_QUERY_LIMITED_INFORMATION is not a conditional you can test with {$IFNDEF}. Use {$IF NOT DECLARED} instead:


{$IF NOT DECLARED(PROCESS_QUERY_LIMITED_INFORMATION)}
const
  PROCESS_QUERY_LIMITED_INFORMATION = $1000;
{$IFEND}

Your code creates a compiler error:

{$IF NOT DECLARED(PROCESS_QUERY_LIMITED_INFORMATION)}// [dcc32 Error] Common.pas(382): E2070 Unknown directive: ''
const
  PROCESS_QUERY_LIMITED_INFORMATION = $1000;
{$IFEND}

 

Share this post


Link to post
29 minutes ago, PeterPanettone said:

Your code creates a compiler error:


{$IF NOT DECLARED(PROCESS_QUERY_LIMITED_INFORMATION)}// [dcc32 Error] Common.pas(382): E2070 Unknown directive: ''
const
  PROCESS_QUERY_LIMITED_INFORMATION = $1000;
{$IFEND}

 

It works perfectly fine for me exactly as I have shown it.  What version are you using?  {$IF} has been available since Delphi 6,

Edited by Remy Lebeau

Share this post


Link to post
1 hour ago, PeterPanettone said:

E2070 Unknown directive: ''

You probably copy/pasted the code from here and therefore got the looks-like-space-but-isn't Unicode characters the forum pretty-printer sometimes uses.

Type it by hand and it will most likely work.

 

Apart from that, why are you even bothering with {$if declared} at all? Just declare the constant unconditionally, FSS. It's not like you will break anything if it's already declared.

  • Like 1

Share this post


Link to post
2 hours ago, PeterPanettone said:

Delphi 12.2.

Wow, what a coincidence, so am I :classic_biggrin: And what I showed works just fine in 12.2.

Share this post


Link to post
2 minutes ago, Remy Lebeau said:

Wow, what a coincidence, so am I :classic_biggrin: And what I showed works just fine in 12.2.

This is indeed very strange. I have also discovered that when I use my previous code version:

const
  {$IFNDEF PROCESS_QUERY_LIMITED_INFORMATION} 
  PROCESS_QUERY_LIMITED_INFORMATION = $1000;
  {$ENDIF}

...then I can compile/build my app, but when I run it from the IDE, I get F2084 Internal Error: AV50A9A35E(509E0000)-R00000000-0 shown in the Structure view (without affecting my app at runtime). So I now simply declare the variable without any compiler conditionals, which resolves all compiler problems.

Share this post


Link to post
2 hours ago, PeterPanettone said:

when I use my previous code version:


const
  {$IFNDEF PROCESS_QUERY_LIMITED_INFORMATION} 
  PROCESS_QUERY_LIMITED_INFORMATION = $1000;
  {$ENDIF}

...then I can compile/build my app

It will compile, but it won't behave as you are expecting.

 

PROCESS_QUERY_LIMITED_INFORMATION is not a compiler conditional via a {$DEFINE} statement, "-D" compiler switch, or "Conditional Defines" list in the project options, thus:

{$IFDEF PROCESS_QUERY_LIMITED_INFORMATION}  // will always evaluate as false
{$IFNDEF PROCESS_QUERY_LIMITED_INFORMATION} // will always evaluate as true

Regardless of whether PROCESS_QUERY_LIMITED_INFORMATION has been declared as a constant in a unit that your code uses.

 

That is where {$IF (NOT) DECLARED} comes into play, as it supports declarations of types, constants, variables, etc.  Not to be confused with {$IF (NOT) DEFINED}, which is the {$IF} version of {$IF(N)DEF} and thus supports only compiler conditionals.

const
  PROCESS_QUERY_LIMITED_INFORMATION = $1000;

{$IF DECLARED(PROCESS_QUERY_LIMITED_INFORMATION)}     // will evaluate as true
{$IF NOT DECLARED(PROCESS_QUERY_LIMITED_INFORMATION)} // will evaluate as false

{$IF DECLARED(PROCESS_QUERY_DOESNT_EXIST)}     // will evaluate as false
{$IF NOT DECLARED(PROCESS_QUERY_DOESNT_EXIST)} // will evaluate as true
2 hours ago, PeterPanettone said:

but when I run it from the IDE, I get F2084 Internal Error: AV50A9A35E(509E0000)-R00000000-0 shown in the Structure view (without affecting my app at runtime).

That is a compiler/IDE bug that would need to be reported, with example to reproduce it.  I don't get that error in my tests.

2 hours ago, PeterPanettone said:

So I now simply declare the variable without any compiler conditionals, which resolves all compiler problems.

Sure, though you would be using your own constant declared in your own unit, and not using a constant declared in the Winapi.Windows unit if Embarcadero ever decides to add it in at a later time.

Edited by Remy Lebeau
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×