rikyoz / bit7z

A C++ static library offering a clean and simple interface to the 7-zip shared libraries.
https://rikyoz.github.io/bit7z
Mozilla Public License 2.0
623 stars 113 forks source link

Correct form of function used #31

Closed CruiseYoung closed 4 years ago

CruiseYoung commented 4 years ago

Description

Motivation and Context

How Has This Been Tested?

Types of changes

Checklist:

rikyoz commented 4 years ago

Hi! Thank you for your pull request! I've seen your changes but I can't figure out exactly what bugs you are trying to fix.

Changing the WinAPI calls to the Unicode variants is not needed: since the macros UNICODE/_UNICODE are defined by default, each call expands automatically to their respective Unicode variant, e.g. LoadLibrary becomes LoadLibraryW.

Yes, setting <CharacterSet> to Unicode would make the explicit defines useless, but the way it is defined now works as well.

The _7Z_VOL macro probably is not needed anymore, you are right, but I think it should remain at least for v3.1 (it is not "incorrect" as you say, it is harmless and probably useless).

In the end, I've seen that you changed the runtime library, but by default bit7z should be compiled using /MD in order to obtain smaller binaries. Obviously, you can change how you compile bit7z without any problem, but it is only a personalized configuration, not the default one.

If you are experiencing any issue with the default build settings, please let me know in order to fix them!

CruiseYoung commented 4 years ago
 bit7z.vcxproj | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bit7z.vcxproj b/bit7z.vcxproj
index 1e43a29..d6a92a2 100644
--- a/bit7z.vcxproj
+++ b/bit7z.vcxproj
@@ -89,7 +89,7 @@
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <OutputDirectory>bin\x86\</OutputDirectory>
     <ATLMinimizesCRunTimeLibraryUsage>false</ATLMinimizesCRunTimeLibraryUsage>
-    <CharacterSet>NotSet</CharacterSet>
+    <CharacterSet>MultiByte</CharacterSet>
     <ConfigurationType>StaticLibrary</ConfigurationType>
     <IntermediateDirectory>build\x86\debug\.obj\</IntermediateDirectory>
     <PrimaryOutput>bit7z_d</PrimaryOutput>
@@ -244,7 +244,7 @@
       <ExceptionHandling>Sync</ExceptionHandling>
       <ObjectFileName>$(IntDir)</ObjectFileName>
       <Optimization>Disabled</Optimization>
-      <PreprocessorDefinitions>_WINDOWS;UNICODE;_UNICODE;WIN32;_7Z_VOL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>_WINDOWS;WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <PreprocessToFile>false</PreprocessToFile>
       <SuppressStartupBanner>true</SuppressStartupBanner>
       <TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>

