袁绍伦
路人甲
路人甲
  • 注册日期2003-08-08
  • 发帖数654
  • QQ164646905
  • 铜币1336枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1491回复:0

C++ Example of an RDO Dataset

楼主#
更多 发布于:2003-09-03 21:35

#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();
 }
}
喜欢0 评分0
愿意和大家交朋友! QQ:47559983 MSN:shaolun_yuan@hotmail.com eMail:shaolun-yuan@163.com
游客

返回顶部