阅读:1490回复:0
C++ Example of an RDO Dataset#import <msrdo20.dll> \ rename("EOF", "rdoEOF") \ rename("UserNameA", "_UserNameA") : : : /* * This must be here to ensure that COM is always initialized. * we could alternately put the CoInitialize and CoUninitialize * calls in InitInstance and ExitInstance of our application * class. */ static struct InitOle { InitOle() { ::CoInitialize(NULL); } ~InitOle() { ::CoUninitialize(); } } _init_InitOle_; inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);}; : : : void CMapXAppView::OnStuff() { // Note: instead of having all these RDO:: qualifiers, // we could have just put "using namespace RDO;" at the top // of this file. RDO::_rdoResultsetPtr rsPtr; RDO::_rdoConnectionPtr connPtr; HRESULT hr; COleVariant rsVt; CMapXDataset ds; COptionalVariant optVt; // Create a new Connection object connPtr.CreateInstance(__uuidof(RDO::rdoConnection)); // Change the "DBQ=" line if MapX was installed in a //different location. connPtr->Connect = "DRIVER={Microsoft Access Driver (*.mdb)};" "DBQ=C:\\Program Files\\MapInfo\MapX 5.0\\Data\\MapStats.mdb"; hr = connPtr->EstablishConnection(); TESTHR(hr); // make sure the EstablishConnection() went OK. // Open the USA table of the MapStats database rsPtr = connPtr->OpenResultset("select * from USA", (long)RDO::rdOpenStatic); // Make the rsVt variant point to our Resultset rsVt.vt = VT_DISPATCH; rsVt.pdispVal = rsPtr; rsVt.pdispVal->AddRef(); try { // Add the dataset to the map and create a simple theme //from it. ds = m_ctrlMapX.GetDatasets().Add(miDataSetRDO, rsVt, COleVariant("RDOSet"), optVt, optVt, COleVariant("USA"), optVt, optVt); ds.GetThemes().Add(miThemeRanged, "TOTPOP"); } catch(COleDispatchException* e) { e->ReportError(); e->Delete(); } catch(COleException* e) { e->ReportError(); e->Delete(); } } |
|
|