home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / oledb / sampclnt / sampclnt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-12  |  5.9 KB  |  316 lines

  1. //--------------------------------------------------------------------
  2. // Microsoft OLE DB Sample Consumer
  3. // (C) Copyright 1995 - 1998 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File name: SAMPCLNT.H
  6. //
  7. //      Declaration file for a simple OLE DB consumer.
  8. //
  9. //      See OLE DB SDK Guide for information on building and running 
  10. //        this sample, as well as notes concerning the implementation of 
  11. //        a simple OLE DB consumer.
  12. //
  13.  
  14.  
  15. #define WIN32_LEAN_AND_MEAN        // avoid the world
  16. #define INC_OLE2                // tell windows.h to always include ole2.h
  17.  
  18. #include <windows.h>            // 
  19. #include <ole2ver.h>            // OLE2.0 build version
  20. #include <cguid.h>                // GUID_NULL
  21. #include <stdio.h>                // vsnprintf, etc.
  22. #include <stddef.h>                // offsetof
  23. #include <stdarg.h>                // va_arg
  24. #include <time.h>                // time
  25. #include <assert.h>                // assert
  26. #include <conio.h>                // _getch()
  27.  
  28. //    OLE DB headers
  29. #include <oledb.h>
  30. #include <oledberr.h>
  31.  
  32.  
  33. //-----------------------------------
  34. //    constants 
  35. //------------------------------------
  36.  
  37. // Alignment for placement of each column within memory.
  38. // Rule of thumb is "natural" boundary, i.e. 4-byte member should be
  39. // aligned on address that is multiple of 4.
  40. // Worst case is double or __int64 (8 bytes).
  41. #define COLUMN_ALIGNVAL 8
  42.  
  43. #define MAX_GUID_STRING     42    // size of a GUID, in characters
  44. #define MAX_NAME_STRING     60  // size of DBCOLOD name or propid string
  45. #define MAX_BINDINGS       100    // size of binding array
  46. #define NUMROWS_CHUNK       20    // number of rows to grab at a time
  47. #define DEFAULT_CBMAXLENGTH 40    // cbMaxLength for binding
  48.  
  49.  
  50. // for pretty printing
  51. #define PRETTYPRINT_MAXTOTALWIDTH    200     // max entire width of printed row 
  52. #define PRETTYPRINT_MINCOLWIDTH     6        // min width of printed column
  53.  
  54.  
  55.  
  56. //-----------------------------------
  57. //    macros 
  58. //------------------------------------
  59.  
  60.  
  61. // Rounding amount is always a power of two.
  62. #define ROUND_UP(   Size, Amount ) (((DWORD)(Size) +  ((Amount) - 1)) & ~((Amount) - 1))
  63.  
  64. #ifndef  NUMELEM
  65. # define NUMELEM(p) (sizeof(p)/sizeof(*p))
  66. #endif
  67.  
  68. // usage: DUMPLINE();
  69. #define DUMP_ERROR_LINENUMBER() DumpErrorMsg("Error at file: %s  line: %u  \n", __FILE__, __LINE__)
  70.  
  71.  
  72.  
  73. //-----------------------------------
  74. //    type and structure definitions 
  75. //------------------------------------
  76.  
  77. // How to lay out each column in memory.
  78. // Issue? we depend on the dwLength field being first in memory (see assert)
  79. // is there another way to handle this?
  80. struct COLUMNDATA 
  81.     {
  82.     DWORD        dwLength;    // length of data (not space allocated)
  83.     DWORD        dwStatus;    // status of column
  84.     BYTE        bData[1];    // data here and beyond
  85.     };
  86.  
  87.  
  88. // Lists of value/string pairs.
  89. typedef struct {
  90.     DWORD dwFlag;
  91.     char *szText;
  92. } Note;
  93.  
  94. #define NOTE(s) { (DWORD) s, #s }
  95.  
  96.  
  97.  
  98.  
  99. //-----------------------------------
  100. //    global variables and functions that are private to the file 
  101. //------------------------------------
  102.  
  103.  
  104. DEFINE_GUID(CLSID_SampProv, 0xE8CCCB79L,0x7C36,0x101B,0xAC,0x3A,0x00,0xAA,0x00,0x44,0x77,0x3D);
  105. DEFINE_GUID(DBINIT_OPT_SAMPPROV_PATH, 0xe9fbaf50, 0xd402, 0x11ce, 0xbe, 0xdc, 0x0, 0xaa, 0x0, 0xa1, 0x4d, 0x7d);
  106.  
  107. extern IMalloc*    g_pIMalloc;
  108. extern FILE*    g_fpLogFile;
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115. // function prototypes, sampclnt.cpp
  116.  
  117. void main();
  118.  
  119. HRESULT DoTests();
  120.  
  121.  
  122. HRESULT GetSampprovDataSource
  123.     (
  124.     IDBInitialize**    ppIDBInitialize_out
  125.     );
  126.  
  127.  
  128. HRESULT GetDBSessionFromDataSource
  129.     (
  130.     IDBInitialize*      pIDBInitialize,     
  131.     IOpenRowset**       ppIOpenRowset_out   
  132.     );
  133.  
  134.  
  135. HRESULT GetRowsetFromDBSession
  136.     (
  137.     IOpenRowset*   pIOpenRowset,   
  138.     LPWSTR         pwszTableName,      
  139.     IRowset**      ppIRowset_out       
  140.     );
  141.  
  142.     
  143. HRESULT GetDataFromRowset
  144.     (
  145.     IRowset*    pIRowset
  146.     );
  147.     
  148.     
  149. HRESULT GetColumnsInfo
  150.     (
  151.     IRowset*        pIRowset,
  152.     ULONG*            pcCol_out,
  153.     DBCOLUMNINFO**    ppColumnInfo_out,
  154.     WCHAR**            ppStringsBuffer_out
  155.     );
  156.  
  157.    
  158. HRESULT SetupBindings
  159.     (
  160.     ULONG             cCol,
  161.     DBCOLUMNINFO*    pColumnInfo,
  162.     DBBINDING*        rgBind_out,
  163.     ULONG*            cBind_out,
  164.     ULONG*          pcMaxRowSize_out
  165.     );
  166.  
  167.     
  168. HRESULT CreateAccessor
  169.     (
  170.     IRowset*    pIRowset,
  171.     DBBINDING*    rgBind,
  172.     ULONG        cBind,
  173.     HACCESSOR*    phAccessor_out
  174.     );
  175.  
  176.     
  177. HRESULT GetData
  178.     (
  179.     IRowset*    pIRowset,
  180.     ULONG       cMaxRowSize,
  181.     HACCESSOR    hAccessor,
  182.     DBBINDING*        rgBind,            // needed for pretty printing
  183.     ULONG            cBind,            // for pretty printing
  184.     DBCOLUMNINFO*    pColumnInfo,     // for pretty printing
  185.     ULONG            cCol            // for pretty printing        
  186.     );
  187.  
  188.  
  189. HRESULT CleanupRowset
  190.     (
  191.     IRowset*    pIRowset,
  192.     HACCESSOR     hAccessor
  193.     );
  194.     
  195.     
  196.     
  197. // function prototypes, dump.cpp
  198.  
  199. void DumpErrorMsg
  200.     (
  201.     const char* format,
  202.     ...
  203.     );
  204.  
  205.  
  206. void DumpStatusMsg
  207.     (
  208.     const char* format,
  209.     ...
  210.     );
  211.  
  212.  
  213. HRESULT DumpErrorHResult
  214.     (
  215.     HRESULT      hr_return,
  216.     const char  *format,
  217.     ... 
  218.     );
  219.  
  220.  
  221. void DumpColumnsInfo
  222.     (
  223.     DBCOLUMNINFO* pColInfo,
  224.     ULONG          cCol
  225.     );
  226.  
  227.  
  228.  
  229. void WriteColumnInfo
  230.     (
  231.     FILE*            fp,
  232.     DBCOLUMNINFO*    p 
  233.     );
  234.     
  235.  
  236. char* GetNoteString
  237.     ( 
  238.     Note * rgNote, 
  239.     int    cNote,
  240.     DWORD  dwValue 
  241.     );
  242.  
  243.  
  244.     
  245. char* GetNoteStringBitvals
  246.     (
  247.     Note*     rgNote,
  248.     int     cNote,
  249.     DWORD   dwValue 
  250.     );
  251.  
  252.  
  253. ULONG CalcPrettyPrintMaxColWidth
  254.     (
  255.     DBBINDING*    rgBind,
  256.     ULONG       cBind
  257.     );
  258.  
  259.     
  260. void DumpColumnHeadings
  261.     (
  262.     DBBINDING*        rgBind, 
  263.     ULONG            cBind, 
  264.     DBCOLUMNINFO*     pColInfo, 
  265.     ULONG            cCol,
  266.     ULONG            cMaxColWidth
  267.     );
  268.  
  269.  
  270. WCHAR* LookupColumnName
  271.     (
  272.     DBCOLUMNINFO*    rgColInfo,
  273.     ULONG             cCol,
  274.     ULONG             iCol 
  275.     );
  276.  
  277. void DumpRow
  278.     (
  279.     DBBINDING*     rgBind,
  280.     ULONG        cBind,
  281.     ULONG        cMaxColWidth,
  282.     BYTE*         pData
  283.     );
  284.  
  285.  
  286. void PrintColumn
  287.     (
  288.     COLUMNDATA    *pColumn,
  289.     DBBINDING     *rgBind,
  290.     ULONG          iBind,
  291.     ULONG          cMaxColWidth 
  292.     );
  293.  
  294.     
  295. void tfprintf
  296.     (
  297.     FILE*        fp,
  298.     const char* format,
  299.     ... 
  300.     );
  301.  
  302.  
  303. void tvfprintf
  304.     (
  305.     FILE*        fp,
  306.     const char* format,
  307.     va_list        argptr 
  308.     );
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.