⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 helpers.cpp

📁 vc++与visio 安装VISIO office(推荐2003以上版本)必须安装visio office 否则程序无法运行 安装VisioSDK(推荐2003以上版本) 默认安装路径为<
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//
VVariant::VVariant(const VVariant& other)
{
	Init();
	Copy(other.m_v);
}

//	VVariant - Constructor
//
//	<summary>
//	Constructor for VVariant class - takes a VARIANT
//	</summary>
//
//	Return Value:
//	None
//
VVariant::VVariant(const VARIANT& v)
{
	//	*REQUIRED*
	Init();
	Copy(v);
}

//	VVariant - Constructor
//
//	<summary>
//	Constructor for VVariant class - takes an LPCTSTR
//	</summary>
//
//	Return Value:
//	None
//
VVariant::VVariant(LPCTSTR p)
{
	Init();
	V_VT(&m_v)= VT_BSTR;
	if (p)
		V_BSTR(&m_v)= SysAllocString(VBstr(p));
}

//	VVariant - Constructor
//
//	<summary>
//	Constructor for VVariant class - takes an BSTR.  Can assume responsibility 
//	for the BSTR
//	</summary>
//
//	Return Value:
//	None
//
VVariant::VVariant(const BSTR bstr, BOOL bAssumeResponsibility)
{
	Init();
	V_VT(&m_v)= VT_BSTR;

	if (bAssumeResponsibility)
		V_BSTR(&m_v)= bstr;
	else
		V_BSTR(&m_v)= SysAllocString(bstr);
}

//	VVariant - Constructor
//
//	<summary>
//	Constructor for VVariant class - takes an long
//	</summary>
//
//	Return Value:
//	None
//
VVariant::VVariant(const long n)
{
	Init();
	V_VT(&m_v)= VT_I4;
	V_I4(&m_v)= n;
}

//	VVariant - Constructor
//
//	<summary>
//	Constructor for VVariant class - takes an double
//	</summary>
//
//	Return Value:
//	None
//
VVariant::VVariant(const double d)
{
	Init();
	V_VT(&m_v)= VT_R8;
	V_R8(&m_v)= d;
}

//	VVariant - Constructor
//
//	<summary>
//	Constructor for VVariant class - takes an LPUNKNOWN
//	</summary>
//
//	Return Value:
//	None
//
VVariant::VVariant(const LPUNKNOWN pUnk)
{
	Init();
	V_VT(&m_v)= VT_UNKNOWN;
	V_UNKNOWN(&m_v)= pUnk;
	if (pUnk)
		pUnk->AddRef();
}

//	VVariant - Constructor
//
//	<summary>
//	Constructor for VVariant class - takes an LPDISPATCH
//	</summary>
//
//	Return Value:
//	None
//
VVariant::VVariant(const LPDISPATCH pDisp)
{
	Init();
	V_VT(&m_v)= VT_DISPATCH;
	V_DISPATCH(&m_v)= pDisp;
	if (pDisp)
		pDisp->AddRef();
}

//	~VVariant - Destructor
//
//	<summary>
//	Destructor for VVariant class.  Clears the variant.
//	</summary>
//
//	Return Value:
//	None
//
VVariant::~VVariant()
{
	Clear();
}

//	operator VARIANT * - operator for accessing VARIANT member's address
//
//	<summary>
//	Access the address of the variant member variable.
//	</summary>
//
//	Return Value:
//	VARIANT * - the address of the VARIANT member variable
//
VVariant::operator VARIANT*()
{
	//	*REQUIRED*
	return &m_v;
}

//	operator VARIANT - operator for accessing VARIANT member
//
//	<summary>
//	Access the variant member variable.
//	</summary>
//
//	Return Value:
//	VARIANT - the value of the VARIANT member variable
//
VVariant::operator VARIANT()
{
	//	*REQUIRED*
	return m_v;
}

