Archive for 3月 10th, 2013

  1. Hello, Win32 API(Common Lisp) World!

    Posted on 3月 10th, 2013 by cx20

    Win32 API(Common Lisp)

    Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
    以下は Common Lisp にて FFI を使用した Win32 API 呼出しの例となっている。

    ソースコード

    (defpackage "WIN32"
      (:modern t)
      (:use "FFI")
      (:shadowing-import-from "EXPORTING"
        #:defconstant #:defun #:defmacro
        #:def-c-type #:def-c-enum #:def-c-struct #:def-c-var #:def-call-out))
     
    (in-package "WIN32")
     
    (default-foreign-language :stdc-stdcall) ; WINAPI means __stdcall
     
    (def-c-type handle c-pointer)
    (def-c-type dword uint32)
    (def-c-type word uint16)
     
    (default-foreign-library "user32.dll")
     
    (defconstant MB_OK 0)
     
    (def-call-out MessageBoxA (:return-type int)
      (:arguments (parent handle) (text c-string) (caption c-string) (type uint)))
     
    (win32:MessageBoxA nil "Hello, Win32 API World!" "Hello, World!" win32:MB_OK)

    実行方法

    C:¥> clisp Hello.lisp

    実行結果

    ---------------------------
    Hello, World!
    ---------------------------
    Hello, Win32 API World!
    ---------------------------
    OK   
    ---------------------------