1>------ Build started: Project: bit7z, Configuration: Debug Win32 ------
1>bit7zlibrary.cpp
1>fsindexer.cpp
1>fsitem.cpp
1>fsutil.cpp
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(31,51): error C2664: 'DWORD GetFileAttributesA(LPCSTR)': cannot convert argument 1 from 'const _Elem *' to 'LPCSTR'
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(31,51): error C2664:         with
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(31,51): error C2664:         [
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(31,51): error C2664:             _Elem=wchar_t
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(31,51): error C2664:         ]
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(31,48): message : Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\fileapi.h(540,1): message : see declaration of 'GetFileAttributesA' (compiling source file src\fsutil.cpp)
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(35,44): error C2664: 'DWORD GetFileAttributesA(LPCSTR)': cannot convert argument 1 from 'const _Elem *' to 'LPCSTR'
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(35,44): error C2664:         with
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(35,44): error C2664:         [
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(35,44): error C2664:             _Elem=wchar_t
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(35,44): error C2664:         ]
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(35,41): message : Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\fileapi.h(540,1): message : see declaration of 'GetFileAttributesA' (compiling source file src\fsutil.cpp)
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(40,111): error C2664: 'BOOL MoveFileExA(LPCSTR,LPCSTR,DWORD)': cannot convert argument 1 from 'const _Elem *' to 'LPCSTR'
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(40,111): error C2664:         with
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(40,111): error C2664:         [
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(40,111): error C2664:             _Elem=wchar_t
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(40,111): error C2664:         ]
1>E:\Projects\third_source\bit7z\src\fsutil.cpp(40,38): message : Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winbase.h(5365,1): message : see declaration of 'MoveFileExA' (compiling source file src\fsutil.cpp)
1>E:\Projects\third_source\bit7z\src\bit7zlibrary.cpp(28,102): error C2664: 'HMODULE LoadLibraryA(LPCSTR)': cannot convert argument 1 from 'const _Elem *' to 'LPCSTR'
1>E:\Projects\third_source\bit7z\src\bit7zlibrary.cpp(28,102): error C2664:         with
1>E:\Projects\third_source\bit7z\src\bit7zlibrary.cpp(28,102): error C2664:         [
1>E:\Projects\third_source\bit7z\src\bit7zlibrary.cpp(28,102): error C2664:             _Elem=wchar_t
1>E:\Projects\third_source\bit7z\src\bit7zlibrary.cpp(28,102): error C2664:         ]
1>E:\Projects\third_source\bit7z\src\bit7zlibrary.cpp(28,99): message : Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winbase.h(3179,1): message : see declaration of 'LoadLibraryA' (compiling source file src\bit7zlibrary.cpp)
1>E:\Projects\third_source\bit7z\src\fsitem.cpp(50,67): error C2664: 'HANDLE FindFirstFileA(LPCSTR,LPWIN32_FIND_DATAA)': cannot convert argument 1 from 'const _Elem *' to 'LPCSTR'
1>E:\Projects\third_source\bit7z\src\fsitem.cpp(50,67): error C2664:         with
1>E:\Projects\third_source\bit7z\src\fsitem.cpp(50,67): error C2664:         [
1>E:\Projects\third_source\bit7z\src\fsitem.cpp(50,67): error C2664:             _Elem=wchar_t
1>E:\Projects\third_source\bit7z\src\fsitem.cpp(50,67): error C2664:         ]
1>E:\Projects\third_source\bit7z\src\fsitem.cpp(50,52): message : Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\fileapi.h(280,1): message : see declaration of 'FindFirstFileA' (compiling source file src\fsitem.cpp)
1>E:\Projects\third_source\bit7z\src\fsitem.cpp(96,63): error C2440: 'static_cast': cannot convert from 'const CHAR [260]' to 'const wchar_t *'
1>E:\Projects\third_source\bit7z\src\fsitem.cpp(96,12): message : Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>E:\Projects\third_source\bit7z\src\fsindexer.cpp(44,64): error C2664: 'HANDLE FindFirstFileA(LPCSTR,LPWIN32_FIND_DATAA)': cannot convert argument 1 from 'const _Elem *' to 'LPCSTR'
1>E:\Projects\third_source\bit7z\src\fsindexer.cpp(44,64): error C2664:         with
1>E:\Projects\third_source\bit7z\src\fsindexer.cpp(44,64): error C2664:         [
1>E:\Projects\third_source\bit7z\src\fsindexer.cpp(44,64): error C2664:             _Elem=wchar_t
1>E:\Projects\third_source\bit7z\src\fsindexer.cpp(44,64): error C2664:         ]
1>E:\Projects\third_source\bit7z\src\fsindexer.cpp(44,54): message : Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\fileapi.h(280,1): message : see declaration of 'FindFirstFileA' (compiling source file src\fsindexer.cpp)
1>Done building project "bit7z.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
rikyoz commented 4 years ago
 bit7z.vcxproj | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bit7z.vcxproj b/bit7z.vcxproj
index 1e43a29..d6a92a2 100644
--- a/bit7z.vcxproj
+++ b/bit7z.vcxproj
@@ -89,7 +89,7 @@
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <OutputDirectory>bin\x86\</OutputDirectory>
     <ATLMinimizesCRunTimeLibraryUsage>false</ATLMinimizesCRunTimeLibraryUsage>
-    <CharacterSet>NotSet</CharacterSet>
+    <CharacterSet>MultiByte</CharacterSet>
     <ConfigurationType>StaticLibrary</ConfigurationType>
     <IntermediateDirectory>build\x86\debug\.obj\</IntermediateDirectory>
     <PrimaryOutput>bit7z_d</PrimaryOutput>
@@ -244,7 +244,7 @@
       <ExceptionHandling>Sync</ExceptionHandling>
       <ObjectFileName>$(IntDir)</ObjectFileName>
       <Optimization>Disabled</Optimization>
-      <PreprocessorDefinitions>_WINDOWS;UNICODE;_UNICODE;WIN32;_7Z_VOL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>_WINDOWS;WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <PreprocessToFile>false</PreprocessToFile>
       <SuppressStartupBanner>true</SuppressStartupBanner>
       <TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>

From what I see, you set <CharacterSet> to MultiByte but also remove UNICODE and _UNICODE flags in <PreprocessorDefinitions>. However, at least one of the two options must be set in order to have the correct expansion of the WinAPI functions! The default .vcxproj file of bit7z correctly defines the flags, so if you do not change them you should not have any problem!

CruiseYoung commented 4 years ago

https://github.com/rikyoz/7-Zip/blob/master/CPP/Build.mak

!IFNDEF MY_NO_UNICODE CFLAGS = $(CFLAGS) -DUNICODE -D_UNICODE !ENDIF

This is an option, but not the default option, which allows the user to choose. The same reason, bit7z should be the same.

rikyoz commented 4 years ago

https://github.com/rikyoz/7-Zip/blob/master/CPP/Build.mak

!IFNDEF MY_NO_UNICODE CFLAGS = $(CFLAGS) -DUNICODE -D_UNICODE !ENDIF

This is an option, but not the default option, which allows the user to choose. The same reason, bit7z should be the same.

Actually, being an !IFNDEF, it means that by default 7-zip is compiled using UNICODE and _UNICODE flags, unless the user specifies the MY_NO_UNICODE flag.

bit7z, at the moment, has an API which supports only Unicode (a choice done at the beginning of the project in order to provide a simpler public API). However, the next version v4.0, which is in the working, will bring support to the ANSI versions of both 7-zip and WinAPIs, as well as many other features.