A useful Variant class when using the ADO to operate the database!

zhaozj2021-02-11  229

Inline cstring vtocstr (V-> vt == vt_bstr) {CSTRING STR ((lpcwstr) V-> BStrVal); Return Str;} else {return cstring (");}}

#define vtolong (v) ((v) .vt == vt_i4? (line) (v) .lval: 0L) #define vtodate (v) ((v) .vt == vt_date? (ctime) (v). Ival: 0L)

Class CVAR: PUBLIC VARIANT {public: cvar () {variantinit (this);} cvar (VARTYPE VT, Scode Scode = 0) {variantinit (this); this-> vt = vt; this-> scode = scode;} CVAR (Variant var) {* this = var;} ~ cvar () {variantClear (this);

// ASSIGNMENT OPS CVar & operator = (PCWSTR pcwstr) {VariantClear (this);. If (NULL == (this-> bstrVal = SysAllocStringLen (pcwstr, wcslen (pcwstr)))) throw E_OUTOFMEMORY; this-> vt = VT_BSTR ; Return * this;} cvar & operator = (variant var) {HRESULT HR;

VariantClear (this); if (Failed (HR = Variantcopy (this, & var))) "Return * this;}

. Operator str () const {if (vt_bs == this-> vt) Return this-> bstrval; else return null;}

Operator long () const {if (vt_i4 == this-> vt) Return this-> lval; else return null;} operator date () const {if (vt_date == this-> vt) Return this-> Date; Else Return null;} Operator cy () const {Colecurrency Cynull; cynull.setcurrency (0); if (vt_cy == this-> vt) return this-> cyval; else returnal ()} HRESULT CLEAR () {Return Variant Clear () {Return Variant Clear ()} HRESULT CLEAR (this);}};

This is a class I organizes and enhanced in MSDN, I hope to help the ADO operation database!

转载请注明原文地址:https://www.9cbs.com/read-4279.html

New Post(0)