动态链接DLL出错
#include "stdafx.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
typedef int(*lpAddFun)(int,int);//宏定义函数指针类型
HINSTANCE hInst=NULL;
lpAddFun addFun; //函数指针
hInst=::LoadLibraryA("C:\\Users\\Administrator\\Documents\\Visual Studio 2010\\Projects\\CreatDLL\\Debug\\DLLTest.dll");
if(hInst==NULL)
{
printf("Load mydll.DLL fail!\n");
//return 0;
}
else
{
addFun=(lpAddFun)GetProcAddress(hInst,MAKEINTRESOURCE(1));
if (addFun!=NULL)
{
int result=addFun(2,3);
printf("%d", result);
}
}
FreeLibrary(hInst);
return 0;
}
动态调用是用MAKEINTRESOURCE提示 error C2664: 'GetProcAddress' : cannot convert parameter 2 from 'LPWSTR' to 'LPCSTR',我想请问,def文件是在创建dll的工程中添加,还是在应用的工程中添加?怎么正确的使用,才能通过MAKEINTRESOURCE来进行调用?
[解决办法]
#include "stdafx.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[]) {
typedef int(*lpAddFun)(int,int);//宏定义函数指针类型
HINSTANCE hInst=NULL;
lpAddFun addFun; //函数指针
hInst=::LoadLibrary(_T("C:\\Users\\Administrator\\Documents\\Visual Studio 2010\\Projects\\CreatDLL\\Debug\\DLLTest.dll"));
if(hInst==NULL) {
_tprintf(_T("Load mydll.DLL fail!\n"));
//return 0;
} else {
addFun=(lpAddFun)GetProcAddress(hInst,(LPCSTR)1);
if (addFun!=NULL) {
int result=addFun(2,3);
_tprintf(_T("%d"), result);
}
}
FreeLibrary(hInst);
return 0;
}