浏览代码

Workaround stdcall issue. Not yet finished so also not yet tested.

Martijn Laan 11 月之前
父节点
当前提交
144a32834c

+ 10 - 4
Projects/Src/Compression.SevenZipDecoder.pas

@@ -20,16 +20,22 @@ implementation
 uses
   Windows, SysUtils, Setup.LoggingFunc;
 
-{ Compiled by Embarcadero C++ 7.30 2022 using compile-bcc32c.bat
-  For Visual Studio use compile.bat and define VISUALSTUDIO below but currently this gives linker errors in Delphi }
+{ Compiled by Visual Studio 2022 using compile.bat
+  To enable source debugging recompile using compile-bcc32c.bat and turn off the VISUALSTUDIO define below
+  Note that in a speed test the code produced by bcc32c was about 33% slower }
 {$L Src\Compression.SevenZipDecoder\7zDecode\IS7zDec.obj}
+{$DEFINE VISUALSTUDIO}
 
 function IS_7zDec(const fileName: PChar; const fullPaths: Bool): Integer; cdecl; external name '_IS_7zDec';
 
-{.$DEFINE VISUALSTUDIO}
-
 //https://github.com/rust-lang/compiler-builtins/issues/403
 {$IFDEF VISUALSTUDIO}
+function __CreateDirectoryW(lpPathName: LPCWSTR;
+  lpSecurityAttributes: PSecurityAttributes): BOOL; cdecl;
+begin
+  Result := CreateDirectoryW(lpPathName, lpSecurityAttributes);
+end;
+
 procedure __allshl; register; external 'ntdll.dll' name '_allshl';
 procedure __aullshr; register; external 'ntdll.dll' name '_aullshr';
 {$ELSE}

+ 16 - 0
Projects/Src/Compression.SevenZipDecoder/7zDecode/IS7zDec.c

@@ -3,6 +3,22 @@
   This file is public domain (like the LZMA SDK)
 */
 
+#ifdef _MSC_VER
+
+/* Stop 7-Zip from using stdcall functions which will get unavoidable decorated names from
+   MSVC's cl.exe which Delphi can't handle: first include windows.h and then hide the
+   functions 7-Zip wants to use with macros pointing to cdecl prototypes. This will enable
+   is us to call the stdcall function from a cdecl implementation in Delphi and keeps the
+   rest of windows.h available to 7-Zip. */
+
+#include "../../../../Components/Lzma2/Util/7z/Precomp.h" /* Says it must be included first */
+#include "../../../../Components/Lzma2/7zWindows.h"
+
+BOOL _CreateDirectoryW(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
+#define CreateDirectoryW _CreateDirectoryW
+
+#endif
+
 #include "../../../../Components/Lzma2/Util/7z/7zMain.c"
 
 #include "../../../../Components/Lzma2/7zAlloc.c"

二进制
Projects/Src/Compression.SevenZipDecoder/7zDecode/IS7zDec.obj


+ 1 - 1
README.md

@@ -214,7 +214,7 @@ Compiled by Visual Studio 2022 from the [Projects\Src\Compression.LZMADecompress
 Compiled by Visual Studio 2022 from the [Projects\Src\Compression.LZMA1SmallDecompressor\LzmaDecode] directory.
 
 **Projects\Src\Compression.SevenZipDecoder\7zDecode\IS7zDec.obj** -
-Compiled by Embarcadero C++ 7.30 from the [Projects\Src\Compression.SevenZipDecoder\7zDecode] directory.
+Compiled by Visual Studio 2022 from the [Projects\Src\Compression.SevenZipDecoder\7zDecode] directory.
 
 **Examples\MyProg.exe**, **Examples\MyProg-x64.exe**, **Examples\MyProg-Arm64.exe** -
 Compiled by Visual Studio 2022 from the [Examples\MyProg] directory.