Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- #include "TestInterface.h"
- // Simplified version of the logging function.
- void logOneLine (const char *clr, const char *msg) {
- static FILE *log = 0;
- log = fopen("TestDLL.log", log ? "at" : "wt");
- fprintf (log, "%s: %s\n", clr, msg);
- fclose (log);
- }
- // Macro logging to ease reading the code.
- #define Log logOneLine(__func__, buff)
- int main (void) {
- char buff[255];
- memset (buff, 0, 255*sizeof(char));
- Log;
- HMODULE hDll = LoadLibrary(L"TestLib.dll");
- while (1) {
- if (hDll) {
- // You might want to replace mangled names below with the right ones after compiling on your system.
- Instanciator instanciator = (Instanciator) GetProcAddress(hDll, "_Z11Instanciatebi");
- Destructor destructor = (Destructor) GetProcAddress(hDll, "_Z7DestroyP13TestInterface");
- if (!instanciator || !destructor) {
- sprintf (buff, "Unable to retrieve factory function pointers.");
- Log;
- break;
- }
- int numinstances = 0;
- printf ("\nEnter number of iterations:");
- if (scanf("%d", &numinstances)!=1)
- break;
- sprintf (buff, "Number of iterations: %d.", numinstances);
- Log;
- if (numinstances<1 || numinstances > 40)
- break;
- TestInterface **ptrs = new TestInterface*[numinstances];
- if (!ptrs)
- break;
- memset (ptrs, 0, sizeof(TestInterface*)*numinstances);
- for (int i=0; i<numinstances; ++i) {
- sprintf (buff, "Iteration #%d...", i);
- Log;
- bool bb;
- int ii;
- ptrs[i] = instanciator((i % 2)==0, i);
- if (!ptrs[i])
- break;
- if (ptrs[i]->get(bb, ii)) {
- sprintf(buff, "Got bb=%s, ii=%d.", bb ? "true" : "false", ii);
- Log;
- }
- }
- for (int i=0; i<numinstances; ++i) {
- destructor (ptrs[i]);
- ptrs[i] = 0;
- }
- delete[] ptrs;
- }
- break;
- }
- if (hDll) {
- FreeLibrary (hDll);
- hDll = 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement