Thanks for moving me... guess instead of creating a new thread I might as well post another question here:
I'm attempting to learn DLLs, but I can't get it to work:
Code:
// This is DllOne.dll
#include <windows.h>
BOOL WINAPI DllMain(HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved)
{
return TRUE;
}
__declspec (dllexport) int Multiply(int x, int y )
{
return x*y;
}
Code:
// This is my main trying to test the DLL
#include <iostream>
#include <windows.h>
using namespace std;
typedef int (*MYPROC)(int, int);
int main()
{
HINSTANCE inst = LoadLibrary("DllOne.dll");
MYPROC ProcAdd;
ProcAdd = (MYPROC)GetProcAddress(inst, "Multiply");
if(ProcAdd)
cout << (ProcAdd)(1, 2);
if(inst)
{
FreeLibrary(inst);
}
cout << "Hello";
return 0;
}
Problem is the code above in RED never gets executed. I have my DLL in the same directory as my program, but I can't seem to access the function within my DLL. Also, is the only way to use a DLL is to use function pointers due to compile time checks?