// If the handle is valid, try to get the function address.
if (hinstLib != NULL) { ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myfun"); //ProcAdd即为myfun在DLL中的地址 // If the function address is valid, call the function.
if (fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd) ("message via DLL function\n");
#include <windows.h>
typedef VOID (*MYPROC)(LPTSTR); //函数指针(取得函数在DLL中的地址)
//void为返回值,LPCSTR为参数
//LPCSTR可根据需要改动VOID main(VOID)
{
HINSTANCE hinstLib; //句柄
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary("my.dll"); //装载DLL
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myfun");
//ProcAdd即为myfun在DLL中的地址 // If the function address is valid, call the function.
if (fRunTimeLinkSuccess = (ProcAdd != NULL))
(ProcAdd) ("message via DLL function\n");
//现在为可以使用myfun函数了。方法为:
/*
ProcAdd((char *)&InitArgs);//(char *)&InitArgs为参数
*/
//调用完后释放句柄,如需调用其它函数,重复即可。
// 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");
}
#include <iostream.h>
#include <windows.h>
HINSTANCE Dll_handler;
typedef char* (*DLLTEST)();
DLLTEST CommOpen;int main(int argc, char* argv[])
{
Dll_handler = LoadLibrary("vbdll.dll");//这一步成功
CommOpen = (DLLTEST)GetProcAddressDll_handler,"output");//output是vbdll。dll中class CFunc的一个方法、这一步不成功,我不知道如何写。 ……
//other code FreeLibrary(Dll_handler); return 0;}
LoadLibary
GetProcAddress
FreeLibary
几个函数的应用
难道vb写的dll只能在vb中调用、应该不会这样吧!!
怎么调用?请详细说说or给出代码。
查看基本信息,
不过只能用COM的方式调用