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

📄 common.h

📁 用测试OLE DB提供者的一个程序。能够测试出OEL DB提供者到底实现了哪些接口?很灵的。
💻 H
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------
// Microsoft OLE DB RowsetViewer
// Copyright (C) 1994 - 1998 By Microsoft Corporation.
//
// @doc
//
// @module COMMON.H
//
//-----------------------------------------------------------------------------------

#ifndef _COMMON_H_
#define _COMMON_H_


///////////////////////////////////////////////////////////////
// Defines
//
///////////////////////////////////////////////////////////////

//We want type checking on Window Handles
#define STRICT


enum EXCEPTION_SOURCE
{
	EXCEPTION_PROVIDER,
	EXCEPTION_APPLICATION,
};

enum SOURCE
{
	//Object Source
	DATASOURCE,
	DATASOURCEINIT,
	DATASOURCEADMIN,
	SESSION,
	COMMAND,
	ROWSET,
	ENUMERATOR,
	TRANSACTION,

	TRANSACTIONLOCAL,
	TRANSACTIONJOIN,
	MTSTRANSACTION,

	//Methods Source
	ROWSET_SETDATA,
	ROWSET_INSERTROW,
};


enum CONV_FLAGS
{
	CONV_NONE			= 0x00000000,
	CONV_VARBOOL		= 0x00000001,
	CONV_ALPHABOOL		= 0x00000002,
	CONV_HEX			= 0x00000004,
	CONV_OCTAL			= 0x00000008,
	CONV_DECIMAL		= 0x00000010,
	CONV_BINARY			= 0x00000020,
};


///////////////////////////////////////////////////////////////
// Includes
//
///////////////////////////////////////////////////////////////
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>	//InitCommonControls

#include <stddef.h>
#include <stdio.h>
#include <limits.h>
#include <wchar.h>
#include <ocidl.h>		//IConnectionPoint

#include "resource.h"

#include "oledb.h"		//OLE DB Header 
#include "oledberr.h"	//OLE DB Errors
#include "msdasc.H"		//OLE DB ServiceComponents

#include "Error.h"		//RowsetViewer file


////////////////////////////////////////////////////////////////////////////
// Windows Defines
//
////////////////////////////////////////////////////////////////////////////
#define CHECK_MEMORY(pv)	if(!pv) { OutOfMemory(NULL); goto CLEANUP; }

//Dialog Box procedures want to know if you handled the MSG
//or not.  If you do, thenit just returns, if not then it calls
//the default windialog procedure to try and handle it
const BOOL HANDLED_MSG	 = TRUE;
const BOOL UNHANDLED_MSG = FALSE;
#define LVM_ERR (-1)


///////////////////////////////////////////////////////////////
// Defines
//
///////////////////////////////////////////////////////////////
#define NUMELE(rgEle) (sizeof(rgEle) / sizeof(rgEle[0]))
#define __WIDESTRING(str) L##str
#define WIDESTRING(str) __WIDESTRING(str)

//FindLeaks
#if defined(_DEBUG) && defined(_IMALLOC_SPY)
#define DISP_FILE_LINE	TRACE("File '%s', Line '%lu'\n", __FILE__, __LINE__)
#else
#define DISP_FILE_LINE
#endif //_DEBUG && _IMALLOCSPY

//IMalloc Wrappers
#define SAFE_ALLOC(pv, type, cb)		{ DISP_FILE_LINE; pv = (type*)CoTaskMemAlloc((cb)*sizeof(type)); CHECK_MEMORY(pv);			}
#define SAFE_REALLOC(pv, type, cb)		{ DISP_FILE_LINE; pv = (type*)CoTaskMemRealloc(pv, (cb)*sizeof(type)); CHECK_MEMORY(pv);	}
#define SAFE_SYSALLOC(pv, bstr)			{ pv = SysAllocString(bstr); CHECK_MEMORY(pv);												}		

#define SAFE_FREE(pv)					{ CoTaskMemFree(pv); pv = NULL;						}
#define SAFE_SYSFREE(bstr)				{ SysFreeString(bstr); bstr = NULL;					}

//IUnknown->Release Wrapper
#define SAFE_ADDREF(pv)					if(pv) { (pv)->AddRef();							}
#define SAFE_RELEASE(pv)				if(pv) { (pv)->Release(); (pv) = NULL;				}  
#define SAFE_DELETE(pv)					if(pv) { delete pv; pv = NULL;	}  
																									
//Test macros																					
#define CHECKC(hr)						{ if(!(hr)) { ASSERT(!#hr); goto CLEANUP;			} }

//Exception Handling
#define PROVEXCEPTION(hWnd)				do { if(1 == HandleException(hWnd, EXCEPTION_PROVIDER,		WIDESTRING(__FILE__), __LINE__)) _DbgBreak(); } while (0)
#define APPEXCEPTION(hWnd)				do { if(1 == HandleException(hWnd, EXCEPTION_APPLICATION,	WIDESTRING(__FILE__), __LINE__)) _DbgBreak(); } while (0)

