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

📄 cdialog.cpp

📁 用测试OLE DB提供者的一个程序。能够测试出OEL DB提供者到底实现了哪些接口?很灵的。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		//upto the max size of the array
		va_start(marker, pszFmt);
		_vsnprintf(szBuffer, MAX_QUERY_LEN, pszFmt, marker);
		va_end(marker);

		//Make sure there is a NULL Terminator, vsnwprintf will not copy
		//the terminator if length==MAX_NAME_LEN
		szBuffer[MAX_QUERY_LEN-1] = EOL;	
		
		//Delegate 				  
		OutputText(LB_APPEND, "%s", szBuffer);
	}
	return S_OK;
}


//////////////////////////////////////////////////////////////////
// ULONG CListBox::OutputAddRef
//
//////////////////////////////////////////////////////////////////
ULONG CListBox::OutputAddRef(IUnknown* pIUnknown, CHAR* pszFmt)
{
	ULONG ulRefCount = 0;

	//AddRef
	if(pIUnknown)
	{
		ulRefCount = pIUnknown->AddRef();

		//Only if the user is interested in this message
		if(GetOptionsObj()->m_dwNotifyOpts & NOTIFY_ADDREF)
		{
			//Delegate 				  
			OutputText(LB_APPEND, "%s::AddRef() - %d", pszFmt ? pszFmt : "IUnknown", ulRefCount);
			m_iNotificationIndex = LB_APPEND;
		}
	}

	return ulRefCount;
}


//////////////////////////////////////////////////////////////////
// ULONG CListBox::OutputRelease
//
//////////////////////////////////////////////////////////////////
ULONG CListBox::OutputRelease(IUnknown** ppIUnknown, CHAR* pszFmt, ULONG ulExpectedRefCount)
{
	ASSERT(ppIUnknown);
	ULONG ulRefCount = 0;

	//Release
	if(*ppIUnknown)
	{
		//PreNotification
		//We actually nned to out a pre and a post for IUnknown::Release
		//Since IRowset::Release will send a notfication!  ROWSET_RELEASE
		if(GetOptionsObj()->m_dwNotifyOpts & NOTIFY_RELEASE)
			m_iNotificationIndex = OutputText(LB_APPEND, "%s::Release() - %d", pszFmt ? pszFmt : "IUnknown", ulRefCount);
		
		//Actual Release and NULL pointer
		ulRefCount = (*ppIUnknown)->Release();
		*ppIUnknown = NULL;

		//Only if the user is interested in this message
		if(GetOptionsObj()->m_dwNotifyOpts & NOTIFY_RELEASE)
		{
			//Delegate 				  
			OutputText(m_iNotificationIndex, "%s::Release() - %d", pszFmt ? pszFmt : "IUnknown", ulRefCount);
			m_iNotificationIndex = LB_APPEND;
		}

		//Display Errors if RefCount is not what is expected...
		if(ulExpectedRefCount==0 && ulRefCount!=0)
		{
			DisplayRefCountErrors(/*m_hWnd*/NULL, pszFmt, ulRefCount, ulExpectedRefCount);
		}
	}

	return ulRefCount;
}


//////////////////////////////////////////////////////////////////
// HRESULT CListBox::OutputQI
//
//////////////////////////////////////////////////////////////////
HRESULT CListBox::OutputQI(IUnknown* pIUnknown, REFIID riid, IUnknown** ppIUnknown, CHAR* pszFmt)
{
	ASSERT(ppIUnknown);
	HRESULT hr = E_NOINTERFACE;

	if(pIUnknown)
	{
		//QueryInterface
		hr = pIUnknown->QueryInterface(riid, (void**)ppIUnknown);

		//Only if the user is interested in this message
		if(GetOptionsObj()->m_dwNotifyOpts & NOTIFY_QUERYINTEFACE)
		{
			//Delegate 				  
			OutputText(LB_APPEND, "%s::QueryInterface(%s, &0x%08x) - %S", pszFmt ? pszFmt : "IUnknown", GetInterfaceName(riid), *ppIUnknown, GetErrorName(hr));
			m_iNotificationIndex = LB_APPEND;
		}
	}
	
	return hr;
}


