我正在尝试创建一个简单的WCX插件的总指挥官。
我从这里下载了wcxhead.pas (在帮助文件中):http://ghisler.fileburst.com/plugins/wcx_ref2.21se_chm.zip
这是链接到这里的官方文件:https://www.ghisler.com/plugins.htm
并创建了我自己的DLL:
library TST;
uses
Windows,
SysUtils,
Classes,
wcxhead;
{$E wcx}
var Num: Integer;
function OpenArchive (var ArchiveData: tOpenArchiveData): THANDLE; stdcall;
begin
Result := 99999;
Num := 0;
end;
function ReadHeader(hArcData: THANDLE; var HeaderData: tHeaderData): Integer; stdcall;
begin
with HeaderData do begin
FileName := 'my_file.ext';
PackSize := 1000;
UnpSize := 2000;
FileTime := 1876543;
FileAttr := $3F;
end;
if Num < 1 then Result := 0
else Result := E_END_ARCHIVE;
Inc(Num);
end;
function ProcessFile(hArcData: THANDLE; Operation: Integer; DestPath: PChar; DestName: PChar): Integer; stdcall;
begin
Result := 0;
end;
function CloseArchive(hArcData: THANDLE): Integer; stdcall;
begin
Result := 0;
end;
procedure SetChangeVolProc(hArcData: THANDLE; pChangeVolProc1: tChangeVolProc);stdcall;
begin
//
end;
procedure SetProcessDataProc(hArcData: THANDLE; pProcessDataProc: tProcessDataProc); stdcall;
begin
//
end;
exports
OpenArchive, ReadHeader, ProcessFile, CloseArchive, SetChangeVolProc, SetProcessDataProc;
end.这是wcxhead.pas
unit wcxhead;
interface
const {Error codes returned to calling application}
E_END_ARCHIVE= 10; {No more files in archive}
E_NO_MEMORY= 11; {Not enough memory}
E_BAD_DATA= 12; {CRC error in the data of the currently unpacked file}
E_BAD_ARCHIVE= 13; {The archive as a whole is bad, e.g. damaged headers}
E_UNKNOWN_FORMAT= 14; {Archive format unknown}
E_EOPEN= 15; {Cannot open existing file}
E_ECREATE= 16; {Cannot create file}
E_ECLOSE= 17; {Error closing file}
E_EREAD= 18; {Error reading from file}
E_EWRITE= 19; {Error writing to file}
E_SMALL_BUF= 20; {Buffer too small}
E_EABORTED= 21; {Function aborted by user}
E_NO_FILES= 22; {No files found}
E_TOO_MANY_FILES= 23; {Too many files to pack}
E_NOT_SUPPORTED= 24; {Function not supported}
{Unpacking flags}
PK_OM_LIST= 0;
PK_OM_EXTRACT= 1;
{Flags for ProcessFile}
PK_SKIP= 0; {Skip file (no unpacking)}
PK_TEST= 1; {Test file integrity}
PK_EXTRACT= 2; {Extract file to disk}
{Flags passed through ChangeVolProc}
PK_VOL_ASK= 0; {Ask user for location of next volume}
PK_VOL_NOTIFY= 1; {Notify app that next volume will be unpacked}
{Packing flags}
{For PackFiles}
PK_PACK_MOVE_FILES= 1; {Delete original after packing}
PK_PACK_SAVE_PATHS= 2; {Save path names of files}
PK_PACK_ENCRYPT= 4; {Ask user for password, then encrypt}
{Returned by GetPackCaps}
PK_CAPS_NEW= 1; {Can create new archives}
PK_CAPS_MODIFY= 2; {Can modify exisiting archives}
PK_CAPS_MULTIPLE= 4; {Archive can contain multiple files}
PK_CAPS_DELETE= 8; {Can delete files}
PK_CAPS_OPTIONS= 16; {Supports the options dialogbox}
PK_CAPS_MEMPACK= 32; {Supports packing in memory}
PK_CAPS_BY_CONTENT= 64; {Detect archive type by content}
PK_CAPS_SEARCHTEXT= 128; {Allow searching for text in archives
{ created with this plugin}
PK_CAPS_HIDE= 256; { Show as normal files (hide packer icon) }
{ open with Ctrl+PgDn, not Enter }
PK_CAPS_ENCRYPT= 512; { Plugin supports PK_PACK_ENCRYPT option }
BACKGROUND_UNPACK=1; { Which operations are thread-safe? }
BACKGROUND_PACK=2;
BACKGROUND_MEMPACK=4; { For tar.pluginext in background }
{Flags for packing in memory}
MEM_OPTIONS_WANTHEADERS=1; {Return archive headers with packed data}
{Errors returned by PackToMem}
MEMPACK_OK= 0; {Function call finished OK, but there is more data}
MEMPACK_DONE= 1; {Function call finished OK, there is no more data}
{Flags for PkCryptProc callback}
PK_CRYPT_SAVE_PASSWORD=1;
PK_CRYPT_LOAD_PASSWORD=2;
PK_CRYPT_LOAD_PASSWORD_NO_UI=3; { Load password only if master password has already been entered!}
PK_CRYPT_COPY_PASSWORD=4; { Copy encrypted password to new archive name}
PK_CRYPT_MOVE_PASSWORD=5; { Move password when renaming an archive}
PK_CRYPT_DELETE_PASSWORD=6; { Delete password}
PK_CRYPTOPT_MASTERPASS_SET = 1; // The user already has a master password defined
type
{Definition of callback functions called by the DLL}
{Ask to swap disk for multi-volume archive}
PChangeVolProc=^TChangeVolProc;
TChangeVolProc=function(ArcName:pchar;Mode:longint):longint; stdcall;
PChangeVolProcW=^TChangeVolProcW;
TChangeVolProcW=function(ArcName:pwidechar;Mode:longint):longint; stdcall;
{Notify that data is processed - used for progress dialog}
PProcessDataProc=^TProcessDataProc;
TProcessDataProc=function(FileName:pchar;Size:longint):longint; stdcall;
PProcessDataProcW=^TProcessDataProcW;
TProcessDataProcW=function(FileName:pwidechar;Size:longint):longint; stdcall;
PPkPluginCryptProc=^TPkPluginCryptProc;
TPkPluginCryptProc=function(CryptoNr:integer;mode:integer;ArchiveName,
Password:pchar;maxlen:integer):integer; stdcall;
PPkPluginCryptProcW=^TPkPluginCryptProcW;
TPkPluginCryptProcW=function(CryptoNr:integer;mode:integer;ArchiveName,
Password:pwidechar;maxlen:integer):integer; stdcall;
type
THeaderData=packed record
ArcName:array [0..259] of char;
FileName:array [0..259] of char;
Flags,
PackSize,
UnpSize,
HostOS,
FileCRC,
FileTime,
UnpVer,
Method,
FileAttr:longint;
CmtBuf:pchar;
CmtBufSize,
CmtSize,
CmtState:longint;
end;
THeaderDataEx=packed record
ArcName:array [0..1023] of char;
FileName:array [0..1023] of char;
Flags:longint;
PackSize,
PackSizeHigh,
UnpSize,
UnpSizeHigh: Cardinal;
HostOS,
FileCRC,
FileTime,
UnpVer,
Method,
FileAttr:longint;
CmtBuf:pchar;
CmtBufSize,
CmtSize,
CmtState:longint;
Reserved:array[0..1023] of char;
end;
THeaderDataExW=packed record
ArcName:array [0..1023] of widechar;
FileName:array [0..1023] of widechar;
Flags:longint;
PackSize,
PackSizeHigh,
UnpSize,
UnpSizeHigh: Cardinal;
HostOS,
FileCRC,
FileTime,
UnpVer,
Method,
FileAttr:longint;
CmtBuf:pchar;
CmtBufSize,
CmtSize,
CmtState:longint;
Reserved:array[0..1023] of char;
end;
tOpenArchiveData=packed record
ArcName:pchar;
OpenMode,
OpenResult:longint;
CmtBuf:pchar;
CmtBufSize,
CmtSize,
CmtState:longint;
end;
tOpenArchiveDataW=packed record
ArcName:pwidechar;
OpenMode,
OpenResult:longint;
CmtBuf:pwidechar;
CmtBufSize,
CmtSize,
CmtState:longint;
end;
tPackDefaultParamStruct=record
size,
PluginInterfaceVersionLow,
PluginInterfaceVersionHi:longint;
DefaultIniName:array[0..259] of char;
end;
pPackDefaultParamStruct=^tPackDefaultParamStruct;
implementation
end.我把这个插件安装在Total Commander里了。现在,总指挥官打开我的.TST文件,但没有显示任何文件。它应该显示"my_file.ext“。
我甚至找到了一个简单的WCX插件,但我看不出我的代码在重要方面有什么不同:https://github.com/ypid-bot/doublecmd/blob/master/plugins/wcx/unbz2/src/bz2func.pas
发布于 2020-01-16 00:09:18
好了,问题来了($3F表示“任何文件”):
FileAttr := $3F;它应该是(0表示"A文件“):
FileAttr := 0;发布于 2020-01-15 23:46:13
这个头文件显然是从Unicode之前的Delphi时间创建的。它假设char = AnsiChar,但从Delphi2009开始就不是这样了。
从论坛上看,TotalCommander 32位仍然是用Delphi2或Delphi3编译的,有很多自定义的RTL,以保持它的小巧和高效。
如果您使用的是Unicode版本的Delphi,请尝试将char更改为AnsiChar,并使用支持Unicode的*W()导出。
此外,不要使用全局变量来维护打包程序访问的状态:您应该使用THandle值来打开/关闭给定的归档文件。可以同时打开两个档案。
编辑:由于您使用的是Delphi 7,因此这不是Unicode问题。但我会试着
strpcopy(filename,'my_file.ext');https://stackoverflow.com/questions/59754726
复制相似问题