ページの先頭行へ戻る
Interstage Application Server アプリケーション作成ガイド(CORBAサービス編)
Interstage

3.7.3 ワイド文字列型

(1)IDLマッピング

IDL言語で文字列型wstringを指定した場合、C言語ではCORBA_wstringにマッピングされます。CORBA_wstringは以下のように定義されています。

typedef CORBA_wchar   *CORBA_wstring; 

以下のIDL定義例をもとに説明します。


IDL言語
module ODsample{
    interface   wstringtest{
        wstring op1(in wstring str1, out wstring str2, inout wstring str3); 
    };
};

C言語
CORBA_wstring
ODsample_wstringtest_op1(
    ODsample_wstringtest obj;  /* オブジェクトリファレンス */
    CORBA_wstring str1,        /* inパラメタ */
    CORBA_wstring *str2,       /* outパラメタ */
    CORBA_wstring *str3,       /* inoutパラメタ */
    CORBA_Environment *env )   /* 例外情報 */

(2)クライアントアプリケーションで扱うパラメタ

クライアントアプリケーションのパラメタの扱いについて以下に示します。

パラメタ

サーバへ渡すパラメタ

サーバから渡されたパラメタ

in

CORBA_wstring_alloc()で領域を獲得します。

inout

(inパラメタと同じ)

領域はスタブで自動的に獲得されます。

out
復帰

(inoutパラメタと同じ)


注意

クライアントおよびスタブで獲得した領域は、不要になった時点でCORBA_free()で解放する必要があります。

クライアントアプリケーションでの処理例を以下に示します。

CORBA_wstring          str1, str2, str3, ret; 
CORBA_Environment      env; 

/* inパラメタ */
str1 = CORBA_wstring_alloc(2);  /* 領域獲得 */
str1[0] = ...;                  /* パラメタ設定(“(4)文字列の設定方法”参照) */
    :

/* inoutパラメタ */
str3 = CORBA_wstring_alloc(5);  /* 領域獲得 */
str3[0] = ...;                  /* パラメタ設定(“(4)文字列の設定方法”参照) */
    :

/* サーバ呼出し */
ret = ODsample_wstringtest_op1(obj, str1, &str2, &str3, &env ); 

/* 領域解放 */
CORBA_free( str1 );             /* inパラメタ */
CORBA_free( str2 );             /* outパラメタ */
CORBA_free( str3 );             /* inoutパラメタ */
CORBA_free( ret );              /* 復帰パラメタ */

(3)サーバアプリケーションで扱うパラメタ

サーバアプリケーションのパラメタの扱いについて以下に示します。

パラメタ

クライアントから渡されたパラメタ

クライアントへ渡すパラメタ

in

文字列域は、スケルトンで自動的に獲得/解放されます。

inout

文字列域は、スケルトンで自動的に獲得されます。

  • 渡されたパラメタより短い文字列を返す場合
    渡された文字列域に文字列を設定します。

  • 渡されたパラメタより長い文字列を返す場合
    渡された文字列域をCORBA_free()で一度解放し、CORBA_wstring_alloc()で再獲得します。

文字列域は、スケルトンで自動的に解放されます。

out
復帰

文字列域をCORBA_wstring_alloc()で獲得します。文字列域は、スケルトンで自動的に解放されます。

サーバアプリケーションでの処理例を以下に示します。

CORBA_wstring
ODsample_wstringtest_op1(
    ODsample_stringtest  obj;   /* オブジェクトリファレンス */
    CORBA_wstring     wstr1,    /* inパラメタ */
    CORBA_wstring     *wstr2,   /* outパラメタ */
    CORBA_wstring     *wstr3,   /* inoutパラメタ */
    CORBA_Environment *env )    /* 例外情報 */
{
    CORBA_wstring    wstr; 

/* outパラメタ */
    *wstr2 = CORBA_wstring_alloc(3);   /* 領域獲得 */
    (*wstr2)[0] = ...;                 /* パラメタ設定:(4)参照 */
      :

/* inoutパラメタ */
    CORBA_free( *wstr3 );              /* 領域解放 */
    *wstr3 = CORBA_wstring_alloc(5);   /* 領域再獲得 */
    (*wstr3)[0] = ...;                 /* パラメタ設定:(4)参照 */
      :

/* 復帰パラメタ */
    wstr = CORBA_wstring_alloc(4);     /* 領域獲得 */
    wstr[0] = ...;                     /* パラメタ設定:(4)参照 */
      :
    return( wstr ); 
}

(4)文字列の設定方法

ワイド文字列型への文字列の設定方法を以下に示します。変数wstrは、CORBA_wchar*型です。


EUCまたはShiftJISを使用する場合

文字を1文字ずつ設定します(EUCの場合)。

wstr[0] = 0xc6fc;  /*  "日"    */
wstr[1] = 0xcbdc;  /*  "本"    */
wstr[2] = 0xb8ec;  /*  "語"    */
wstr[3] = 0x0000;  /*  終端子  */

Windows(R)でUNICODEを使用する場合

""で囲んだ文字列にL修飾子を付けると、UNICODEになります。

wstr = L"日本語";

UNIXでUNICODEを使用する場合

UNICODEの値を1文字ずつ直接数値で設定します。

wstr[0] = 0x65e5;  /*  "日"    */
wstr[1] = 0x672c;  /*  "本"    */
wstr[2] = 0x8a9e;  /*  "語"    */
wstr[3] = 0x0000;  /*  終端子  */

注意

ワイド文字列型をコンソールなどに出力する場合、出力処理は各OSに依存するため、そのままでは正しい文字が出力できないことがあります。出力の方法については、各OSのマニュアルを参照してください。


L"..."の形式の文字列を処理することはできません。