<div dir="ltr"><font class="fixed_width" face="Courier, Monospaced">Hello, <br> </font><p><font class="fixed_width" face="Courier, Monospaced">I&#39;m trying out PLT Scheme FFI on WIn32. Examples included into the distribution show only simpler cases. <br>
 </font></p><p><font class="fixed_width" face="Courier, Monospaced">Here is the C snippet I&#39;m trying to translate: <br> </font></p><span style="font-family: courier new,monospace;">typedef unsigned char BYTE;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">typedef BYTE* LPBYTE;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">typedef const BYTE* LPCBYTE;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">typedef unsigned long DWORD;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">typedef DWORD* LPDWORD;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">typedef void* SCARDHANDLE; // Just an handle.</span><br style="font-family: courier new,monospace;"><p style="font-family: courier new,monospace;"><font class="fixed_width">typedef struct _SCARD_IO_REQUEST{ <br>
 &nbsp; &nbsp; DWORD dwProtocol; &nbsp; // Protocol identifier <br> &nbsp; &nbsp; DWORD cbPciLength; &nbsp;// Protocol Control Information Length <br> </font></p><div id="qhide_87640" style="display: block; font-family: courier new,monospace;" class="qt">
<font class="fixed_width">} SCARD_IO_REQUEST, *PSCARD_IO_REQUEST, *LPSCARD_IO_REQUEST; <br>&nbsp; <br></font></div><font style="font-family: courier new,monospace;" class="fixed_width" face="Courier, Monospaced">typedef const SCARD_IO_REQUEST *LPCSCARD_IO_REQUEST; <br>
<br> </font><p><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;">LONG SCardTransmit( </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> &nbsp; /* IN */&nbsp; SCARDHANDLE hCard,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> &nbsp; </span></font><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;">/* IN */&nbsp; </span></font><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;">LPCSCARD_I0_REQUEST pioSendPci, </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> &nbsp; </span></font><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;">/* IN */&nbsp; </span></font><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;">LPCBYTE pbSendBuffer, </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> &nbsp; </span></font><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;">/* IN */&nbsp; </span></font><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;">DWORD cbSendLength, </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> &nbsp; </span></font><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;">/* OUT */ </span></font><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;">LPSCARD_IO_REQUEST pioRecvPci, </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> &nbsp; </span></font><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;">/* OUT */</span></font><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;"> LPBYTE pbRecvBuffer, </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> &nbsp; </span></font><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;">/* OUT */ </span></font><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;">LPDWORD pcbRecvLength </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ); </span><br> </font></p><p><font class="fixed_width" face="Courier, Monospaced">Here the resulting PLT Scheme code, with compiler errors: <br> </font></p><p style="font-family: courier new,monospace;">
<font class="fixed_width">(module winscard mzscheme <br> &nbsp; (require mzlib/foreign) <br> &nbsp; (unsafe!) <br> </font></p><p style="font-family: courier new,monospace;"><font class="fixed_width">&nbsp; (define _DWORD _int) ;; It should be 32 bits unsigned integer. <br>
 &nbsp; (define _LONG _int) ;; OK: 32 bits integer. <br> &nbsp; (define _SCARDHANDLE _int) ;; This is an handle, I&#39;d prefer using a <br> &quot;typed&quot; integer for type checking. <br> </font></p><p style="font-family: courier new,monospace;">
<font class="fixed_width">&nbsp; (define-cstruct _SCARD_IO_REQUEST ((dwProtocol _DWORD) ;; &nbsp; // <br> Protocol identifier <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(cbPciLength _DWORD))) ;; &nbsp;// <br> Protocol Control Information Length <br>
 </font></p><p style="font-family: courier new,monospace;"><font class="fixed_width">&nbsp; (define winscard (ffi-lib &quot;winscard&quot;)) <br> </font></p><p style="font-family: courier new,monospace;"><font class="fixed_width">&nbsp; &nbsp;;; [simpler functions not included] <br>
 </font></p><p style="font-family: courier new,monospace;"><font class="fixed_width">&nbsp; (provide scard-transmit) <br> &nbsp; (define-struct scard-transmit-result (error recv-pci recv-buffer <br> recv-length)) <br> &nbsp; (define scard-transmit (get-ffi-obj &quot;SCardTransmit&quot; winscard <br>
 &nbsp; &nbsp; &nbsp; (_fun (hCard : _SCARDHANDLE) <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (pioSendPci : _SCARD_I0_REQUEST-pointer) ;; ERROR: expand: <br> unbound variable in module in: __SCARD_I0_REQUEST-pointer <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (pbSendBuffer : (_cvector i _byte)) ;; ERROR: expand: <br>
 unbound variable in module in: i <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (cbSendLength : _DWORD) <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (ioRecvPci : (_ptr o _SCARD_IO_REQUEST)) <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (pbRecvBuffer : &nbsp;(_cvector o _byte )) ;; ERROR: expand: <br> unbound variable in module in: o <br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (cbRecvLength : (_ptr o _DWORD)) <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt; (error : _LONG) <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt; (make-scard-transmit-result error ioRecvPci <br> pbRecvBuffer cbRecvLength)))) <br> </font></p><p><font class="fixed_width" face="Courier, Monospaced"><span style="font-family: courier new,monospace;">) </span><br>
 </font></p><p><font class="fixed_width" face="Courier, Monospaced">What&#39;s wrong? <br> </font></p><p><font class="fixed_width" face="Courier, Monospaced">And what about byte aligned, word aligned, double word aligned&nbsp; structures? What about calling conventions? <br>
 </font></p><font class="fixed_width" face="Courier, Monospaced">Thanks </font></div>