有一个DLL文件TEST.dll,它里面有一个名称为TEST1()的函数,在我的程序里如何来调用呢?我很菜,请指点一下,谢谢
----------------------------------------------------------------------
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();
--------------------------------------------------------
那小弟试一试!谢谢各位大侠帮忙
--------------------------------------------------------
1.静态加载
2.动态加载
--------------------------------------------------------
问这个问题需要勇气
你为什么不先找找以前别人的答案?菜鸟要会学习,csdn的搜索很有用的