//	operator const VARIANT - get a constant copy of the variant member
//
//	<summary>
//	Get const access to the variant member variable.
//	</summary>
//
//	Return Value:
//	const VARIANT - const value of the VARIANT member variable
//
VVariant::operator const VARIANT() const
{
	//	*REQUIRED*
	return m_v;
}

//	operator= - Assignment operator
//
//	<summary>
//	Assign the VVariant with the value of another VVariant
//	</summary>
//
//	Return Value:
//	const VVariant & - constant reference to the VVariant
//
const VVariant& VVariant::operator=(const VVariant& other)
{
	if (&other!=this)
		{
		Clear();
		Copy(other.m_v);
		}
	return (*this);
}

//	operator= - Assignment operator
//
//	<summary>
//	Assign the VVariant with the value of a VARIANT
//	</summary>
//
//	Return Value:
//	const VVariant & - constant reference to the VVariant
//
const VVariant& VVariant::operator=(const VARIANT& v)
{
	Clear();
	Copy(v);
	return (*this);
}

//	operator= - Assignment operator
//
//	<summary>
//	Assign the VVariant with the value of an LPCTSTR
//	</summary>
//
//	Return Value:
//	const VVariant & - constant reference to the VVariant
//
const VVariant& VVariant::operator=(LPCTSTR p)
{
	Clear();
	V_VT(&m_v)= VT_BSTR;
	if (p)
		V_BSTR(&m_v)= SysAllocString(VBstr(p));
	return (*this);
}


//	operator= - Assignment operator
//
//	<summary>
//	Assign the VVariant with the value of a long
//	</summary>
//
//	Return Value:
//	const VVariant & - constant reference to the VVariant
//
const VVariant& VVariant::operator=(const long n)
{
	Clear();
	V_VT(&m_v)= VT_I4;
	V_I4(&m_v)= n;
	return (*this);
}

//	operator= - Assignment operator
//
//	<summary>
//	Assign the VVariant with the value of a double
//	</summary>
//
//	Return Value:
//	const VVariant & - constant reference to the VVariant
//
const VVariant& VVariant::operator=(const double d)
{
	Clear();
	V_VT(&m_v)= VT_R8;
	V_R8(&m_v)= d;
	return (*this);
}

//	operator= - Assignment operator
//
//	<summary>
//	Assign the VVariant with the value of a LPUNKNOWN
//	</summary>
//
//	Return Value:
//	const VVariant & - constant reference to the VVariant
//
const VVariant& VVariant::operator=(const LPUNKNOWN pUnk)
{
	Clear();
	V_VT(&m_v)= VT_UNKNOWN;
	V_UNKNOWN(&m_v)= pUnk;
	if (pUnk)
		pUnk->AddRef();
	return (*this);
}

//	operator= - Assignment operator
//
//	<summary>
//	Assign the VVariant with the value of a LPDISPATCH
//	</summary>
//
//	Return Value:
//	const VVariant & - constant reference to the VVariant
//
const VVariant& VVariant::operator=(const LPDISPATCH pDisp)
{
	Clear();
	V_VT(&m_v)= VT_DISPATCH;
	V_DISPATCH(&m_v)= pDisp;
	if (pDisp)
		pDisp->AddRef();
	return (*this);
}


//	operator= - SetBSTR 
//
//	<summary>
//	Assign the VVariant with the value of a BSTR.  
//	</summary>
//
//	Return Value:
//	const VVariant & - constant reference to the VVariant
const VVariant& VVariant::SetBSTR(const BSTR bstr)
{
	Clear();
	V_VT(&m_v)= VT_BSTR;
	V_BSTR(&m_v)= SysAllocString(bstr);
	return (*this);
}


//	Init - Initialize the VARIANT member variable
//
//	<summary>
//	Initialize the VARIANT member variable.
//	</summary>
//
//	Return Value:
//	None
//
void VVariant::Init(void)
{
	VariantInit(&m_v);
}

//	Clear - Clear the VARIANT member variable
//
//	<summary>
//	Clear the VARIANT member variable.
//	</summary>
//
//	Return Value:
//	None
//
void VVariant::Clear(void)
{
	VariantClear(&m_v);
}

