使用dll以及调用dll例子
1)以下是简单的使用dll的例子
#include "stdafx.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
extern "C"
{
__declspec(dllexport) int HttpVIP(char * strContent,int * result)
{
return 0;
}
};
2)以下是调用dll的例子
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
HINSTANCE Hdll = GetModuleHandle("dll.dll");
if (NULL == Hdll)
{
Hdll = LoadLibrary("dll.dll");
}
//HttpVIP(char * strContent,int * result)
typedef int (*TESTDLL)(char * strContent,int * result);
TESTDLL pHttpIVR;
pHttpIVR=(TESTDLL)GetProcAddress(Hdll,"HttpVIP");
int r;
int res=pHttpIVR("501",&r);
cout<<"res = "<<res<<endl;
FreeLibrary(Hdll); //在恰当的时候释放句柄。
return 0;
}