1.DLL原代码:
#include "stdafx.h"BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}int _declspec(dllexport) GetValue(int n)
{
if(n == 1)
{
return 10;
}
else
return 200;
}2.调用DLL
void CTestDlg::OnButton1()
{
// TODO: Add your control notification handler code here
typedef int (*ABC)(int);
HINSTANCE h;
h = LoadLibrary("TDll.dll");
ABC abc;
abc = (ABC)GetProcAddress(h,"GetValue"); abc(4);
FreeLibrary(h);
}我只是写了一个测试程序,所以没有进行其他判断和处理,不知是哪儿出了问题.
#include "stdafx.h"BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}int _declspec(dllexport) GetValue(int n)
{
if(n == 1)
{
return 10;
}
else
return 200;
}2.调用DLL
void CTestDlg::OnButton1()
{
// TODO: Add your control notification handler code here
typedef int (*ABC)(int);
HINSTANCE h;
h = LoadLibrary("TDll.dll");
ABC abc;
abc = (ABC)GetProcAddress(h,"GetValue"); abc(4);
FreeLibrary(h);
}我只是写了一个测试程序,所以没有进行其他判断和处理,不知是哪儿出了问题.
int _declspec(dllexport) GetValue(int n)
写成
extern "C" int _declspec(dllexport) GetValue(int n)楼主的写法用
#pragma comment(lib,"test.lib")
int _declspec(dllexport) GetValue(int n)然后直接调用
GetValue(100)是可行的用LoadLibrary的方式就不能用但是如果生成dll文件时自己定义一个def文件也能用
LoadLibrary