Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CallDllFunction.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- using namespace std;
- // Defining the function prototype.
- typedef double (__cdecl *AddType)(double a, double b);
- int main()
- {
- HINSTANCE dllHandle = NULL;
- AddType AddPtr = NULL;
- double result = 0.0;
- // Load the dll.
- dllHandle = LoadLibrary(L"MathLibrary.dll");
- if (dllHandle == NULL) {
- cerr << "Failed to load library with error code " << GetLastError() << endl;
- return EXIT_FAILURE;
- }
- // Get a pointer to the add function in MathLibrary.dll.
- AddPtr = (AddType) GetProcAddress(dllHandle, "?Add@Functions@MathLibrary@@SANNN@Z");
- if (AddPtr == NULL) {
- cerr << "Could not find add function. Error code " << GetLastError() << endl;
- return EXIT_FAILURE;
- }
- // The moment of truth...
- result = AddPtr(1.0, 2.0);
- cout << "The result is " << result << endl;
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment