I created my first (VERY) simple DLL that contains 3 functions... add, subtract and multiply. I then created a program to test the DLL. Problem is the add function works fine but it seems like the calls to the other two are failing and I can't quite figure out why...
the DLL is
dllmain.h
and dllmain.cppCode:#ifndef DLLMAIN_H_INCLUDED #define DLLMAIN_H_INCLUDED #include <windows.h> #define DLL_EXPORT __declspec(dllexport) #ifdef __cplusplus extern "C" { #endif int DLL_EXPORT subtract(int, int); int DLL_EXPORT add(int, int); int DLL_EXPORT multiply(int, int); #ifdef __cplusplus } #endif #endif // DLLMAIN_H_INCLUDEDand the test file is main.cppCode:#include "dllmain.h" int DLL_EXPORT subtract(int a, int b) { return a - b; } int DLL_EXPORT add(int a, int b) { return a + b; } int DLL_EXPORT multiply(int a, int b) { return a * b; } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: // attach to process // return FALSE to fail DLL load break; case DLL_PROCESS_DETACH: // detach from process break; case DLL_THREAD_ATTACH: // attach to thread break; case DLL_THREAD_DETACH: // detach from thread break; } return TRUE; // successful }the functins are identical except for the operator being used and I am not sure what else could cause the problem... any ideas?Code:#include <windows.h> #include <iostream> typedef int (*FunctionPtr)(int, int); // definition of the function from the DLL int main() { HINSTANCE hinstDLL = NULL; // HINSTANCE of the DLL to load FunctionPtr FuncToCall = NULL; // address of the function to call // load the DLL containing the function definitions hinstDLL = LoadLibrary("DLL/bin/Release/test.dll"); // if the DLL loaded OK then get the function address if(hinstDLL != NULL) { FuncToCall = (FunctionPtr)GetProcAddress(hinstDLL, "multiply"); } else { std::cout<<"DLL failed to load!\n"; return 0; } // if it is a good address the call the function if(FuncToCall != NULL) { std::cout<<FuncToCall(8, 5) <<"\n"; } else { std::cout<<"Function address is NULL\n"; } // free the DLL and exit FreeLibrary(hinstDLL); return 0; }



LinkBack URL
About LinkBacks



