tags:

views:

202

answers:

1

The MSDN documentation for SetFileInformationByHandle refers to "FileExtd.lib on Windows Server 2003 and Windows XP". I managed to track down the library and .h file, which is available to download as the "Win32 FileID APIs 1.1" from:

http://www.microsoft.com/downloads/details.aspx?FamilyID=1DECC547-AB00-4963-A360-E4130EC079B8&displaylang=en

It appears the implementation is in the static .lib file - how can this be referenced/linked to a Delphi app? Is my only option to create a "C Dll" in Visual Studio and export the functions? And has anyone ported the .h file to Delphi header definitions?

+3  A: 

C and C++ use lib files to provide the "stub" that the linker can use for a DLL function. The actual function implementation is in the DLL. Delphi doesn't use lib files; its external directive accomplishes the same thing. Therefore, you can usually ignore the "library" requirement in MSDN. The "DLL" requirement is still valid, though.

If the units that come with Delphi don't include an API function you want, then you have a couple of options:

  • Find someone else's code that declares it for you. A frequent candidate is the Jedi API units.

  • Declare it yourself.

    interface
    function SetFileInformationByHandle(
      hFile: THandle;
      FileInformationClass: TFileInfoByHandleClass;
      lpFileInformation: Pointer;
      dwBufferSize: DWord
    ): Bool; stdcall;
    
    
    implementation
    function SetFileInformationByHandle; external 'kernel32';
    

    I don't know whether TFileInfoByHandleClass is already declared somewhere; you might need to declare that, too. MSDN includes function declarations, but sometimes lacks associated enum and constant values, so it's handy to have the Platform SDK headers nearby (so the download link in your question isn't totally useless).

Rob Kennedy
Since SetFileInformationByHandle() is only available on W2K3 and XP onwards, you will have to use LoadLibrary() and GetProcAddress() for run-time binding, instead of the 'external' keyword for compile-time binding, if you need to support older OS versions.
Remy Lebeau - TeamB
tikinoa
In XP/2003, SetFileInformationByHandle() does not exist in kernel32.dll at all, so you cannot import it from that DLL. You are correct that it is implemented inside of FileExtd.lib for XP/2003, however AFAIK you cannot use that lib with Delphi at all, as it is not compatible with the compiler (static-link .lib files are compiler-specific).
Remy Lebeau - TeamB