#if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define STRICT #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0400 #endif #define _ATL_APARTMENT_THREADED #include <atlbase.h> // CComModule クラスから派生したクラスを使用して、オーバーライドする場合 // _Module の名前は変更しないでください。 extern CComModule _Module; #include <atlcom.h> #pragma comment( lib, "lightbox.lib" ) #pragma comment( lib, "shlwapi.lib" ) //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ は前行の直前に追加の宣言を挿入します。
interface IMyAPI: IDispatch { [id(1), helpstring("メソッド MsgBox")] HRESULT MsgBox( [in] BSTR Message, [in,optional] VARIANT Title ); [id(2), helpstring("メソッド Repeat")] HRESULT Repeat( [in] BSTR Value, [in] long nCnt, [out,retval] BSTR *pVal ); };
public: STDMETHOD(MsgBox)( BSTR Message, VARIANT Title ); STDMETHOD(Repeat)( BSTR Value, long nCnt, BSTR *pVal ); };
STDMETHODIMP CMyAPI::Repeat( BSTR Value, long nCnt, BSTR *pVal ) { _bstr_t bstrValue; LboxString LString; bstrValue.operator = (Value); LString.Repeat( (LPTSTR)bstrValue, nCnt ); bstrValue.operator = (LString.szLboxString); *pVal = bstrValue.copy(); return S_OK; }
STDMETHODIMP CMyAPI::Repeat( BSTR Value, long nCnt, BSTR *pVal ) { _bstr_t bstrValue; LboxString LString; bstrValue.operator = (Value); LString.Repeat( (LPTSTR)bstrValue, nCnt ); *pVal = A2BSTR(LString.szLboxString); return S_OK; }
Set obj = CreateObject("MyCom.MyAPI") Value = obj.Repeat( "漢字|", 10 ) obj.MsgBox( Value )
[id(3), helpstring("メソッド MsgOkCancel")] HRESULT MsgOkCancel( [in] BSTR Value, [out,retval] BOOL *pVal );
STDMETHOD(MsgOkCancel)( BSTR Value, BOOL *pVal );
STDMETHODIMP CMyAPI::MsgOkCancel( BSTR Value, BOOL *pVal ) { _bstr_t bstrValue; LboxWintool Wintool; bstrValue.operator = (Value); *pVal = LboxBool( Wintool.MsgOkCancel((LPTSTR)bstrValue) ); return S_OK; }
Set obj = CreateObject("MyCom.MyAPI") if obj.MsgOkCancel("OK または キャンセル を選択" ) then obj.MsgBox( "OK" ) else obj.MsgBox( "キャンセル" ) end if