//////////////////////////////////////////////////////////////////
// HRESULT CListBox::OutputPreMethod
//
//////////////////////////////////////////////////////////////////
HRESULT CListBox::OutputPreMethod(CHAR* pszFmt, ...)
{
	ASSERT(pszFmt);
	
	//Only if the user is interested in this message
	if(GetOptionsObj()->m_dwNotifyOpts & NOTIFY_METHODCALLS)
	{
		va_list		marker;
		CHAR		szBuffer[MAX_QUERY_LEN];

		// Use format and arguements as input
		//This version will not overwrite the stack, since it only copies
		//upto the max size of the array
		va_start(marker, pszFmt);
		_vsnprintf(szBuffer, MAX_QUERY_LEN, pszFmt, marker);
		va_end(marker);

		//Make sure there is a NULL Terminator, vsnwprintf will not copy
		//the terminator if length==MAX_NAME_LEN
		szBuffer[MAX_QUERY_LEN-1] = EOL;	
		
		//Delegate 				  
		m_iNotificationIndex = OutputText(LB_APPEND, "%s", szBuffer);
	}
	
	//Set Timings
	if(GetOptionsObj()->m_dwNotifyOpts & NOTIFY_TIMINGS)
	{
		if(!QueryPerformanceCounter(&m_timerValue))
			m_timerValue.QuadPart = 0;
	}
	return S_OK;
}


//////////////////////////////////////////////////////////////////
// HRESULT CListBox::OutputPostMethod
//
//////////////////////////////////////////////////////////////////
HRESULT CListBox::OutputPostMethod(HRESULT hrActual, CHAR* pszFmt, ...)
{
	ASSERT(pszFmt);
	
	//Only if the user is interested in this message
	if(GetOptionsObj()->m_dwNotifyOpts & NOTIFY_METHODCALLS)
	{
		va_list		marker;
		CHAR		szBuffer[MAX_QUERY_LEN];

		// Use format and arguements as input
		//This version will not overwrite the stack, since it only copies
		//upto the max size of the array
		va_start(marker, pszFmt);
		_vsnprintf(szBuffer, MAX_QUERY_LEN, pszFmt, marker);
		va_end(marker);

		//Make sure there is a NULL Terminator, vsnwprintf will not copy
		//the terminator if length==MAX_NAME_LEN
		szBuffer[MAX_QUERY_LEN-1] = EOL;	
		
		//Delegate 				  
		if(GetOptionsObj()->m_dwNotifyOpts & NOTIFY_TIMINGS && m_timerValue.QuadPart)
		{
			//Time Calculation
			double dTime = 0;
			LARGE_INTEGER timerValue;
			if(QueryPerformanceCounter(&timerValue))
				dTime = (double)(timerValue.QuadPart - m_timerValue.QuadPart) / (double)m_timerFreq.QuadPart;
			
			//Output Notiifcation
			OutputText(m_iNotificationIndex, "%s - %S - %.06f seconds", szBuffer, GetErrorName(hrActual), dTime);

			//Reset Timings
			m_timerValue.QuadPart = 0;
		}
		else
		{
			OutputText(m_iNotificationIndex, "%s - %S", szBuffer, GetErrorName(hrActual));
		}
		
		m_iNotificationIndex = LB_APPEND;
	}

	return hrActual;
}


////////////////////////////////////////////////////////////////
// CListBox::ClearNotifications
//
/////////////////////////////////////////////////////////////////
HRESULT CListBox::ClearNotifications()
{
	//Select all the Text and Cut it...
	//This method allows the text to be undone...
//	SendMessage(m_hWnd, EM_SETSEL, 0, -1);
//	SendMessage(m_hWnd, WM_CUT, 0, 0);

	//Since this window is ReadOnly, we can't Cut it, we can only delete...
	SendMessage(m_hWnd, WM_SETTEXT, 0, (LPARAM)"");
	m_pCMainWindow->m_fWarnMaxEditBuffer = TRUE;
	return S_OK;
}


