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

📄 cenum.cpp

📁 用测试OLE DB提供者的一个程序。能够测试出OEL DB提供者到底实现了哪些接口?很灵的。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		TESTC(m_pCListBox->OutputPreMethod("CoCreateInstance(%S, 0x%08x, %d, %s, &0x%08x)", pwszProgID, pIUnkOuter, dwCLSCTX, GetInterfaceName(riid), ppIUnknown ? *ppIUnknown : NULL));
		XTEST(m_hWnd, hr = CoCreateInstance(clsid, pIUnkOuter, dwCLSCTX, riid, (void**)ppIUnknown));
		TESTC(m_pCListBox->OutputPostMethod(hr, "CoCreateInstance(%S, 0x%08x, %d, %s, &0x%08x)", pwszProgID, pIUnkOuter, dwCLSCTX, GetInterfaceName(riid), ppIUnknown ? *ppIUnknown : NULL));
	}

	
CLEANUP:
	SAFE_FREE(pwszProgID);
	return hr;
}


/////////////////////////////////////////////////////////////////////////////
// BOOL CEnum::IsConnectedToRootEnum
//
/////////////////////////////////////////////////////////////////////////////
BOOL CEnum::IsConnectedToRootEnum()
{
	return (BOOL)m_pIParseDisplayName;
}


/////////////////////////////////////////////////////////////////////////////
// HRESULT CEnum::ConnectToRootEnum
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CEnum::ConnectToRootEnum()
{
	HRESULT hr = S_OK;

	//Initialize the OLE DB Enumerator and Obtain rowset
	//For some reason the RootEnum may fail, don't display error...
	TESTC(m_pCListBox->OutputPreMethod("CoCreateInstance(CLSID_OLEDB_ENUMERATOR, NULL, CLSCTX_INPROC_SERVER, IID_IParseDisplayName, &0x%08x)", m_pIParseDisplayName));
	hr = CoCreateInstance(CLSID_OLEDB_ENUMERATOR, NULL, CLSCTX_INPROC_SERVER, IID_IParseDisplayName, (void**)&m_pIParseDisplayName);
	TESTC(m_pCListBox->OutputPostMethod(hr, "CoCreateInstance(CLSID_OLEDB_ENUMERATOR, NULL, CLSCTX_INPROC_SERVER, IID_IParseDisplayName, &0x%08x)", m_pIParseDisplayName));

	//Now Delegate to our generic Enumerator method
	TESTC(hr = GetEnumRowset(m_pIParseDisplayName, &m_cEnumInfo, &m_rgEnumInfo));
	
	//NOTE:  The Root Enumerator doesn't include itself in the List of Enumerators
	//This is good for the case of tree controls would be never ending, but bad
	//for apps like this one, where you might want to see the "rowset" of the Root
	//Enum.  So to get arround this I will just add it to the list manually

	//Alloc room for extra MSDAENUM additon
	SAFE_REALLOC(m_rgEnumInfo, ENUMINFO, m_cEnumInfo + 1);
	wcscpy(m_rgEnumInfo[m_cEnumInfo].wszName,		L"MSDAENUM");
	wcscpy(m_rgEnumInfo[m_cEnumInfo].wszParseName,	L"{c8b522d0-5cf3-11ce-ade5-00aa0044773d}");
	wcscpy(m_rgEnumInfo[m_cEnumInfo].wszDescription,L"Microsoft OLE DB Root Enumerator");
	m_rgEnumInfo[m_cEnumInfo].wType					= DBSOURCETYPE_ENUMERATOR;
	m_rgEnumInfo[m_cEnumInfo].fIsParent				= VARIANT_TRUE;
	m_cEnumInfo++;


CLEANUP:
	return hr;
}



