I am trying to write a DLL and call a function in it using LoadLibrary and GetProcAddress(). The code compiles fine, and I can enter two numbers, but then it crashes. This is my code:
Code://Main program #include <iostream> using namespace std; #include <windows.h> typedef void (__stdcall* MYFUNCTION)(int, int, int &); int main() { HINSTANCE hDLL; MYFUNCTION funcAdd; int x, y, sum; hDLL = LoadLibrary("dll.dll"); if (hDLL) { funcAdd = (MYFUNCTION)GetProcAddress(hDLL, "funcAdd"); cout << "Enter 2 ints:" << endl; cin >> x >> y; (funcAdd)(x, y, sum);// call the function cout << "The sum is " << sum << endl; FreeLibrary(hDLL); } cin.get(); return 0; }Any ideas?Code://DLL code void __stdcall __declspec(dllexport) funcAdd(int a, int b, int &c) { c = a + b; }![]()




Reply With Quote