////////////////////////////////////////////////////////////////
// CConnectDlg::CConnectDlg
//
/////////////////////////////////////////////////////////////////
CConnectDlg::CConnectDlg(HWND hWnd, HINSTANCE hInst, CMainWindow* pCMainWindow)
	: CDialogBase(hWnd, hInst)
{
	ASSERT(pCMainWindow);
	CHAR szBuffer[MAX_NAME_LEN+1];

	//Data
	m_pCMainWindow	= pCMainWindow;
	m_pCListBox		= new CListBox(NULL, hInst, pCMainWindow);
	m_pCEnum		= new CEnum(NULL, pCMainWindow, m_pCListBox);
	m_pCPropDlg		= new CPropDlg(NULL, hInst, pCMainWindow, m_pCListBox);

	//Create CListBox window, (hidden - not WS_VISIBILE)
	m_pCListBox->Display(m_pCMainWindow->m_hWnd, 0, 0, 75, 75, WS_BORDER, this);

	//Enum
	m_pIUnknown				= NULL;
	m_pIParseDisplayName	= NULL;
	memset(&m_EnumInfo, 0, sizeof(ENUMINFO));
	wcscpy(m_EnumInfo.wszName, L"MSDASQL");

	//Properties
	m_cPropSets			= 0;
	m_rgPropSets		= NULL;

	m_hWndProvider		= NULL;
	m_hWndProperties	= NULL;
	m_hWndSecurity		= NULL;
	m_hWndOptions		= NULL;
	m_hWndTrace			= NULL;

	//ServiceComponents
	m_pIDataInitialize		= NULL;
	m_pIDBPromptInitialize	= NULL;

	//Reset all Defaults
	ResetDefaults();

	//Load Configuration Name, so we know which configuration is the default
	GetRegEntry(HKEY_ROWSETVIEWER, szCONFIG_KEY, "DefaultConfig",	m_szConfigName, MAX_NAME_LEN);

	//Load Recent Configurations
	for(ULONG i=0; i<MAX_RECENTCONFIGS; i++)
	{
		if(FAILED(GetRegEnumValue(HKEY_ROWSETVIEWER, szRECENTCONFIG_KEY, i, szBuffer, MAX_NAME_LEN)))
			break;
		
		m_listConfigs.AddTail(strDuplicate(szBuffer));
	}

	//Load Recent File
	for(i=0; i<MAX_RECENTFILES; i++)
	{
		if(FAILED(GetRegEnumValue(HKEY_ROWSETVIEWER, szRECENTFILE_KEY, i, szBuffer, MAX_NAME_LEN)))
			break;
		
		m_listFiles.AddTail(strDuplicate(szBuffer));
	}

	//Load the Values for this Configuration
	LoadDefaults();
}


////////////////////////////////////////////////////////////////
// CConnectDlg::~CConnectDlg
//
/////////////////////////////////////////////////////////////////
CConnectDlg::~CConnectDlg()
{
	//The MDIChild takes care of cleaning up itself and the DataSource
	SAFE_DELETE(m_pCEnum);
	SAFE_DELETE(m_pCPropDlg);
	SAFE_DELETE(m_pCListBox);

	SAFE_RELEASE(m_pIUnknown);
	SAFE_RELEASE(m_pIParseDisplayName);
	FreeProperties(&m_cPropSets, &m_rgPropSets);

	//Release ServiceComponents
	SAFE_RELEASE(m_pIDataInitialize);
	SAFE_RELEASE(m_pIDBPromptInitialize);

	//Save Recent Configs
	DelRegEntry(HKEY_ROWSETVIEWER, szRECENTCONFIG_KEY);
	while(!m_listConfigs.IsEmpty())
	{
		CHAR* pszConfigName = m_listConfigs.RemoveHead();
		if(FAILED(SetRegEntry(HKEY_ROWSETVIEWER, szRECENTCONFIG_KEY, pszConfigName, MAX_NAME_LEN)))
			break;

		SAFE_FREE(pszConfigName);
	}

	//Save Recent Files
	DelRegEntry(HKEY_ROWSETVIEWER, szRECENTFILE_KEY);
	while(!m_listFiles.IsEmpty())
	{
		CHAR* pszFileName = m_listFiles.RemoveHead();
		if(FAILED(SetRegEntry(HKEY_ROWSETVIEWER, szRECENTFILE_KEY, pszFileName, MAX_NAME_LEN)))
			break;

		SAFE_FREE(pszFileName);
	}

	//ServiceComponents
	CHAR szBuffer[MAX_QUERY_LEN];
	ConvertToMBCS(m_wszInitString, szBuffer, MAX_QUERY_LEN);
	DelRegEntry(HKEY_ROWSETVIEWER, szRECENTINITSTRING_KEY);
	SetRegEntry(HKEY_ROWSETVIEWER, szRECENTINITSTRING_KEY,	szBuffer, MAX_QUERY_LEN);
}


