Archive for 2月 6th, 2013

  1. Hello, COM(Cobra) World!

    Posted on 2月 6th, 2013 by cx20

    COM(Cobra)

    COM(Component Object Model)はマイクロソフトの提唱するプログラム部品の仕様である。
    COM を用いて開発された部品であれば言語を問わず利用することができる。
    以下は Cobra による COM クライアントの例となっている。

    ソースコード(実行時バインディング)

    use System
    use System.Reflection
    use System.Runtime.InteropServices
     
    class Program
        def main is shared
            objType = Type.getTypeFromProgID("Shell.Application") 
            shell = Activator.createInstance(objType)
            param = @[ 0, "Hello, COM(Cobra) World!", 0, 36 ]
            folder = shell.getType.invokeMember( 
                "BrowseForFolder", BindingFlags.InvokeMethod, nil, shell, param )
            if folder  nil
                Marshal.releaseComObject(folder)
            Marshal.releaseComObject(shell)

    コンパイル方法(実行時バインディング)

    C:¥> cobra -compile Hello.cobra

    実行結果

    +----------------------------------------+
    |Browse For Folder                    [X]|
    +----------------------------------------+
    | Hello, COM(Cobra) Wolrd!               |
    |                                        |
    | +------------------------------------+ |
    | |[Windows]                           | |
    | | +[addins]                          | |
    | | +[AppCompat]                       | |
    | | +[AppPatch]                        | |
    | | +[assembly]                        | |
    | |     :                              | |
    | |     :                              | |
    | |     :                              | |
    | +------------------------------------+ |
    | [Make New Folder]    [  OK  ] [Cancel] |
    +----------------------------------------+