//Excpetion Handling (Try, Catch macros)
#ifdef USE_EXCEPTIONS
#define EXC_BEGIN						try {
#define EXC_END_PROV(hWnd)				} catch(...) { PROVEXCEPTION(hWnd);			} 
#define EXC_END_PROV_(hWnd, stmt)		} catch(...) { PROVEXCEPTION(hWnd);	 stmt;	} 
#define EXC_END(hWnd)					} catch(...) { APPEXCEPTION(hWnd);			} 
#define EXC_END_(hWnd, stmt)			} catch(...) { APPEXCEPTION(hWnd);	stmt;	} 
#else  //USE_EXCEPTIONS
#define EXC_BEGIN						
#define EXC_END_PROV(hWnd)				
#define EXC_END_PROV_(hWnd, stmt)		
#define EXC_END(hWnd)					
#define EXC_END_(hWnd, stmt)			

#endif //USE_EXCEPTIONS

//Error Checking
#define TESTC(hr)						{ if(FAILED(hr)) goto CLEANUP;				}
#define TESTC_(hr, hrExpected)			{ if((hr) != (hrExpected)) goto CLEANUP;	}

//Error Checking (with Exception Handling)
#define EXC_TEST(hr)					{ EXC_BEGIN hr;										EXC_END(NULL)					}
#define EXC_TESTC(hr)					{ EXC_BEGIN if(FAILED(hr)) goto CLEANUP;			EXC_END_(NULL, goto CLEANUP)	}
#define EXC_TESTC_(hr, hrExpected)		{ EXC_BEGIN if((hr) != (hrExpected)) goto CLEANUP;	EXC_END_(NULL, goto CLEANUP)	}

//Error Checking (with Exception Handling, and ErrorInfo checking)
//These Macros are used for calling all OLE DB Methods...
#define XTEST(hWnd, hr)					{ EXC_BEGIN DisplayAllErrors(hWnd, hr, WIDESTRING(__FILE__), __LINE__);											EXC_END_PROV(hWnd)					}
#define XTEST_(hWnd, hr, hrExpected)	{ EXC_BEGIN DisplayAllErrors(hWnd, hr, hrExpected, WIDESTRING(__FILE__), __LINE__);								EXC_END_PROV(hWnd)					}
#define XTESTC(hWnd, hr)				{ EXC_BEGIN if(FAILED(DisplayAllErrors(hWnd, hr, WIDESTRING(__FILE__), __LINE__))) goto CLEANUP;				EXC_END_PROV_(hWnd, goto CLEANUP)	}
#define XTESTC_(hWnd, hr, hrExpected)	{ EXC_BEGIN if(FAILED(DisplayAllErrors(hWnd, hr, hrExpected, WIDESTRING(__FILE__), __LINE__))) goto CLEANUP;	EXC_END_PROV_(hWnd, goto CLEANUP)	}


///////////////////////////////////////////////////////////////
// Defines
//
///////////////////////////////////////////////////////////////
#define MAX_QUERY_LEN			4096
#define MAX_NAME_LEN			256

#define MAX_COL_SIZE		    5000
#define MAX_BLOCK_SIZE			2000
#define MAX_OPENROWS			 256

//Displays values like VALUE as   VALUE , L"VALUE"
#define VALUE_WCHAR(value) value, L#value
#define VALUE_CHAR(value) value, #value

#define EOL		 '\0'
#define wEOL	L'\0'

#define ON		TRUE
#define OFF		FALSE


///////////////////////////////////////////////////////////////////
// Accessor / Binding 
//
///////////////////////////////////////////////////////////////////
//STATUS helpers, for locating obStatus offsets in the bindings
#define STATUS_IS_BOUND(Binding)    ( (Binding).dwPart & DBPART_STATUS )
#define BINDING_STATUS(Binding, pv) (*(ULONG*)((BYTE*)(pv) + (Binding).obStatus))

//LENGTH helpers, for locating obLength offsets in the bindings
#define LENGTH_IS_BOUND(Binding)    ( (Binding).dwPart & DBPART_LENGTH )
#define BINDING_LENGTH(Binding, pv) (*(ULONG*)((BYTE*)(pv) + (Binding).obLength))

//VALUE helpers, for locating obValue offsets in the bindings
#define VALUE_IS_BOUND(Binding)     ( (Binding).dwPart & DBPART_VALUE )
#define BINDING_VALUE(Binding, pv)  (*(ULONG*)((BYTE*)(pv) + (Binding).obValue ))

//ROUNDUP on all platforms pointers must be aligned properly
#define ROUNDUP_AMOUNT	8
#define ROUNDUP_(size,amount)		(((ULONG)(size)+((amount)-1))&~((amount)-1))
#define ROUNDUP(size)				ROUNDUP_(size, ROUNDUP_AMOUNT)

#define ENABLE_BIT(dwValue, dwBit, fEnable) ((fEnable) ? (dwValue) |= (dwBit) : (dwValue) &= ~(dwBit))

BOOL FreeBindings(ULONG* pcBindings, DBBINDING** prgBindings);
BOOL FreeBindingData(ULONG cBindings, DBBINDING* rgBindings, void* pData);


////////////////////////////////////////////////////////////////////////////
// DBTYPE functions
//
////////////////////////////////////////////////////////////////////////////
BOOL IsFixedType(DBTYPE wType);
BOOL IsVariableType(DBTYPE wType);
BOOL IsNumericType(DBTYPE wType);

⌨️ 快捷键说明

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