LudovicRousseau / pcsc-tools

Some tools to be used with smart cards and PC/SC
https://pcsc-tools.apdu.fr/
GNU General Public License v2.0
185 stars 63 forks source link

how to compile the pcsc_scan.exe with UNICODE on Windows platform #66

Closed totti0858 closed 1 year ago

totti0858 commented 1 year ago

I run the pcsc_scan.exe (http://ludovic.rousseau.free.fr/softwares/pcsc-tools/pcsc_scan.exe) you provided but when I start app, we can see it finally invoke the method SCardGetStatusChangeA instead of SCardGetStatusChangeW at background once the winscard.h SCardGetStatusChange API define: https://learn.microsoft.com/en-us/windows/win32/api/winscard/nf-winscard-scardgetstatuschangea https://learn.microsoft.com/en-us/windows/win32/api/winscard/nf-winscard-scardgetstatuschangew

Here is the note: The winscard.h header defines SCardGetStatusChange as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

Then I try to compile the pcsc_scan.exe by my self and specify the UNICODE flag for I don't want to invoke the method SCardGetStatusChangeA at background.

How can I pass the -DUNICODE flag to the compiler during configure the pcsc_scan project?

LudovicRousseau commented 1 year ago

Windows is not supported. I let you find the solution yourself.

A Pull Request is welcome if you find a nice solution with no side effect on non-Windows systems.

LudovicRousseau commented 1 year ago

You can use something like:

CPPFLAGS=-DUNICODE ./configure

I have not tested on a Windows system but on my GNU/Linux system I see the -DUNICODE argument passed to the compiler:

$ make V=1
make  all-am
make[1]: Entering directory '/home/rousseau/Documents/sc/pcsc-tools'
gcc -DHAVE_CONFIG_H -I.   -DUNICODE -I/usr/include/PCSC -pthread   -MT pcsc_scan-pcsc_scan.o -MD -MP -MF .deps/pcsc_scan-pcsc_scan.Tpo -c -o pcsc_scan-pcsc_scan.o `test -f 'pcsc_scan.c' || echo './'`pcsc_scan.c
mv -f .deps/pcsc_scan-pcsc_scan.Tpo .deps/pcsc_scan-pcsc_scan.Po
gcc -I/usr/include/PCSC -pthread     -o pcsc_scan pcsc_scan-pcsc_scan.o -lpcsclite  
make[1]: Leaving directory '/home/rousseau/Documents/sc/pcsc-tools'
LudovicRousseau commented 1 year ago

The compilation using MSYS2 works but with warnings because when UNICODE is defined the characters are not char any more. Execution then does not work as expected at all.

Why do you want to use Unicode?

LudovicRousseau commented 1 year ago

@totti0858 I get not response from you. Should I close this issue?

totti0858 commented 1 year ago

thanks for your info, you can close it now.