Enlazar columnas dinámicamente en un proveedor

Actualización: noviembre 2007

Decida si necesita realmente el enlace dinámico a columnas. Puede necesitarlo si:

  • Las columnas del conjunto de filas no se definen en tiempo de compilación.

  • Va a ofrecer compatibilidad con elementos como marcadores que agregan columnas.

Para implementar el enlace dinámico a columnas

  1. Quite del código las macros PROVIDER_COLUMN_MAP.

  2. En el registro de usuario (su estructura), agregue la siguiente declaración:

    static ATLCOLUMNINFO* GetColumnInfo(void* pThis, ULONG* pcCols);
    
  3. Implemente la función GetColumnInfo. Esta función establece la forma de almacenar la información. Puede que tenga que obtener propiedades u otra información para esta función. Es posible que desee crear una macro, similar a la macro COLUMN_ENTRY, para agregar su propia información.

    En el ejemplo siguiente se muestra una función 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;
    }
    

Vea también

Conceptos

Trabajar con plantillas de proveedores OLE DB