Delphi: Declaration of LONG_PTR, WNDPROC
Can you please tell me HOW the following symbols are declared in Windows.pas for newer Delphi versions?
- LONG_PTR = ?
- WNDPROC = ?
I want that my code is compatible with Delphi 2006 and I do not just want to write "Integer" or "Pointer", instead the "correct" and official declaration.
Can you please also tell me in which Delphi version the functions
- GetWindowLongPtr
- SetWindowLongPtr
were officially added? (According to http://qc.embarcadero.com/wc/qcmain.aspx?d=48771 it seems that in Delphi 11 (2007) t开发者_如何学Pythonhis issue was active and in Delphi 12 (2009) the issue was solved)
When working with VCL controls (TControl
descendants which includes TCustomForm
) you don't have to use the SetWindowLongPtr
API to replace the window procedure; you can set WindowProc
property to achieve the same result. I've posted an example here.
GetWindowLongPtr and SetWindowLongPtr both appear in the windows unit of Delphi 2009 (version 12 of the compiler).
{$EXTERNALSYM GetWindowLongPtr}
function GetWindowLongPtr(hWnd: HWND; nIndex: Integer): LONG_PTR; stdcall;
{$EXTERNALSYM SetWindowLongPtr}
function SetWindowLongPtr(hWnd: HWND; nIndex: Integer; dwNewLong: LONG_PTR): LONG_PTR; stdcall;
The Ansi and Wide versions of the API are also declared, although there is no difference except in name and calls aren't diverted like with many other API functions where the "unadorned" version of a MyApiFunction is redirected to either the MyApiFunctionA (pre D2009) or the MyApiFunctionW (D2009+) function. As in:
function MyApiFunction; external advapi32 name 'MyApiFunctionW';
function MyApiFunctionA; external advapi32 name 'MyApiFunctionA';
function MyApiFunctionW; external advapi32 name 'MyApiFunctionW';
If D2006 doesn't define them as @Frank Shearer says, and the issue was open in QC for D2007 and closed for version 12 (D200(), I guess D2009 is indeed the version in which these declaration were added.
Please note that you can always add the declaration of a Windows API yourself if it isn't provided by the Delphi version you are using. And as always with API functions it is wise to know from which Windows version on they exist so you don't call API's that do not exist on the platform on which your program is running.
I don't know the exact version that introduced Get/SetWindowLongPtr, but Delphi 2006 doesn't define either.
The below declarations all come from Delphi 2006.
WNDPROC's probably a TFNWndProc, in Windows.pas:
TFarProc = Pointer;
TFNWndProc = TFarProc;
Classes.pas' StdWndProc's signature looks like this in Delphi 2006:
function StdWndProc(Window: HWND; Message, WParam: Longint;
LParam: Longint): Longint; stdcall; assembler;
MSHTML.pas defines LONG_PTR as:
LONG_PTR = Integer;
This definition is the only mention of LONG_PTR
in Delphi 2006's source directory.
精彩评论