VC常用代码之动态加载DLL
2008-10-21 16:12
357 查看
根据MSDN:
// File: RUNTIME.C
// A simple program that uses LoadLibrary and
// GetProcAddress to access myPuts from MYPUTS.DLL.
#include <stdio.h>
#include <windows.h>
typedef VOID (*MYPROC)(LPTSTR);
VOID main(VOID)
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary("myputs");
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts");
// If the function address is valid, call the function.
if (fRunTimeLinkSuccess = (ProcAdd != NULL))
(ProcAdd) ("message via DLL function/n");
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("message via alternative method/n");
}
// File: RUNTIME.C
// A simple program that uses LoadLibrary and
// GetProcAddress to access myPuts from MYPUTS.DLL.
#include <stdio.h>
#include <windows.h>
typedef VOID (*MYPROC)(LPTSTR);
VOID main(VOID)
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary("myputs");
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts");
// If the function address is valid, call the function.
if (fRunTimeLinkSuccess = (ProcAdd != NULL))
(ProcAdd) ("message via DLL function/n");
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("message via alternative method/n");
}
相关文章推荐
- VC常用代码之动态加载DLL
- vc静态加载dll和动态加载dll(转)
- VC++ .NET 动态加载DLL,使用反射方式Invoke委托调用
- vc静态加载dll和动态加载dll
- 动态加载dll代码
- VC++通过动态生成并加载DLL,实现可执行文件的自删除
- VC6 静态与动态加载Dll [示例代码]
- VC++通过动态生成并加载DLL,实现可执行文件的自删除
- 用vc++动态加载dll
- VC中实现dll动态库文件加载
- vc静态加载dll和动态加载dll
- VC++通过动态生成并加载DLL,实现可执行文件的自删除
- 解决VC中动态加载DLL时,必须将DLL文件放在EXE文件路经和系统目录下的问题
- 用vc++动态加载dll
- 静态与动态加载Dll [示例代码]
- 初次接触vc 运行时动态加载DLL
- [代码生成器] 二. 动态加载DLL的代码自动生成
- C++ 常用代码001 IsValidFileName VC/MFC 判断有效文件名
- 非阻塞动态加载javascript广告实现代码
- dll动态加载方式