interface IMyAPI : IDispatch { [id(1), helpstring("メソッド MsgBox")] HRESULT MsgBox( [in] BSTR Message, [in] BSTR Title ); };
public: STDMETHOD(MsgBox)( BSTR Message, BSTR Title );
STDMETHODIMP CMyAPI::MsgBox( BSTR Message, BSTR Title ) { _bstr_t bstr; _bstr_t bstr2; bstr.operator = (Message); bstr2.operator = (Title); ::MessageBox( NULL, (LPTSTR)bstr, (LPTSTR)bstr2, MB_OK ); return S_OK; }
Set obj = CreateObject("MyCom.MyAPI") Call obj.MsgBox("こんにちは !", "タイトルの表示" )
Set obj = CreateObject("MyCom.MyAPI") obj.MsgBox "こんにちは !", "タイトルの表示"
interface IMyAPI : IDispatch { [id(1), helpstring("メソッド MsgBox")] HRESULT MsgBox( [in] BSTR Message, [in,optional] VARIANT Title ); };
public: STDMETHOD(MsgBox)( BSTR Message, VARIANT Title );
STDMETHODIMP CMyAPI::MsgBox( BSTR Message, VARIANT Title ) { // 引数省略チェック用 _variant_t vtWork(Title); _bstr_t bstr(Message); _bstr_t bstr2; // タイトル引数チェック if ( vtWork.vt != VT_ERROR ) { bstr2.operator = (Title); } else { bstr2.operator = ("デフォルト文字列"); } MessageBox( NULL, (LPTSTR)bstr, (LPTSTR)bstr2, MB_OK ); return S_OK; }