listplug.pas - corrected version

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

listplug.pas - corrected version

Post by *MarcinW »

I downloaded "WCX Plugin Guide 2.21se" from http://www.ghisler.com/plugins.htm. There is a "listplugin.hlp" file inside, which in chapter "7. Header files" contains listing of "listplug.pas". I found some problems with this file and I corrected them, so I attached the corrected file below.

@ghisler(Author): feel free to use this modified code if you want.


Here is the list of changes. Thanks to these changes, "listplug.pas" works properly also with modern Delphi versions, and is also coherent with "listplug.h":

1) Modern Delphi versions, starting from Delphi 2009, use unicode chars and strings by default, so they map "Char" to "WideChar" and "PChar" to "PWideChar". But we need to have ANSI statements there, so I explicitly changed "Char" to "AnsiChar" and "PChar" to "PAnsiChar". Without this change the code could be compiled, but wouldn't work properly.

2) I added "uses Windows" - without this the file couldn't be compiled.

3) I replaced :

Code: Select all

{$ifdef win64}
function ListNotificationReceived(ListWin:thandle;Message:integer;wParam:WPARAM;lParam:LPARAM):integer; stdcall;
{$else}
ListNotificationReceived(ListWin:thandle;Message:integer;wParam,lParam:integer):integer; stdcall;
{$endif}
with:

Code: Select all

function ListNotificationReceived(ListWin:thandle;Message:integer;wParam:WPARAM;lParam:LPARAM):integer; stdcall;
In 32-bit Delphi, WPARAM and LPARAM are mapped to Longint, which is identical to Integer, so two variants of the declaration are in fact needless. One definition is simpler, and also without this change file couldn't be compiled - {$ifdef win64} has been treated as the end of another, most outer comment, so {$else} has been reported as an invalid directive.

4) To be coherent with "listplug.h", I changed "THandle" to "HWND" in all places. "THandle" and "HWND" have same size and in most cases are compatible each other (in particular in this code), so this change shouldn't cause any problems.

5) To be coherent with "listplug.h", I corrected field types in "tListDefaultParamStruct" record - "size" became "Integer", and "PluginInterfaceVersionLow" and "PluginInterfaceVersionHi" became "Cardinal".

6) To avoid potential problems with $ALIGN compiler directive, I added "packed" to the definition of "tListDefaultParamStruct" type and also to the "DefaultIniName" buffer inside.

7) I changed case of type definitions, to be coherent with Delphi definitions - for example "integer" to "Integer" and "hbitmap" to "HBITMAP".

8) Finally I inserted some spaces, so the code is more readable.


Here is the modified code:

Code: Select all

unit listplug; { Contents of file listplug.pas }

interface

uses
  Windows;

const
  lc_copy = 1;
  lc_newparams = 2;
  lc_selectall = 3;
  lc_setpercent = 4;

  lcp_wraptext = 1;
  lcp_fittowindow = 2;
  lcp_ansi = 4;
  lcp_ascii = 8;
  lcp_variable = 12;
  lcp_forceshow = 16;
  lcp_fitlargeronly = 32;
  lcp_center = 64;

  lcs_findfirst = 1;
  lcs_matchcase = 2;
  lcs_wholewords = 4;
  lcs_backwards = 8;

  itm_percent = $FFFE;
  itm_fontstyle = $FFFD;
  itm_wrap = $FFFC;
  itm_fit = $FFFB;
  itm_next = $FFFA;
  itm_center = $FFF9;

  LISTPLUGIN_OK = 0;
  LISTPLUGIN_ERROR = 1;

type
  tListDefaultParamStruct = packed record
    size : Integer;
    PluginInterfaceVersionLow : Cardinal;
    PluginInterfaceVersionHi : Cardinal;
    DefaultIniName : packed array[0..MAX_PATH-1] of AnsiChar;
  end;
  pListDefaultParamStruct = ^tListDefaultParamStruct;

{ Function prototypes: Functions need to be defined exactly like this!}
{
function ListLoad(ParentWin : HWND; FileToLoad : PAnsiChar; ShowFlags : Integer) : HWND; stdcall;
function ListLoadW(ParentWin : HWND; FileToLoad : PWideChar; ShowFlags : Integer) : HWND; stdcall;
function ListLoadNext(ParentWin, PluginWin : HWND; FileToLoad : PAnsiChar; ShowFlags : Integer) : Integer; stdcall;
function ListLoadNextW(ParentWin, PluginWin : HWND; FileToLoad : PWideChar; ShowFlags : Integer) : Integer; stdcall;
procedure ListCloseWindow(ListWin : HWND); stdcall;
procedure ListGetDetectString(DetectString : PAnsiChar; maxlen : Integer); stdcall;
function ListSearchText(ListWin : HWND; SearchString : PAnsiChar;
                        SearchParameter : Integer) : Integer; stdcall;
function ListSearchTextW(ListWin : HWND; SearchString : PWideChar;
                        SearchParameter : Integer) : Integer; stdcall;
function ListSearchDialog(ListWin : HWND; FindNext : Integer) : Integer; stdcall;
function ListSendCommand(ListWin : HWND; Command, Parameter : Integer) : Integer; stdcall;
function ListPrint(ListWin : HWND; FileToPrint, DefPrinter : PAnsiChar;
                   PrintFlags : Integer; var Margins : TRect) : Integer; stdcall;
function ListPrintW(ListWin : HWND; FileToPrint, DefPrinter : PWideChar;
                   PrintFlags : Integer; var Margins : TRect) : Integer; stdcall;
function ListNotificationReceived(ListWin : HWND; Message : Integer; wParam : WPARAM; lParam : LPARAM) : Integer; stdcall;
procedure ListSetDefaultParams(dps : pListDefaultParamStruct); stdcall;
function ListGetPreviewBitmap(FileToLoad : PAnsiChar; width, height : Integer;
    contentbuf : PAnsiChar; contentbuflen : Integer) : HBITMAP; stdcall;
function ListGetPreviewBitmapW(FileToLoad : PWideChar; width, height : Integer;
    contentbuf : PAnsiChar; contentbuflen : Integer) : HBITMAP; stdcall;
}

implementation
end.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50475
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

For which Delphi version are your changes? In older versions,you couldn't have a parameter with the same name as a file type (e.g. WPARAM).
Author of Total Commander
https://www.ghisler.com
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

These changes can be used even with Delphi 2. The problem with declarations like "wParam : WPARAM" is only in case of nested declarations, but can be easily solved by changing "WPARAM" to "Windows.WPARAM" (or another appropriate unit name in place of "Windows"). The example below compiles with Delphi 2:

Code: Select all

function Test(wParam : WPARAM) : WPARAM;

  function Test2(wParam : Windows.WPARAM) : Windows.WPARAM;
  begin
    Result:=wParam*2;
  end;

begin
  Result:=Test2(wParam);
end;
Regards
Post Reply