64,282
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
#include <stdio.h>
typedef int (__cdecl *MYPROC)(LPWSTR);
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, "myPuts");
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
(ProcAdd) (L"Message sent to the DLL function\n");
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("Message printed from executable\n");
}
#include <stdio.h>
#include <windows.h>
#include <string>
#include <iostream>
using namespace std;
void main(void)
{
typedef int (__stdcall *PFUNCTION)( int k,int i);
//声明参数类型,以后会用到PFUNCTION
HMODULE hLib = ::LoadLibrary("xx.dll");
if ( NULL == hLib )
{
perror("装载DLL文件错误:");
}
else
{
PFUNCTION myAddFunction=myAddFunction=(PFUNCTION)::GetProcAddress(hLib,"ConnectEx");
//ConnectEx是动态库中的方法
if ( NULL == myAddFunction)
{
perror("装载的DLL文件中无对应的函数:");
}
else
{
int k=myAddFunction(1,2);
cout <<k <<endl;
}
::FreeLibrary(hLib);
}
}
我学的是java,这是我研究出来的,