home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / ado / employee / emp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-13  |  2.4 KB  |  124 lines

  1. // Emp.h : main header file for the EMP application
  2. //
  3.  
  4. #include <objbase.h>
  5. #include <afxdisp.h>
  6. #include <tchar.h>            // Unicode
  7. #include <adoid.h>            // ADO C++ header     
  8. #include <adoint.h>            // ADO C++ header
  9.  
  10. #ifndef __AFXWIN_H__
  11.     #error include 'stdafx.h' before including this file for PCH
  12. #endif
  13.  
  14. #include "resource.h"        // main symbols
  15.  
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CEmpApp:
  19. // See Emp.cpp for the implementation of this class
  20. //
  21.  
  22. class CEmpApp : public CWinApp
  23. {
  24. public:
  25.     CEmpApp();
  26.  
  27. // Overrides
  28.     // ClassWizard generated virtual function overrides
  29.     //{{AFX_VIRTUAL(CEmpApp)
  30.     public:
  31.     virtual BOOL InitInstance();
  32.     //}}AFX_VIRTUAL
  33.  
  34. // Implementation
  35.  
  36.     //{{AFX_MSG(CEmpApp)
  37.         // NOTE - the ClassWizard will add and remove member functions here.
  38.         //    DO NOT EDIT what you see in these blocks of generated code !
  39.     //}}AFX_MSG
  40.     DECLARE_MESSAGE_MAP()
  41. };
  42.  
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45.  
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // Conversion macros/inline functions - Variant 
  49.                   
  50. inline CString VTOCSTR(VARIANT *v)
  51. {
  52.     if(v->vt==VT_BSTR)
  53.     {
  54.         CString str((LPCWSTR)v->bstrVal);
  55.         return str;
  56.     }
  57.     else
  58.     {
  59.         return CString("");
  60.     }
  61. }
  62.  
  63. #define VTOLONG(v)    ((v).vt==VT_I4 ? (LONG)(v).lVal:0L)
  64. #define VTODATE(v)    ((v).vt==VT_DATE ? (CTime)(v).iVal:0L)
  65.  
  66.  
  67. class CVar : public VARIANT
  68.     {
  69. public:
  70.     CVar()
  71.         {
  72.         VariantInit(this);
  73.         }
  74.     CVar(VARTYPE vt, SCODE scode = 0)
  75.         {
  76.         VariantInit(this);
  77.         this->vt = vt;
  78.         this->scode = scode;
  79.         }
  80.     CVar(VARIANT var)
  81.         {
  82.         *this = var;
  83.         }
  84.     ~CVar()
  85.         {
  86.         VariantClear(this);
  87.         }
  88.  
  89.     // ASSIGNMENT OPS.
  90.     CVar & operator=(PCWSTR pcwstr)
  91.         {
  92.         VariantClear(this);
  93.         if (NULL == (this->bstrVal = SysAllocStringLen(pcwstr, wcslen(pcwstr))))
  94.             throw E_OUTOFMEMORY;
  95.         this->vt = VT_BSTR;
  96.         return *this;
  97.         }
  98.     CVar & operator=(VARIANT var)
  99.         {
  100.         HRESULT hr;
  101.  
  102.         VariantClear(this);
  103.         if (FAILED(hr = VariantCopy(this, &var)))
  104.             throw hr;
  105.         return *this;
  106.         }
  107.  
  108.     // CAST OPS.
  109.     // doesn't change type. only returns BSTR if variant is of type
  110.     // bstr. asserts otherwise.
  111.     operator BSTR() const
  112.     {
  113.         if(VT_BSTR == this->vt)
  114.             return this->bstrVal;
  115.         else
  116.             return NULL;
  117.     }
  118.  
  119.     HRESULT Clear()
  120.     {
  121.         return VariantClear(this);
  122.     }
  123. };
  124.