自己做了个DLL,另外建了个应用程序调用这个DLL,执行后能加载DLL,但不能调用函数,生成DLL的那个程序部分如下:
// MyDLL.cpp : Defines the entry point for the DLL application.
//#include "stdafx.h"
//#include "MyDLL.def"
int _declspec(dllexport) Max(int a,int b)
{
if(a>=b)return a;
else
return b;
}
int _declspec(dllexport) Min(int a,int b)
{
if(a>=b)return b;
else
return a;
}BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
 )
{
    return TRUE;
}调用DLL的程序部分如下:
void CTestDlg::OnButton1() 
{
int max_value=19;
int min_value=18;
int result;
HINSTANCE hLibrary;
typedef int (*_Max)(int a,int b);
typedef int (*_Min)(int a,int b);
_Max max;
_Min min;
hLibrary=LoadLibrary("MyDLL.dll");
if(hLibrary!=NULL)
 MessageBox("The MyDLL.DLL has already been load.");max=(_Max)GetProcAddress(hLibrary,"Max");
//if (max!=(_Max)NULL)
//{
result=(*max)(max_value,min_value);
cout<<result<<endl;
//}
//else
MessageBox("the call of function failure!!!");
//int max_value= (*max)(15,20);
//int min_value= (* min)(15,20);
//MessageBox(""+max_value);
FreeLibrary(hLibrary);

}MyDLL.dll还有MyDLL.lib已经copy到该工程debug目录下

解决方案 »

  1.   

    dll中的导出函数这样申明:
    extern "C" DllExport int _stdcall Min(int a,int b)
    试试看吧
      

  2.   

    看了你的代码,没有错误,怎么不能调用函数?
    “执行后能加载DLL”,不是加载DLL成功了么,真的吗?
      

  3.   

    name mangling error~extern "C" __declspec(dllexport) int Max(int a,int b);
      

  4.   

    dll中的导出函数这样申明:
    extern "C" __declspec(dllexport) int _stdcall Min(int a,int b)
      

  5.   

    动态加载不用 .lib
    但要加入   MyDLL.h #include " MyDLL.h"
    修改引入的MyDLL.h中
    extern "C" __declspec(dllexport) int Max(int a,int b);

    extern "C" __declspec(dllimport) int Max(int a,int b);
      

  6.   

    错误信息:0x00000000指令引用的0x00000000内存。该内存不能为read
      

  7.   

    如果是函数不能调用,那应该是link错误,告诉你XXX函数未定义
    你的错误应该不是DLL的问题,可能是初始化了一个空指针,未赋值便读取,找一下NULL关键字试试
      

  8.   

    我的问题和这差不多,关注ing