Hello!
Trying to access my gnuk using gpg in cygwin, I've discovered a rare bug. Here is an fragment from scdaemon.log:
2019-04-03 20:28:24 scdaemon[1606.600048ae0] DBG: send apdu: c=00 i=A4 p1=00 p2=0C lc=2 le=-1 em=0 2019-04-03 20:28:24 scdaemon[1606.600048ae0] DBG: PCSC_data: 00 A4 00 0C 02 3F 00 2019-04-03 20:28:24 scdaemon[1606.600048ae0] pcsc_transmit failed: invalid parameter (0x80100004)
At the same time, the "native" ɡpɡ which comes with standard gpg4win installation worked fine. After some discovery I've found out that the reason is a wrong memory layout for SCardTransmit 2nd argument (a pointer to SCARD_IO_REQUEST). It is defined in apdu.c like this:
struct pcsc_io_request_s { unsigned long protocol; unsigned long pci_len; };
but in WinAPI reference it is defined asː
typedef struct { DWORD dwProtocol; DWORD cbPciLength; } SCARD_IO_REQUEST;
When compiled for 64-bit, unsigned long occupies 8 bytes, whereas DWORD size is 4 bytes regardless of used memory model. I've changed unsigned long to pcsc_dword_t and problem disappeared. Here is the patchː