Archive for 5月 20th, 2012

  1. Hello, COM(JScript.NET) World!

    Posted on 5月 20th, 2012 by cx20

    COM(JScript.NET)

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

    ソースコード

    import System;
    import System.Runtime.InteropServices;
     
    var ssfWINDOWS = 36
     
    main();
     
    function main() {
        var shell = new ActiveXObject("Shell.Application");
        var folder = shell.BrowseForFolder( 0, "Hello, COM(JScript.NET) World!", 0, ssfWINDOWS );
        if ( folder != null )
        {
            Marshal.ReleaseComObject( folder );
        }
        Marshal.ReleaseComObject( shell );
    }

    コンパイル方法

    C:¥> jsc hello.js

    実行結果

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