#ifndef DEMODLL_H #define DEMODLL_H /////////////////////////////////////////////////////////////////// // DemoDll.h - Demonstrate Creation, use, and miss-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 // ///////////////////////////////////////////////////////////////////////// // #ifdef DEMODLL_EXPORTS #define DEMODLL_API __declspec(dllexport) #else #define DEMODLL_API __declspec(dllimport) #endif class DEMODLL_API CDemoDll { public: CDemoDll(void); void setDir(const char *path); const char* getDir(); void restore(); bool changed(); private: friend DEMODLL_API const char* GetDir(); bool _changed; /// _PATHSIZE change breaks dllClient /// but does not break interfaceClient static const size_t _PATHSIZE = 100; // too small char _curPath[_PATHSIZE]; char _oldPath[_PATHSIZE]; }; DEMODLL_API void SetDir(const char *path); DEMODLL_API const char* GetDir(); #endif