/////////////////////////////////////////////////////////////// // ATLclient.cpp - client of ICurrDir interface // // ver 1.0 // // // // demonstrate creation of simple ATL-based, in-process // // component. This client uses _com_ptr and _com_error // // classes. // // // // Language: Visual C++, ver 6.0 // // Platform: Micron Dual Pentium Pro 200, Win NT 4.0 // // Application: Demo: CSE791 - Distributed Objects // // Author: Jim Fawcett, CST 2-187, Syracuse Univ. // // (315) 443-3948, fawcett@ecs.syr.edu // /////////////////////////////////////////////////////////////// #include "stdafx.h" #include #import "dirControl.tlb" no_namespace using namespace std; void main() { cout << "\n Testing CurrDir In-proc Component " << "\n ===================================\n"; // save current path to restore at end of program const int PathSize = 256; char currPath[PathSize]; ::GetCurrentDirectory(PathSize,currPath); cout << "\n Saving Current Directory = " << currPath; // begin use of dirControl try { CoInitializeEx(NULL,COINIT_APARTMENTTHREADED); ICurrDirPtr pDir(_T("dirControl.CurrDir.1")); _bstr_t newPath = ".."; cout << "\n Setting Current Directory = " << (char*)newPath; pDir->SetCurrDir(newPath); //----< using unwrapped method with BSTR >--------- // // BSTR bstr = SysAllocString(L".."); // pDir->raw_SetCurrDir(bstr); // SysFreeString(bstr); // //------------------------------------------------- _bstr_t bStr = pDir->GetCurrDir(); cout << "\n Getting Current Directory = " << (char*)bStr << endl; //----< using unwrapped method with BSTR >--------- // // pDir->raw_GetCurrDir(&bstr); // char *retStr = new char[wcslen(bstr)+1]; // wcstombs(retStr,bstr,wcslen(bstr)+1); // SysFreeString(bstr); // cout << "\n " << retStr << "\n\n"; // delete [] retStr; // //------------------------------------------------- bStr = pDir->GetDirContents(); cout << "\n Directory Contents:" << (char*)bStr << "\n"; //----< using unwrapped method with BSTR >--------- // // pDir->raw_GetDirContents(&bstr); // retStr = new char[wcslen(bstr)+1]; // wcstombs(retStr,bstr,wcslen(bstr)+1); // SysFreeString(bstr); // cout << "\n " << retStr << "\n"; // delete [] retStr; // //------------------------------------------------- } catch(_com_error e) { cout << e.ErrorMessage() << endl; } CoUninitialize(); cout << "\n restoring original path\n\n"; ::SetCurrentDirectory(currPath); }