What does dll.h look like? Does it prototype SetFunction() and CallFunction()?
The contents should be something like this:
#ifdef DLL_EXPORTS# define MYDLL_LINKAGE __declspec(dllexport)#else# define MYDLL_LINKAGE __declspec(dllimport)#endifMYDLL_LINKAGE void SetFunction(void (*func)(int));MYDLL_LINKAGE void CallFunction(int i)
And then dll.cpp should be:
//dllmain.cpp//the function pointervoid (*FuncPointer)(int i);MYDLL_LINKAGE void SetFunction(void (*func)(int)){FuncPointer = func;}MYDLL_LINKAGE void CallFunction(int i){FuncPointer(i);}
When you're building your DLL, you should define DLL_EXPORTS somewhere (preferably in the preprocessor settings if you're using MSVC++).
If this is defined, then the compiler will flag the functions as exported from the DLL.
When you build your main application, DLL_EXPORTS won't be defined, so the compiler will flag the functions as being imported from a DLL. I'm not even entirely sure you *need* to say they're imported from a DLL, you could perhaps get away with not using __declspec(dllimport), but it's not a good idea.
Also, your last linker error is because you created a Win32 application instead of a Win32 console application. Either re-create the project as a console app, or change your int main() function to int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) and #include windows.h.