如何调用DLL! 有一个DLL文件TEST.dll,它里面有一个名称为TEST1()的函数,在我的程序里如何来调用呢?我很菜,请指点一下,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1、包含该DLL接口的头文件,设置好DLL库的路径;2、调用该DLL的函数。 // A simple program that uses LoadLibrary and // GetProcAddress to access myPuts from Myputs.dll. #include <stdio.h> #include <windows.h> typedef int (*MYPROC)(LPTSTR); VOID main(VOID) { HINSTANCE hinstLib; MYPROC ProcAdd; BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; // Get a handle to the DLL module. hinstLib = LoadLibrary(TEXT("myputs")); // If the handle is valid, try to get the function address. if (hinstLib != NULL) { ProcAdd = (MYPROC) GetProcAddress(hinstLib, TEXT("myPuts")); // If the function address is valid, call the function. if (NULL != ProcAdd) { fRunTimeLinkSuccess = TRUE; (ProcAdd) (TEXT("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"); } 若是没有DLL的头文件可不可以调用啊? 没有头文件可以,但是需要知道DLL中函数的原型,方法就是mynamelj说的那种 HINSTANCE hin=LoadLibrary("Test.dll");typedef int (__stdcall *Fun)();Fun fun=(Fun)GetProcAddress(hin,"test");int r=fun(); 问这个问题需要勇气你为什么不先找找以前别人的答案?菜鸟要会学习,csdn的搜索很有用的 有人在xp-sp2下写过无线零配置么 整数后面的小数点怎么去掉? 改写CRectTracker类后gdi内存泄漏 帮菜鸟看下简单代码 请问我应该去哪里? 急、在命令行下如何编译Windows程序?? 多线程中迸发事件,的解决方法总结。欢迎Mark 如何取得List Control中某个单元的数据 求助,谁有一段在网页里播放音乐的源代码!绝对给分!!!!! 关于vc在mapx中画点的问题 如何在一个文本文件里查找字符串??? 大家说说为什么c++不支持如下定义map呢?
2、调用该DLL的函数。
// GetProcAddress to access myPuts from Myputs.dll.
#include <stdio.h>
#include <windows.h>
typedef int (*MYPROC)(LPTSTR);
VOID main(VOID)
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(TEXT("myputs"));
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, TEXT("myPuts"));
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
(ProcAdd) (TEXT("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");
}
typedef int (__stdcall *Fun)();
Fun fun=(Fun)GetProcAddress(hin,"test");
int r=fun();