Recent

Author Topic: GetFileSizeEx function missing  (Read 1016 times)

440bx

  • Hero Member
  • *****
  • Posts: 4749
GetFileSizeEx function missing
« on: November 06, 2024, 10:13:02 am »
Hello,

The definition of GetFileSizeEx is missing in Windows.pas.

Possible definitions:
Code: Pascal  [Select][+][-]
  1. const
  2.   kernel32 = 'kernel32';
  3.  
  4. { missing definitions                                                         }
  5.  
  6. function GetFileSizeEx
  7.            (
  8.             InFileHandle : THANDLE;
  9.             OutFileSize  : PLARGE_INTEGER
  10.            )
  11.          : BOOL; stdcall; external kernel32;   { no need to specify the name  }
  12.  
  13.  
  14. function GetFileSizeEx
  15.            (
  16.             InFileHandle : THANDLE;
  17.             OutFileSize  : pint64
  18.            )
  19.          : BOOL; stdcall; external kernel32; overload;
  20.  
  21.  
The first definition mirrors the MSDN definition exactly (except the parameter names which are of no relevance.)  The second one would be a "nice to have" overload since FPC supports 64 bit integers without having to resort to the LARGE_INTEGER structure.

Two more overloads are possible using "var" to eliminate the need for pass a pointer to either function.

ETA:

forgot to mention, this applies to FPC v3.2.2.  I don't know if the definition has already been added in an upcoming version.
« Last Edit: November 06, 2024, 10:15:13 am by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: GetFileSizeEx function missing
« Reply #1 on: November 06, 2024, 10:28:29 am »
function is available in FPC 3.2.2 - attach JwaWinBase unit to uses section
Best regards / Pozdrawiam
paweld

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: GetFileSizeEx function missing
« Reply #2 on: November 06, 2024, 11:15:10 am »
Or simply jwaWindows which solves more than that problem.
And yes, It can be replaced with var, but you have to convince Marcov and I did not succeed in doing that in the past odd 20 years or so.
Just that the API can not express var. The - OLD - Delphi developers were a bit more analytic about those calls and made them safe from the start.
« Last Edit: November 06, 2024, 11:17:48 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

440bx

  • Hero Member
  • *****
  • Posts: 4749
Re: GetFileSizeEx function missing
« Reply #3 on: November 06, 2024, 11:15:59 am »
function is available in FPC 3.2.2 - attach JwaWinBase unit to uses section
I know that but, that should not be necessary.  GetFileSizeEx is documented and defined in kernel32 which is a "bread and butter" dll.  For that reason it should not be necessary to include some other unit/file to access a very common API.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: GetFileSizeEx function missing
« Reply #4 on: November 06, 2024, 11:18:30 am »
Posts crossed, was editting...
(Marcov did provide a compat unit, btw, so I do not blame him for everything)
« Last Edit: November 06, 2024, 11:21:18 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

440bx

  • Hero Member
  • *****
  • Posts: 4749
Re: GetFileSizeEx function missing
« Reply #5 on: November 06, 2024, 11:27:02 am »
(Marcov did provide a compat unit, btw, so I do not blame him for everything)
Just for the record, I'm not blaming anybody for anything.

I would just like to see that function included in the Windows unit because it is a common, documented and often used function.  That's all, no more, no less.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

AlexTP

  • Hero Member
  • *****
  • Posts: 2488
    • UVviewsoft
Re: GetFileSizeEx function missing
« Reply #6 on: November 06, 2024, 11:33:48 am »

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: GetFileSizeEx function missing
« Reply #7 on: November 06, 2024, 11:36:47 am »
It was a light harted remark that Marcov understands.
« Last Edit: November 06, 2024, 02:48:55 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

440bx

  • Hero Member
  • *****
  • Posts: 4749
Re: GetFileSizeEx function missing
« Reply #8 on: November 06, 2024, 11:37:54 am »
Thank you Alex.

I was going to wait for @marcov's view on the matter but, as you have probably noticed, I do believe it should be included in the Windows unit.



@Thaddy, ok, no harm done.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: GetFileSizeEx function missing
« Reply #9 on: November 06, 2024, 02:56:37 pm »
Knowing Marcov a bit he possibly add it to the compat unit.
If I smell bad code it usually is bad code and that includes my own code.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11947
  • FPC developer.
Re: GetFileSizeEx function missing
« Reply #10 on: November 06, 2024, 04:52:33 pm »
Done. redef.inc  with special overloads is just an include file, not an unit btw. 440bx probably knows since he is a regular submitter of windows unit issues.

Note that recommending jwa* should be clearly marked as temporary solution. I'm not sure how 64-bit ready the JWA* units  are.

440bx

  • Hero Member
  • *****
  • Posts: 4749
Re: GetFileSizeEx function missing
« Reply #11 on: November 06, 2024, 05:14:49 pm »
Done.
Thank you Marco.

Note that recommending jwa* should be clearly marked as temporary solution. I'm not sure how 64-bit ready the JWA* units  are.
and in addition to that, I've seen a few errors in the definitions of ntdll functions.  I should have reported those but, I was focused on something else then forgot and now I don't remember which functions.  I do remember that a fair number of them were in definitions of functions in ntdll (some documented, some not.)  The same for internal Windows structures, a fair number of them have not been updated to reflect more recent versions of Windows.

Personally, I'd recommend leaving the Jwa* definitions alone.  They were probably fine at one time but, I think that now they are outdated and, as a result, a bit risky to use.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: GetFileSizeEx function missing
« Reply #12 on: November 06, 2024, 05:34:57 pm »
Tnx Marco, also for the fix.
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018