Active Member
Group: Members
Posts: 54
Member No.: 49504
Joined: 11-February 12
|
First way:
CODE | #include <stdio.h>
extern "C" __declspec(dllimport)double AddNumbers(double a, double b); int main(int argc, char **argv) { double result = AddNumbers(1, 2); printf("The result was: %f\n", result); return 0; }
|
Second way:
CODE | #include <windows.h> #include <stdio.h>
typedef double (*importFunction)(double, double); int main(int argc, char **argv) { importFunction addNumbers; double result; HINSTANCE hinstLib = LoadLibrary("Example.dll"); if (hinstLib == NULL) { printf("ERROR: unable to load DLL\n"); return 1; } addNumbers = (importFunction)GetProcAddress(hinstLib, "AddNumbers"); if (addNumbers == NULL) { printf("ERROR: unable to find DLL function\n"); return 1; } result = addNumbers(1, 2); FreeLibrary(hinstLib); printf("The result was: %f\n", result); return 0; }
|
|