| | |
Help me with DLL animals :)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I have this DLL code, but I cannot access function.
Where am I wrong?
main.h
main.cpp
And here is the console App that calls the DLL
Where am I wrong?
main.h
C++ Syntax (Toggle Plain Text)
#ifndef __MAIN_H__ #define __MAIN_H__ #include <windows.h> /* To use this exported function of dll, include this header * in your project. */ #ifdef BUILD_DLL #define DLL_EXPORT __declspec(dllexport) #else #define DLL_EXPORT __declspec(dllimport) #endif #ifdef __cplusplus extern "C" { #endif //simple functions are being exported EXPORT_DLL double Addition(double a, double b); EXPORT_DLL double Multiplication(double a, double b); #ifdef __cplusplus } #endif #endif // __MAIN_H__
main.cpp
C++ Syntax (Toggle Plain Text)
#include "main.h" //add them and return the answer double DLL_EXPORT Addition(double a, double b) { double c = a+b; return c; } //multiply them and return the answer double DLL_EXPORT Multiplication(double a, double b) { double c = a*b; return c; }
And here is the console App that calls the DLL
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <windows.h> typedef double(*FuncPtr)(double a, double b); //declare DLL handle HINSTANCE hDLL; //declare pointers to the functions FuncPtr AddFunc, MultiFunc; using namespace std; int main() { //create handle to our DLL hDLL = LoadLibrary("mathdll"); //Get proc address if handle is valid if (hDLL!=NULL) { cout<<"Loaded DLL! \n"<<"Getting Proc Address"<<endl; AddFunc = (FuncPtr)GetProcAddress(hDLL, "Addition"); if(AddFunc) { cout<<"Sum of 8 and 2 is: "<<AddFunc(8.0, 2.0); FreeLibrary(hDLL); } else { cout<<"Failed to get a function! Unloading the DLL"<<endl; FreeLibrary(hDLL); } } return 0; }
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
![]() |
Similar Threads
- What is BRIDGE.DLL (Viruses, Spyware and other Nasties)
- Loader.EXE and IEDLL.EXE errors (Web Browsers)
- Please help with DLL error message! (Windows NT / 2000 / XP)
- DLL equivalent to xerces.jar (Java)
- ToolBar>dll (Web Browsers)
- Missing system32\hal.dll (Windows NT / 2000 / XP)
- Kernel32.dll (Windows 95 / 98 / Me)
- vb6 executables w/ dll's (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: Start project - help
- Next Thread: Need help!
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






