调用DLL文件
用VC的Depands工具DLL中有login接口,但是只能成功加载DLL,却不能正确调用相关函数
.h文件
typedef int(__stdcall *login)(char *ip ,unsigned int port,char *username,char *password,void ** handle);.cpp文件
触发函数
HINSTANCE        hDll=NULL;
hDll=    LoadLibrary("D:\\MyProjects\\TestDemo\\Debug\\test.dll"); 

        if(hDll==NULL){
MessageBox("加载失败");
}else{
MessageBox("加载成功");
} //运行到这里是加载成功 login   lpfn2=NULL;      
        lpfn2   =   (login)::GetProcAddress(hDll,"lpfn2"); 
DWORD dw=GetLastError();//dw=127
CString strLp;
strLp.Format("%d",dw);
MessageBox(strLp); int iFlag; 
        //lpfn2=NULL 程序跳入else
        if   (lpfn2!=NULL)   
{       
MessageBox("---Enter---");
iFlag=(lpfn2)("192.168.1.121",7810,"admin","1234",NULL);

if (iFlag==1)

MessageBox("success");   
}else{
MessageBox("error");
}
FreeLibrary(hDll);   
return; 
}else{
MessageBox("2222222");

解决方案 »

  1.   

    看看是不是发生了名字改编 
    dumpbin -exports test.dll 利用模块定义文件防止名字改编 添加一个dll4.def文件到源文件, 内容如下: LIBRARY dll4 EXPORTS 
    add 可以看到EXPORTS下面即为输出的函数名。可以有下面的写法: LIBRARY dll4 EXPORTS 
    export_add=add export_add为要输出的函数名,add为源文件中的函数名