///////////////////////////////////////////////////////////////////////// /// BridgeToCPPengine.cpp - Shows how to use traditional, unmanaged /// /// ver 2.1 C++ packaged as a dll library from /// /// managed code. /// /// /// /// Language: Visual C++, ver 7.0, Visual Studio.Net /// /// Platform: Dell Dimension 8100, Windows Pro 2000 /// /// Application: CSE681 Example /// /// Author: Jim Fawcett, CST 2-187, Syracuse Univ. /// /// (315) 443-3948, jfawcett@twcny.rr.com /// ///////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "bridgeToCPPengine.h" #include #include "Tok.h" #include using namespace bridgeToCPPengine; using namespace System; using namespace std; //----< convert managed string to unmanaged string >------------------- // // user must dispose of unmanaged string // std::string* Bridge::MsToUms(String* pMs) { std::string* pUs = new std::string; for(int i=0; iLength; i++) { wchar_t ch = pMs->Chars[i]; pUs->append(1,static_cast(ch)); } return pUs; } //----< convert unmanaged string to managed string >------------------- String* Bridge::UmsToMs(std::string* pUs) { StringBuilder* pMs = new StringBuilder(pUs->c_str()); return pMs->ToString(); } //----< constructor >-------------------------------------------------- Bridge::Bridge() : _pToker(0),_pStream(0) {} //----< destructor >--------------------------------------------------- Bridge::~Bridge() { delete _pStream; delete _pToker; } //----< open file and attach to Bridge >------------------------------- bool Bridge::attach(String* fileName) { std::string* pName = MsToUms(fileName); _pStream = new ifstream(pName->c_str()); delete pName; if(!_pStream->good()) { _pToker = 0; delete _pStream; _pStream = 0; return false; } _pToker = new toker(*_pStream); return true; } //----< delegate GetTok to unmanaged class TokMgr >-------------------- bool Bridge::GetTok(String*& pTok) { std::string* pToken = MsToUms(pTok); bool ok = _pToker->getTok(*pToken); pTok = UmsToMs(pToken); delete pToken; return ok; } // This is a dynamic link library, so it must by tested by // an external test driver.