Archive for 4月 27th, 2012

  1. Hello, Win32 API(Perl) World!

    Posted on 4月 27th, 2012 by cx20

    Win32 API(Perl)

    Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
    以下は Perl にて Win32::API モジュールを用いた呼出し例である。

    ソースコード

    use strict;
    use Win32::API;
     
    my $msgbox= Win32::API->new("user32", "MessageBoxA", "NPPN", "N");
       $msgbox->Call( 0, "Hello, Win32 API(Perl) World!", "Hello, World!", 0 );

    なお、上記の “NPPN”, “N” は各引数と戻り値の型を表している。以下は主要なタイプ一覧である。詳細は「Win32::API – search.cpan.org」を参照のこと。

    タイプ 説明
    I 整数型(int)
    N 数値型(long)
    F 単精度浮動小数点数(float)
    D 倍精度浮動小数点数(double)
    C 文字型(char)
    P ポインタ型(文字列、構造体等へのポインタ)
    S 構造体オブジェクト(Win32::API::Struct)
    K コールバックオブジェクト(Win32::API::Callback)

    コンパイル方法

    C:¥> perl hello.pl

    実行結果

    ---------------------------
    Hello, World!
    ---------------------------
    Hello, Win32 API(Perl) World!
    ---------------------------
    OK   
    ---------------------------