////////////////////////////////////////////////////////////////
// CConnectDlg::GetOptionsObj
//
/////////////////////////////////////////////////////////////////
COptionsDlg* CConnectDlg::GetOptionsObj()
{
	ASSERT(m_pCMainWindow);
	ASSERT(m_pCMainWindow->m_pCOptionsDlg);
	return m_pCMainWindow->m_pCOptionsDlg;
}


////////////////////////////////////////////////////////////////
// CConnectDlg::ResetDefaults
//
/////////////////////////////////////////////////////////////////
BOOL CConnectDlg::ResetDefaults()
{
	//Configuration Name
	strcpy(m_szConfigName, "(Default)");
	
	//Provider Page
	m_wszLocation[0]	= wEOL;			//DBPROP_INIT_LOCATION
	m_wszDataSource[0]	= wEOL;			//DBPROP_INIT_DATASOURCE
	m_wszUserID[0]		= wEOL;			//DBPROP_AUTH_USERID
	m_wszPassword[0]	= wEOL;			//DBPROP_AUTH_PASSWORD
	m_dwPromptProp		= DBPROMPT_COMPLETE;
	m_dwhWndProp		= (LONG)m_pCMainWindow->m_hWnd;

	//Properties Page
	m_wszProvString[0]		= wEOL;		//DBPROP_INIT_PROVIDERSTRING
	m_wszCatalog[0]			= wEOL;		//DBPROP_INIT_CATALOG
	m_dwlcidProp			= NOTSET;

	m_dwAsynchProp			= NOTSET;
	m_dwTimeoutProp			= NOTSET;
	m_dwModeProp			= NOTSET;

	//Security Page
	m_dwProtectionProp		= NOTSET;
	m_dwImpersonateProp		= NOTSET;
	m_dwMaskPasswordProp	= NOTSET;
	m_dwEncryptPasswordProp	= NOTSET;
	m_dwCacheProp			= NOTSET;	
	m_dwPersistProp			= NOTSET;		
	m_dwPersistEncryptProp	= NOTSET;
	m_wszIntegrated[0]		= wEOL;		// DBPROP_INIT_INTEGRATED

	//Options Page
	m_dwCLSCTX				= CLSCTX_INPROC_SERVER;
	m_wszRemoteServer[0]	= wEOL;
	m_dwConnectOpts			= CONNECT_INITIALIZE | CONNECT_SETPROPERTIES | CONNECT_CREATESESSION | CONNECT_CREATECOMMAND;
	
	//Other Saved Config Info
	m_wszCmdBuffer[0]	= wEOL;

	//ServicecComponents
	m_wszInitString[0]  = wEOL;
	return TRUE;
}


////////////////////////////////////////////////////////////////
// CConnectDlg::LoadDefaults
//
/////////////////////////////////////////////////////////////////
BOOL CConnectDlg::LoadDefaults()
{
	//Need to remove any previously set properties.
	//Specifically any Advanced properties, since this is a new configuration
	FreeProperties(&m_cPropSets, &m_rgPropSets);
	
	//Configuration Name
	if(m_szConfigName[0] == EOL)
		strcpy(m_szConfigName, "(Default)");

	//Formulate the key
	CHAR szKeyName[MAX_NAME_LEN];
	sprintf(szKeyName, "%s\\%s", szCONFIG_KEY, m_szConfigName); 

	//Selected Provider
	GetRegEntry(HKEY_ROWSETVIEWER, szKeyName, "Provider",			m_EnumInfo.wszName, MAX_NAME_LEN);
	GetRegEntry(HKEY_ROWSETVIEWER, szKeyName, "ParseName",			m_EnumInfo.wszParseName, MAX_NAME_LEN);

	//Provider Page
	GetRegEntry(HKEY_ROWSETVIEWER, szKeyName, "Location",			m_wszLocation, MAX_NAME_LEN);
	GetRegEntry(HKEY_ROWSETVIEWER, szKeyName, "DataSource",			m_wszDataSource, MAX_NAME_LEN);
	GetRegEntry(HKEY_ROWSETVIEWER, szKeyName, "UserID",				m_wszUserID, MAX_NAME_LEN);
	GetRegEntry(HKEY_ROWSETVIEWER, szKeyName, "Password",			m_wszPassword, MAX_NAME_LEN);

⌨️ 快捷键说明

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