Hi,
I had a win32 dll which i need to load it with the help of LoadLibrary from my client application.
i am facing a problem in loading and calling the dll functions.
here is the code..
some body please help me.
DLL code:
win32dll.h
#ifndef _WIN32DLL
#define _WIN32DLL
#include <windows.h>
#define DLL_EXPORT __declspec(dllexport)
DLL_EXPORT void sayhai(void);
#endif
Win32dll.c
#include "Win32dll.h"
static HINSTANCE hInst;
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
hInst=hinstDLL;
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
default:
break;
}
return TRUE;
}
DLL_EXPORT void sayhai(void)
{
MessageBox(NULL,"sayhai","sayhai",MB_OK);
}
clientcode:
HINSTANCE dllhinst;
typedef VOID (CALLBACK* LPFNDLLFUNC1)(VOID);
LPFNDLLFUNC1 lpfnDllFunc1;
dllhinst=LoadLibrary("Win32dll");
if (dllhinst!=NULL)
{
lpfnDllFunc1=(LPFNDLLFUNC1)GetProcAddress(dllhinst, "sayhai");
if (!lpfnDllFunc1)
{
FreeLibrary(dllhinst);
}
else
{
lpfnDllFunc1();
}
}