メソッドの戻り値


  文字列を返すメソッド




lightbox オブジェクトの LboxString を使用して、指定した文字列の繰り返し文字列を返すメソッドを作成します

  • StdAfx.h に #pragma を追加して下さい


StdAfx.h
  

#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++ は前行の直前に追加の宣言を挿入します。

  

  MyCom.idl の変更

  

	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
		);
	};
  

  MyAPI.h の変更

  

public:
	STDMETHOD(MsgBox)(
		BSTR Message,
		VARIANT Title
	);
	STDMETHOD(Repeat)(
		BSTR Value,
		long nCnt,
		BSTR *pVal
	);
};
  

  MyAPI.cpp の変更

  

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 )
  

  BOOLを返すメソッド

  

[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
  




yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[cmaterial]
claudebot
24/04/17 01:23:26
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube