读书人

动态链接DLL出错,该如何解决

发布时间: 2014-01-05 18:22:56 作者: rapoo

动态链接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来进行调用?
[解决办法]

引用:
我就怎么用不上MAKEINTRESOURCE?

error C2664: 'GetProcAddress' : cannot convert parameter 2 from 'LPWSTR' to 'LPCSTR',你的参数传递错了。
[解决办法]
#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;
}

读书人网 >C++

热点推荐