//	Copy - Copy the value of a VARIANT into the VARIANT member variable
//
//	<summary>
//	Copy the value of a VARIANT into the VARIANT member variable.
//	</summary>
//
//	Return Value:
//	None
//
void VVariant::Copy(const VARIANT &v)
{
	if (!SUCCEEDED(VariantCopy(&m_v, (VARIANT*) &v)))
		VariantClear(&m_v);
}

//	Init - Initialize a VSafeArray object
//
//	<summary>
//	Initialize the member variables of the VSafeArray.
//	</summary>
//
//	Return Value:
//	HRESULT - NOERROR or some HRESULT error code
//
HRESULT VSafeArray::Init(void)
{
	//	This Init must be called before Create. Calling it after Create
	//	would cause a memory leak...

	//	We have it so we don't duplicate a bunch of code in all the various
	//	constructors.... Set initial values of members here.

	//	Call from ALL constructors...

	m_nDims= DIM_UNINITIALIZED;
	m_vt= VT_EMPTY;
	m_pSA= NULL;

	return NOERROR;
}

//	VSafeArray - Constructor
//
//	<summary>
//	Default constructor for the VSafeArray class
//	</summary>
//
//	Return Value:
//	None
//
VSafeArray::VSafeArray()
{
	Init();
}

//	VSafeArray - Constructor
//
//	<summary>
//	Constructor for the VSafeArray class that creates a VSafeArray of a 
//	particular type, number of dimensions and bounds.
//	</summary>
//
//	Return Value:
//	None
//
VSafeArray::VSafeArray(VARTYPE vt,
					   unsigned int nDims, 
					   SAFEARRAYBOUND FAR* pBounds)
{
	//	Generic:
	Init();
	Create(vt, nDims, pBounds);
}

//	VSafeArray - Constructor
//
//	<summary>
//	Constructor for the VSafeArray class that creates a 1-d SafeArray
//	with a specific number of elements and a lower bound.
//	</summary>
//
//	Return Value:
//	None
//
VSafeArray::VSafeArray(VARTYPE vt, ULONG cElements, LONG lLbound)
{
	//	Simple 1D:
	SAFEARRAYBOUND bound[1];
	bound[0].cElements= cElements;
	bound[0].lLbound= lLbound;

	Init();
	Create(vt, 1, bound);
}

//	VSafeArray - Constructor
//
//	<summary>
//	Constructor for the VSafeArray class that creates a 2-d SafeArray
//	with a specific number of elements and lower bound for each array 
//	dimension.
//	</summary>
//
//	Return Value:
//	None
//
VSafeArray::VSafeArray(VARTYPE vt,
					   ULONG cElements1,
					   LONG lLbound1,
					   ULONG cElements2,
					   LONG lLbound2)
{
	//	2D:
	SAFEARRAYBOUND bound[2];
	bound[0].cElements= cElements1;
	bound[0].lLbound= lLbound1;
	bound[1].cElements= cElements2;
	bound[1].lLbound= lLbound2;

	Init();
	Create(vt, 2, bound);
}

//	VSafeArray - Constructor
//
//	<summary>
//	Constructor for the VSafeArray class that creates a 3-d SafeArray
//	with a specific number of elements and lower bound for each array 
//	dimension.
//	</summary>
//
//	Return Value:
//	None
//
VSafeArray::VSafeArray(VARTYPE vt,
					   ULONG cElements1,
					   LONG lLbound1,
					   ULONG cElements2,
					   LONG lLbound2,
					   ULONG cElements3,
					   LONG lLbound3)
{
	//	3D:
	SAFEARRAYBOUND bound[3];
	bound[0].cElements= cElements1;
	bound[0].lLbound= lLbound1;
	bound[1].cElements= cElements2;
	bound[1].lLbound= lLbound2;
	bound[2].cElements= cElements3;
	bound[2].lLbound= lLbound3;

	Init();
	Create(vt, 3, bound);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -