Creating an Instance of a Data Source Object Directly by Using the Provider s CLSID

OLE DB Programmer's Reference

This example connects directly to a specific MDP by using the provider's unique class identifier, in this case represented by CLSID_GENOLAP. After obtaining an IID_IDBSchemaRowset pointer, this function proceeds to call the function MDPSchemaSample (the code for which appears in the section "Creating a Schema Rowset") to traverse the schema rowset for the MDP data source object.

// HRESULT MDPConnectUsingClsId(void) {    HRESULT hr;    // Initialize property values.    for (ULONG i=0; i < NUMELEM(rgProperties); i++)       VariantInit(&rgProperties[i].vValue);    // Create the instance of the MSOLAP provider.    IDBInitialize *pIDBInitialize = NULL;    hr = CoCreateInstance(CLSID_MSOLAP, NULL, CLSCTX_INPROC_SERVER,       IID_IDBInitialize, (LPVOID*)&pIDBInitialize);    IDBProperties *pIDBProperties = NULL;    hr = pIDBInitialize->QueryInterface(IID_IDBProperties, (void **)                                        &pIDBProperties);    // Identify property set.    DBPROPSET rgPropertySet[1];    DBPROP rgProperties[1];    rgPropertySet[0].rgProperties = rgProperties;    rgPropertySet[0].cProperties = 1;    rgPropertySet[0].guidPropertySet = DBPROPSET_DBINIT;    // Fill in data source.    rgProperties[0].dwPropertyID = DBPROP_INIT_DATASOURCE;    rgProperties[0].dwOptions = DBPROPOPTIONS_REQUIRED;    rgProperties[0].colid = DB_NULLID;    rgProperties[0].vValue.vt = VT_BSTR;    rgProperties[0].vValue.bstrVal = SysAllocString(L"LocalHost");    assert(rgProperties[0].vValue.bstrVal);    hr = pIDBProperties->SetProperties(NUMELEM(rgPropertySet),   rgPropertySet);    // Initialize and create the session.    hr = pIDBInitialize->Initialize();    IDBCreateSession *pIDBCreateSession = NULL;    hr = pIDBInitialize->QueryInterface(IID_IDBCreateSession,       (void **) &pIDBCreateSession);    IDBSchemaRowset *pIDBSchemaRowset = NULL;    hr = pIDBCreateSession->CreateSession(NULL, IID_IDBSchemaRowset,       (IUnknown **) &pIDBSchemaRowset);    IRowset* pIRowset = NULL;    hr = MDPSchemaSample(pIDBSchemaRowset, (IUnknown**)pIRowset);    if (pIDBInitialize) pIDBInitialize->Release();    if (pIDBProperties) pIDBProperties->Release();    if (pIDBCreateSession) pIDBCreateSession->Release();    if (pIDBSchemaRowset) pIDBSchemaRowset->Release();    if (pIRowset) pIRowset->Release();    return hr; }

1998-2001 Microsoft Corporation. All rights reserved.



Microsoft Ole Db 2.0 Programmer's Reference and Data Access SDK
Microsoft OLE DB 2.0 Programmers Reference and Data Access SDK (Microsoft Professional Editions)
ISBN: 0735605904
EAN: 2147483647
Year: 1998
Pages: 1083

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net