Here is a very basic dll demo that works. See if you can see what I did and then compare that to what you did (heres a hint: if something's different you are probably wrong).
Here is the dll file code:
Code:
#ifdef __cplusplus
#define EXPORT extern "C" __declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
#include <windows.h>
EXPORT void doBeep(void);
int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved ) {
return true;
}
EXPORT void doBeep(void) {
for(int i = 0; i<5; i++)
MessageBeep(0);
}
Here is the def file code
Code:
LIBRARY DLLdemo
EXPORTS
doBeep
And finnally here is the code for the test app:
Code:
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//define my pointer type to the function---------------------------------------
typedef int(*myProc)(void);
myProc proc = NULL;
//-----------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
static TCHAR szAppName[] = TEXT("dllTest");
HWND hwnd;
MSG msg;
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = szAppName;
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;
if(!RegisterClass(&wc)){
MessageBox(NULL, TEXT("Could not register class"), szAppName, MB_ICONERROR);
return (0);
}
hwnd = CreateWindow(szAppName, TEXT("dllTEST"), WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
static HINSTANCE hInstLib; //handle to the library
BOOL fFreeResult;
switch(message) {
case WM_CREATE:
hInstLib = LoadLibrary("Dlldemo.dll"); //Load the dll
proc = (myProc)GetProcAddress(hInstLib, TEXT("doBeep"));//Get address of function
proc();//call function
return(0);
case WM_DESTROY:
fFreeResult = FreeLibrary(hInstLib); //release library
PostQuitMessage(0);
return(0);
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
This should get you going in the right direction.