Visual C++

Moderators: Lundin
Number of threads: 379
Number of posts: 695

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
load a win32 dll at run time Posted by kk_mfc on 21 Mar 2006 at 2:00 AM

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();
}
}





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.