プロバイダーでの列の動的な連結
列の動的バインドが本当に必要であることを確認します。 これは次の理由で必要になる可能性があります。
行セットの列がコンパイル時に定義されていない。
列を追加する要素 (ブックマークなど) をサポートする。
列の動的バインドを実装するには
コードから
PROVIDER_COLUMN_MAPを削除します。ユーザー レコード (構造体) で、次の宣言を追加します。
static ATLCOLUMNINFO* GetColumnInfo(void* pThis, ULONG* pcCols);GetColumnInfo関数を実装します。 この関数は、情報がどのように格納されるかをレイアウトします。 この関数については、プロパティまたはその他の情報の取得が必要になる場合があります。 COLUMN_ENTRY マクロに類似したマクロを作成して、独自の情報を追加することもできます。GetColumnInfo関数の例を次に示します。// Check the property flag for bookmarks, if it is set, set the zero // ordinal entry in the column map with the bookmark information. CAgentRowset* pRowset = (CAgentRowset*) pThis; CComQIPtr<IRowsetInfo, &IID_IRowsetInfo> spRowsetProps = pRowset; CDBPropIDSet set(DBPROPSET_ROWSET); set.AddPropertyID(DBPROP_BOOKMARKS); DBPROPSET* pPropSet = NULL; ULONG ulPropSet = 0; HRESULT hr; if (spRowsetProps) hr = spRowsetProps->GetProperties(1, &set, &ulPropSet, &pPropSet); if (pPropSet) { CComVariant var = pPropSet->rgProperties[0].vValue; CoTaskMemFree(pPropSet->rgProperties); CoTaskMemFree(pPropSet); if (SUCCEEDED(hr) && (var.boolVal == VARIANT_TRUE)) { ADD_COLUMN_ENTRY_EX(ulCols, OLESTR("Bookmark"), 0, sizeof(DWORD), DBTYPE_BYTES, 0, 0, GUID_NULL, CAgentMan, dwBookmark, DBCOLUMNFLAGS_ISBOOKMARK) ulCols++; } } // Next, set up the other columns. ADD_COLUMN_ENTRY(ulCols, OLESTR("Command"), 1, 256, DBTYPE_STR, 0xFF, 0xFF, GUID_NULL, CAgentMan, szCommand) ulCols++; ADD_COLUMN_ENTRY(ulCols, OLESTR("Text"), 2, 256, DBTYPE_STR, 0xFF, 0xFF, GUID_NULL, CAgentMan, szText) ulCols++; ADD_COLUMN_ENTRY(ulCols, OLESTR("Command2"), 3, 256, DBTYPE_STR, 0xFF, 0xFF, GUID_NULL, CAgentMan, szCommand2) ulCols++; ADD_COLUMN_ENTRY(ulCols, OLESTR("Text2"), 4, 256, DBTYPE_STR, 0xFF, 0xFF, GUID_NULL, CAgentMan, szText2) ulCols++; if (pcCols != NULL) *pcCols = ulCols; return _rgColumns; }