<div dir="ltr">Hi,<br><br>I'm wrapping Win32 PC/SC and I don't understand how I should wrap structures. Here is my simplified header:<br><br>============= C HEADER =============<br><br>#define IN /* Tag for INPUT parameters */<br>
#define OUT /* Tag for OUTPUT parameters */<br> <br><br>typedef int DWORD;<br>typedef int LONG;<br><br>typedef LONG SCARDHANDLE;<br><br>typedef unsigned char BYTE;<br>typedef const BYTE* LPCBYTE;<br>typedef DWORD* LPDWORD;<br>
<br>typedef struct _SCARD_IO_REQUEST{<br> DWORD dwProtocol; // Protocol identifier<br> DWORD cbPciLength; // Protocol Control Information Length<br>} SCARD_IO_REQUEST, *PSCARD_IO_REQUEST, *LPSCARD_IO_REQUEST;<br>
typedef const SCARD_IO_REQUEST *LPCSCARD_IO_REQUEST;<br><br><br>LONG SCardTransmit(<br> IN SCARDHANDLE hCard,<br> IN LPCSCARD_IO_REQUEST pioSendPci,<br> IN LPCBYTE pbSendBuffer,<br> IN DWORD cbSendLength,<br> IN OUT LPSCARD_IO_REQUEST pioRecvPci,<br>
OUT LPBYTE pbRecvBuffer,<br> IN OUT LPDWORD pcbRecvLength);<br><br><br>============= END OF C HEADER =============<br><br><br>Here is my conversion attempt:<br><br><br><br>============= SCHEME MODULE =============<br>
<br>;; #lang mzscheme<br>(module winscard mzscheme<br> (require mzlib/foreign) <br> (unsafe!)<br> <br> (define winscard (ffi-lib "winscard"))<br> <br> (define _DWORD _int)<br> (define _LONG _int)<br> (define _SCARDHANDLE _int)<br>
<br> (provide scard-ok)<br> (define (scard-ok scard-error)<br> (= scard-error 0))<br> (provide make-SCARD_IO_REQUEST)<br> (define-cstruct _SCARD_IO_REQUEST ([dwProtocol _DWORD];; // Protocol identifier<br> [cbPciLength _DWORD])) ;; // Protocol Control Information Length<br>
<br> #|<br>LONG SCardTransmit(<br> IN SCARDHANDLE hCard,<br> IN LPCSCARD_IO_REQUEST pioSendPci,<br> IN LPCBYTE pbSendBuffer,<br> IN DWORD cbSendLength,<br> IN OUT LPSCARD_IO_REQUEST pioRecvPci,<br> OUT LPBYTE pbRecvBuffer,<br>
IN OUT LPDWORD pcbRecvLength);<br>|#<br> (provide scard-transmit)<br> (define scard-transmit<br> (get-ffi-obj "SCardTransmit"<br> winscard<br> (_fun (hCard : _SCARDHANDLE) ;; == IN SCARDHANDLE hCard<br>
(pioSendPci : _SCARD_IO_REQUEST-pointer) ;; == IN LPCSCARD_IO_REQUEST pioSendPci<br> (pbSendBuffer : (_vector i _byte)) ;; == IN LPCBYTE pbSendBuffer<br> (cbSendLength : _DWORD) ;; == IN DWORD cbSendLength<br>
(ioRecvPci : (_ptr io _SCARD_IO_REQUEST)) ;; == IN OUT LPSCARD_IO_REQUEST pioRecvPci<br> (pbRecvBuffer : (_vector o _byte cbRecvLength)) ;; == OUT LPBYTE pbRecvBuffer<br> (cbRecvLength : (_ptr io _DWORD)) ;; == IN OUT LPDWORD pcbRecvLength<br>
-> (error : _LONG) <br> -> (if (scard-ok error) '(error ioRecvPci pbRecvBuffer cbRecvLength) #f)<br> )))<br> )<br><br>============= END OF SCHEME MODULE =============<br>
<br><br>============= SCHEME PROGRAM =============<br>(require "winscard.ss")<br>(require mzlib/foreign) <br>(unsafe!)<br><br>(define hCard 1)<br>(define pioSendPci (make-SCARD_IO_REQUEST #x0002 8))<br>(define pbSendBuffer (make-vector 4 0))<br>
(define cbSendLength 4)<br>(define ioRecvPci (make-SCARD_IO_REQUEST #x0002 8))<br>(define cbRecvLength 4)<br>(scard-transmit <br> hCard <br> pioSendPci <br> pbSendBuffer <br> cbSendLength <br> ioRecvPci <br> ;; pbRecvBuffer skipped since it's an output parameter<br>
cbRecvLength) <br><br>============= END OF SCHEME PROGRAM =============<br><br>Program fails with: "zero?: expects argument of type <real number>; given #<cpointer>".<br><br>Any hint? Thanks.<br><br>
<br></div>