/////////////////////////////////////////////////////////////////////////////
// HRESULT CEnum::GetEnumRowset
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CEnum::GetEnumRowset(IParseDisplayName* pIParseDisplayName, ULONG* pcEnumInfo, ENUMINFO** prgEnumInfo)
{
	HRESULT hr;
	ASSERT(pIParseDisplayName);
	ASSERT(pcEnumInfo);
	ASSERT(prgEnumInfo);

	HROW rghRows[MAX_BLOCK_SIZE];
	HROW* phRows = rghRows;
	ULONG cRowsObtained = 0;
	IRowset* pIRowset = NULL;

	IAccessor* pIAccessor = NULL;
	HACCESSOR hAccessor = DB_NULL_HACCESSOR;
	ULONG ulRefCount = 0;

	//Make our lives easier
	ULONG cEnumInfo = 0;
	ENUMINFO* rgEnumInfo = NULL;
	ISourcesRowset* pISourcesRowset = NULL;
	
	// Bind the user and table name for the list
	const static ULONG cBindings = 5;
	const static DBBINDING rgBindings[cBindings] = 
		{
			1,	 			
			offsetof(ENUMINFO, wszName),
			0,
			0,	
			NULL,			
			NULL, 		
			NULL,		
			DBPART_VALUE,
			DBMEMOWNER_CLIENTOWNED,		
			DBPARAMIO_NOTPARAM, 
			MAX_NAME_LEN, 		
			0, 				
			DBTYPE_WSTR, 	
			0,	
			0, 				

			2,	 			
			offsetof(ENUMINFO, wszParseName),
			0,
			0,	
			NULL,			
			NULL, 		
			NULL,		
			DBPART_VALUE,
			DBMEMOWNER_CLIENTOWNED,		
			DBPARAMIO_NOTPARAM, 
			MAX_NAME_LEN, 		
			0, 				
			DBTYPE_WSTR, 	
			0,	
			0, 				

			3,	 			
			offsetof(ENUMINFO, wszDescription),
			0,
			0,	
			NULL,			
			NULL, 		
			NULL,		
			DBPART_VALUE,
			DBMEMOWNER_CLIENTOWNED,		
			DBPARAMIO_NOTPARAM, 
			MAX_NAME_LEN, 		
			0, 				
			DBTYPE_WSTR, 	
			0,	
			0, 				
	
			4,	 			
			offsetof(ENUMINFO, wType),
			0,
			0,	
			NULL,			
			NULL, 		
			NULL,		
			DBPART_VALUE,
			DBMEMOWNER_CLIENTOWNED,		
			DBPARAMIO_NOTPARAM, 
			sizeof(DBTYPE), 		
			0, 				
			DBTYPE_UI2, 	
			0,	
			0, 				

			5,	 			
			offsetof(ENUMINFO, fIsParent),
			0,
			0,	
			NULL,			
			NULL, 		
			NULL,		
			DBPART_VALUE,
			DBMEMOWNER_CLIENTOWNED,		
			DBPARAMIO_NOTPARAM, 
			sizeof(VARIANT_BOOL), 
			0, 				
			DBTYPE_BOOL, 	
			0,	
			0, 				
	};

	//Obtain ISourcesRowset interface
	XTEST(m_hWnd, hr = m_pCListBox->OutputQI(pIParseDisplayName, IID_ISourcesRowset, (IUnknown**)&pISourcesRowset, "IParseDisplayName"));

	TESTC(m_pCListBox->OutputPreMethod("ISourcesRowset::GetSourcesRowset(NULL, IID_IRowset, 0, NULL, , &0x%08x)", pIRowset));
	XTEST(m_hWnd, hr = pISourcesRowset->GetSourcesRowset(NULL, IID_IRowset, 0, NULL, (IUnknown**)&pIRowset));
	TESTC(m_pCListBox->OutputPostMethod(hr, "ISourcesRowset::GetSourcesRowset(NULL, IID_IRowset, 0, NULL, , &0x%08x)", pIRowset));

	//Create Accessor
	XTEST(m_hWnd, hr = m_pCListBox->OutputQI(pIRowset, IID_IAccessor, (IUnknown**)&pIAccessor, "IRowset"));

	TESTC(m_pCListBox->OutputPreMethod("IAccessor::CreateAccessor(DBACCESSOR_ROWDATA, %d, 0x%08x, 0, &0x%08x, NULL)", cBindings, rgBindings, hAccessor));
	XTEST(m_hWnd, hr = pIAccessor->CreateAccessor(DBACCESSOR_ROWDATA, cBindings, rgBindings, 0, &hAccessor, NULL));
	TESTC(m_pCListBox->OutputPostMethod(hr, "IAccessor::CreateAccessor(DBACCESSOR_ROWDATA, %d, 0x%08x, 0, &0x%08x, NULL)", cBindings, rgBindings, hAccessor));

	//Loop through the entire returned rowet
	while(TRUE)
	{
		TESTC(m_pCListBox->OutputPreMethod("IRowset::GetNextRows(NULL, 0, %d, &%d, &0x%08x)", MAX_BLOCK_SIZE, cRowsObtained, phRows));
		XTEST(m_hWnd, hr = pIRowset->GetNextRows(NULL, 0, MAX_BLOCK_SIZE, &cRowsObtained, &phRows));
		TESTC(m_pCListBox->OutputPostMethod(hr, "IRowset::GetNextRows(NULL, 0, %d, &%d, &0x%08x)", MAX_BLOCK_SIZE, cRowsObtained, phRows));
		
		//ENDOFROWSET
		if(cRowsObtained==0) 
			break;
		
		//Alloc room for ProviderInfo (in chunks)
		SAFE_REALLOC(rgEnumInfo, ENUMINFO, cEnumInfo + cRowsObtained);
		memset(&rgEnumInfo[cEnumInfo], 0, sizeof(ENUMINFO)*cRowsObtained);

		//Loop over rows obtained and get ProviderInfo
		for(ULONG i=0; i<cRowsObtained; i++) 
		{	
			//Get the Data
			TESTC(m_pCListBox->OutputPreMethod("IRowset::GetData(0x%08x, 0x%08x, 0x%08x)", rghRows[i], hAccessor, &rgEnumInfo[cEnumInfo]));
			XTEST(m_hWnd, hr = pIRowset->GetData(rghRows[i], hAccessor, (void*)&rgEnumInfo[cEnumInfo]));
			TESTC(m_pCListBox->OutputPostMethod(hr, "IRowset::GetData(0x%08x, 0x%08x, 0x%08x)", rghRows[i], hAccessor, &rgEnumInfo[cEnumInfo]));
			cEnumInfo++;
		}
			
		//Release all the rows
		TESTC(m_pCListBox->OutputPreMethod("IRowset::ReleaseRows(%d, 0x%08x, NULL, NULL, NULL)", cRowsObtained, rghRows));
		XTEST(m_hWnd, hr = pIRowset->ReleaseRows(cRowsObtained, rghRows, NULL, NULL, NULL));
		TESTC(m_pCListBox->OutputPostMethod(hr, "IRowset::ReleaseRows(%d, 0x%08x, NULL, NULL, NULL)", cRowsObtained, rghRows));
	}

CLEANUP:
	//Output Params
	*pcEnumInfo = cEnumInfo;
	*prgEnumInfo = rgEnumInfo;
	
	if(hAccessor && pIAccessor)
	{
		HRESULT hrOptional = S_OK;
		m_pCListBox->OutputPreMethod("IAccessor::ReleaseAccessor(0x%08x, &%d)", hAccessor, ulRefCount);
		XTEST(m_hWnd, hrOptional = pIAccessor->ReleaseAccessor(hAccessor, &ulRefCount));
		m_pCListBox->OutputPostMethod(hrOptional, "IAccessor::ReleaseAccessor(0x%08x, &%d)", hAccessor, ulRefCount);
	}

	m_pCListBox->OutputRelease((IUnknown**)&pISourcesRowset,	"ISourcesRowset");
	m_pCListBox->OutputRelease((IUnknown**)&pIRowset,			"IRowset");
	m_pCListBox->OutputRelease((IUnknown**)&pIAccessor,			"IAccessor");
	return hr;
}


⌨️ 快捷键说明

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