首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

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

2014-01-05 
动态链接DLL出错#include stdafx.h#include windows.hint _tmain(int argc, _TCHAR* argv[]){typedef

动态链接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;
}

热点排行