///////////////////////////////////////////////////////////////////////// // interfaceClient.cpp - Demonstrate Creation and proper use of // // Dynamic Link Libraries (DLLs) // // // // Language: Visual C++, ver 7.0 // // Platform: Dell Dimension 8100, Windows 2000, SP 2.0 // // Application: Demonstration for CSE775 - Distributed Objects // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////////// /* Operations: =========== This workspace contains six modules: 1. DemoDll (implemented by this module) - demonstrates creation of basic dll, exporting a class and global functions 2. RevisedDemoDll - changes the implementation of DemoDll but keeps its interface and semantics. 3. dllClient - uses both DemoDll.dll and RevisedDemoDll.dll - use of DemoDll.dll is successful - use of RevisedDemoDll crashes because dll was modified but client was not, and client was welded to the dll's implementation. 4. DemoInterface - demonstrates how to build a dll that does not require a client to bind to its implementation by providing an interface (abstract class) with a creational function. 5. RevisedDemoInterface - changes the implementation of DemoInterface but keeps its interface and semantics. 6. interfaceClient - uses both DemoInterface and RevisedDemoInterface successfully. // Example of what does not work: DemoDll and RevisedDemoDll use the same class and function syntax but different implementations. Since dllClient binds directly to CDemoDll, it cannont survive changes to the CDemoDll imple- mentation that result in different object sizes. +-----------+ +----------+ | dllClient |----->| CDemoDll | +-----------+ +----------+ 1st version in DemoDll 2nd version in RevisedDemoDll Example of what does work: DemoInterface and RevisedDemoInterface use the same class and function syntax. Since only the CDemoDll implementing class changes the interfaceClient works successfully with both. +-----------------+ +----------------+ | interfaceClient |----->| CDemoInterface | +-----------------+ +----------------+ / \ | | +----------+ | CDemoDll | +----------+ 1st version in DemoInterface 2nd version in RevisedDemoInterface */ // ///////////////////////////////////////////////////////////////////////// // Build Processes // ///////////////////////////////////////////////////////////////////////// // DemoDll: // // Required Files: // // DemoDll.h, DemoDll.cpp, stdafx.h, stdafx.cpp // // compiler command: // // devenv DemoDll.vcproj /make /rebuild // ///////////////////////////////////////////////////////////////////////// // RevisedDemoDll: // // Required Files: // // RevisedDemoDll.h, RevisedDemoDll.cpp, stdafx.h, stdafx.cpp // // compiler command: // // devenv RevisedDemoDll.vcproj /make /rebuild // ///////////////////////////////////////////////////////////////////////// // dllClient : // // Required Files: // // dllClient.cpp, stdafx.h, stdafx.cpp, DemoDll.dll, DemoDll.lib // // compiler command: // // devenv dllClient.vcproj /make /rebuild // ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// // DemoInterface: // // Required Files: // // DemoInterface.h, DemoInterface.cpp, stdafx.h, stdafx.cpp // // compiler command: // // devenv DemoInterface.vcproj /make /rebuild // ///////////////////////////////////////////////////////////////////////// // RevisedDemoInterface: // // Required Files: // // RevisedDemoInterface.h, RevisedDemoInterface.cpp, // // stdafx.h, stdafx.cpp // // compiler command: // // devenv RevisedDemoInterface.vcproj /make /rebuild // ///////////////////////////////////////////////////////////////////////// // interfaceClient: // // Required Files: // // interfaceClient.cpp, stdafx.h, stdafx.cpp, // // DemoInterface.dll, DemoInterface.lib // // compiler command: // // devenv interfaceClient.vcproj /make /rebuild // ///////////////////////////////////////////////////////////////////////// // #include "stdafx.h" /////////////////////////////////////////////////////////////////////// // DemoInterface.cpp - Demonstrate Creation and proper use of // // Dynamic Link Libraries (DLLs) // // // // Language: Visual C++, ver 7.0 // // Platform: Dell Dimension 8100, Windows 2000, SP 2.0 // // Application: Demonstration for CSE775 - Distributed Objects // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // /////////////////////////////////////////////////////////////////////// /* Operations: =========== This workspace contains six modules: 1. DemoDll (implemented by this module) - demonstrates creation of basic dll, exporting a class and global functions 2. RevisedDemoDll - changes the implementation of DemoDll but keeps its interface and semantics. 3. dllClient - uses both DemoDll.dll and RevisedDemoDll.dll - use of DemoDll.dll is successful - use of RevisedDemoDll crashes because dll was modified but client was not, and client was welded to the dll's implementation. 4. DemoInterface - demonstrates how to build a dll that does not require a client to bind to its implementation by providing an interface (abstract class) with a creational function. 5. RevisedDemoInterface - changes the implementation of DemoInterface but keeps its interface and semantics. 6. interfaceClient - uses both DemoInterface and RevisedDemoInterface successfully. */ // #include #include "DemoInterface.h" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { cout << "\n Demonstrate use of DLL Through Interface with same exports " << "\n ============================================================\n"; cout << "\n current directory is: " << GetDir(); CDemoInterface *pInterface = CDemoInterface::CreateDemoDll(); pInterface->setDir("c:/temp"); cout << "\n directory has been set to: " << pInterface->getDir(); pInterface->restore(); cout << "\n directory has been restored to: " << pInterface->getDir(); // // The following statements fail to link because the interface-based dll // no-longer exports the CDemoDll class definition. We can turn this into // a compile-time failure - a good thing - by moving the CDemoDll class // declaration into the DemoInterface.cpp and RevisedDemoInterface.cpp // files, keeping just the interface declaration in the header file. // // CDemoDll cd; // CDemoDll *pCd = new CDemoDll(); // cout << "\n\n"; return 0; }