_bstr_t和_variant_t是怎样定义的
发布网友
发布时间:2022-05-06 07:03
我来回答
共3个回答
热心网友
时间:2022-06-28 23:36
_bstr_t的定义:COMUTIL.H
class _bstr_t {
public:
// Constructors
//
_bstr_t() throw();
_bstr_t(const _bstr_t& s) throw();
_bstr_t(const char* s) throw(_com_error);
_bstr_t(const wchar_t* s) throw(_com_error);
_bstr_t(const _variant_t& var) throw(_com_error);
_bstr_t(BSTR bstr, bool fCopy) throw(_com_error);
// Destructor
//
~_bstr_t() throw();
// Assignment operators
//
_bstr_t& operator=(const _bstr_t& s) throw();
_bstr_t& operator=(const char* s) throw(_com_error);
_bstr_t& operator=(const wchar_t* s) throw(_com_error);
_bstr_t& operator=(const _variant_t& var) throw(_com_error);
// Operators
//
_bstr_t& operator+=(const _bstr_t& s) throw(_com_error);
_bstr_t operator+(const _bstr_t& s) const throw(_com_error);
// Friend operators
//
friend _bstr_t operator+(const char* s1, const _bstr_t& s2) throw(_com_error);
friend _bstr_t operator+(const wchar_t* s1, const _bstr_t& s2) throw(_com_error);
// Extractors
//
operator const wchar_t*() const throw();
operator wchar_t*() const throw();
operator const char*() const throw(_com_error);
operator char*() const throw(_com_error);
// Comparison operators
//
bool operator!() const throw();
bool operator==(const _bstr_t& str) const throw();
bool operator!=(const _bstr_t& str) const throw();
bool operator<(const _bstr_t& str) const throw();
bool operator>(const _bstr_t& str) const throw();
bool operator<=(const _bstr_t& str) const throw();
bool operator>=(const _bstr_t& str) const throw();
// Low-level helper functions
//
BSTR copy() const throw(_com_error);
unsigned int length() const throw();
// Binary string assign
//
void Assign(BSTR s) throw(_com_error);
private:
// Referenced counted wrapper
//
class Data_t {
public:
// Constructors
//
Data_t(const char* s) throw(_com_error);
Data_t(const wchar_t* s) throw(_com_error);
Data_t(BSTR bstr, bool fCopy) throw(_com_error);
Data_t(const _bstr_t& s1, const _bstr_t& s2) throw(_com_error);
// Reference counting routines
//
unsigned long AddRef() throw();
unsigned long Release() throw();
// Extractors
//
operator const wchar_t*() const throw();
operator const char*() const throw(_com_error);
// Low-level helper functions
//
const wchar_t* GetWString() const throw();
const char* GetString() const throw(_com_error);
BSTR Copy() const throw(_com_error);
void Assign(BSTR s) throw(_com_error);
unsigned int Length() const throw();
int Compare(const Data_t& str) const throw();
private:
wchar_t* m_wstr;
mutable char* m_str;
unsigned long m_RefCount;
// Never allow default construction
//
Data_t() throw();
// Never allow copy
//
Data_t(const Data_t& s) throw();
// Prevent deletes from outside. Release() must be used.
//
~Data_t() throw();
void _Free() throw();
};
private:
// Reference counted representation
//
Data_t* m_Data;
private:
// Low-level utilities
//
void _AddRef() throw();
void _Free() throw();
int _Compare(const _bstr_t& str) const throw();
};
_variant_t的定义:COMUTIL.H
class _variant_t : public ::tagVARIANT {
public:
// Constructors
//
_variant_t() throw();
_variant_t(const VARIANT& varSrc) throw(_com_error);
_variant_t(const VARIANT* pSrc) throw(_com_error);
_variant_t(const _variant_t& varSrc) throw(_com_error);
_variant_t(VARIANT& varSrc, bool fCopy) throw(_com_error); // Attach VARIANT if !fCopy
_variant_t(short sSrc, VARTYPE vtSrc = VT_I2) throw(_com_error); // Creates a VT_I2, or a VT_BOOL
_variant_t(long lSrc, VARTYPE vtSrc = VT_I4) throw(_com_error); // Creates a VT_I4, a VT_ERROR, or a VT_BOOL
_variant_t(float fltSrc) throw(); // Creates a VT_R4
_variant_t(double dblSrc, VARTYPE vtSrc = VT_R8) throw(_com_error); // Creates a VT_R8, or a VT_DATE
_variant_t(const CY& cySrc) throw(); // Creates a VT_CY
_variant_t(const _bstr_t& bstrSrc) throw(_com_error); // Creates a VT_BSTR
_variant_t(const wchar_t *pSrc) throw(_com_error); // Creates a VT_BSTR
_variant_t(const char* pSrc) throw(_com_error); // Creates a VT_BSTR
_variant_t(IDispatch* pSrc, bool fAddRef = true) throw(); // Creates a VT_DISPATCH
_variant_t(bool bSrc) throw(); // Creates a VT_BOOL
_variant_t(IUnknown* pSrc, bool fAddRef = true) throw(); // Creates a VT_UNKNOWN
_variant_t(const DECIMAL& decSrc) throw(); // Creates a VT_DECIMAL
_variant_t(BYTE bSrc) throw(); // Creates a VT_UI1
// Destructor
//
~_variant_t() throw(_com_error);
// Extractors
//
operator short() const throw(_com_error); // Extracts a short from a VT_I2
operator long() const throw(_com_error); // Extracts a long from a VT_I4
operator float() const throw(_com_error); // Extracts a float from a VT_R4
operator double() const throw(_com_error); // Extracts a double from a VT_R8
operator CY() const throw(_com_error); // Extracts a CY from a VT_CY
operator _bstr_t() const throw(_com_error); // Extracts a _bstr_t from a VT_BSTR
operator IDispatch*() const throw(_com_error); // Extracts a IDispatch* from a VT_DISPATCH
operator bool() const throw(_com_error); // Extracts a bool from a VT_BOOL
operator IUnknown*() const throw(_com_error); // Extracts a IUnknown* from a VT_UNKNOWN
operator DECIMAL() const throw(_com_error); // Extracts a DECIMAL from a VT_DECIMAL
operator BYTE() const throw(_com_error); // Extracts a BTYE (unsigned char) from a VT_UI1
// Assignment operations
//
_variant_t& operator=(const VARIANT& varSrc) throw(_com_error);
_variant_t& operator=(const VARIANT* pSrc) throw(_com_error);
_variant_t& operator=(const _variant_t& varSrc) throw(_com_error);
_variant_t& operator=(short sSrc) throw(_com_error); // Assign a VT_I2, or a VT_BOOL
_variant_t& operator=(long lSrc) throw(_com_error); // Assign a VT_I4, a VT_ERROR or a VT_BOOL
_variant_t& operator=(float fltSrc) throw(_com_error); // Assign a VT_R4
_variant_t& operator=(double dblSrc) throw(_com_error); // Assign a VT_R8, or a VT_DATE
_variant_t& operator=(const CY& cySrc) throw(_com_error); // Assign a VT_CY
_variant_t& operator=(const _bstr_t& bstrSrc) throw(_com_error); // Assign a VT_BSTR
_variant_t& operator=(const wchar_t* pSrc) throw(_com_error); // Assign a VT_BSTR
_variant_t& operator=(const char* pSrc) throw(_com_error); // Assign a VT_BSTR
_variant_t& operator=(IDispatch* pSrc) throw(_com_error); // Assign a VT_DISPATCH
_variant_t& operator=(bool bSrc) throw(_com_error); // Assign a VT_BOOL
_variant_t& operator=(IUnknown* pSrc) throw(_com_error); // Assign a VT_UNKNOWN
_variant_t& operator=(const DECIMAL& decSrc) throw(_com_error); // Assign a VT_DECIMAL
_variant_t& operator=(BYTE bSrc) throw(_com_error); // Assign a VT_UI1
// Comparison operations
//
bool operator==(const VARIANT& varSrc) const throw(_com_error);
bool operator==(const VARIANT* pSrc) const throw(_com_error);
bool operator!=(const VARIANT& varSrc) const throw(_com_error);
bool operator!=(const VARIANT* pSrc) const throw(_com_error);
// Low-level operations
//
void Clear() throw(_com_error);
void Attach(VARIANT& varSrc) throw(_com_error);
VARIANT Detach() throw(_com_error);
void ChangeType(VARTYPE vartype, const _variant_t* pSrc = NULL) throw(_com_error);
void SetString(const char* pSrc) throw(_com_error); // used to set ANSI string
};
热心网友
时间:2022-06-28 23:37
_variant_t和_bstr_t这两个类分别封装并管理VARIANT和BSTR这两种数据类型,VARIANT和BSTR这两种类型是COM中使用的数据类型。为了C++中的变量应用到ADO编程中,只能进行数据类型的转换。_variant_t和_bstr_t这两个类,就可以方便的把C++类型变量转换成COM中的变量了
参考资料:http://zhidao.baidu.com/question/86443910.html?si=2
热心网友
时间:2022-06-28 23:37
在sys/types.h头文件中