///////////////////////////////////////////////////////////////////// // Loader.cpp - Demonstrate loading "Reflection" Library // // // // Language: Visual Studio 2005 C++ // // Platform: Dell Dimension 9150, Windows XP Pro, SP 2 // // Application: Prototype for CSE687 Project #4b - Reflection // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////// #include // note: no reflection.h included here #include #include void main() { std::cout << "\n Test Reflector Loader"; std::cout << "\n =======================\n"; ///////////////////////////////////////////////////////// // load ReflectionProto.dll library HMODULE hmod = LoadLibrary(L"ReflectionProto"); if(!hmod) { std::cout << "\n library load failed"; return; } ///////////////////////////////////////////////////////// // find global function const char* GetTypes() typedef const char* (*GT)(); GT GetTypes = (GT)GetProcAddress(hmod,"GetTypes"); if(!GetTypes) { std::cout << "\n GetProcAddress failed for GetTypes"; return; } std::cout << GetTypes(); ///////////////////////////////////////////////////////// // find const char* GetMethods(const char* type) typedef const char* (*GM)(const char*); GM GetMethods = (GM)GetProcAddress(hmod,"GetMethods"); if(!GetMethods) { std::cout << "\n GetProcAddress failed"; return; } std::cout << GetMethods("reflector"); ///////////////////////////////////////////////////////// // find const char* GetParams(const char* type, const char* method) typedef const char* (*GP)(const char*, const char*); GP GetParams = (GP)GetProcAddress(hmod,"GetParams"); if(!GetParams) { std::cout << "\n GetProcAddress failed"; return; } std::cout << GetParams("reflector","show"); class IGateway { public: virtual ~IGateway() {} IGateway* Create(); virtual int& value()=0; virtual void say()=0; }; typedef IGateway* (*CR)(); CR Create = (CR)GetProcAddress(hmod,"?Create@gateway@@SAPAV1@XZ"); if(!Create) { std::cout << "\n GetProcAddress failed for Create"; } IGateway* pGateway = (IGateway*)Create(); pGateway->say(); pGateway->value() = 5; pGateway->say(); FreeLibrary(hmod); std::cout << "\n\n"; }