[racket] ffi: handling return values in arguments?

From: Altenburg, Robert (raltenburg at state.pa.us)
Date: Tue Nov 16 12:09:54 EST 2010

This is probably a simple question, but I can't seem
to make this work:

The Windows SDK defines the following function:

  __in   LPWSTR servername,
  __in   DWORD level,
  __out  LPBYTE *bufptr

In this case "bufptr" points to a structure allocated by
the system that contains the results.

How does one indicate this to get-ffi-obj, and get the
returned value from the buffer?


(require ffi/unsafe)

; bufptr points to one of these structures:
(define-cstruct _wksta-info-100
  ([platform_id _int32]
   [computername _pointer]
   [langroup _pointer]
   [ver_major _int32]
   [ver_minor _int32]))

(define netapi-lib (ffi-lib "Netapi32.dll"))
(define net-wksta-get-info
  (get-ffi-obj "NetWkstaGetInfo" netapi-lib
               (_fun [_int = 0] [_int = 100] ??? ; <--- needs a *bufptr here
                   -> [ret : _int]
                   -> (if (zero? ret) ; 0x0 = NERR_Success
                          (display "works")
                          (display "fails")))))


; When done, call NetApiBufferFree on the buffer

Posted on the users mailing list.