我写了一个 DLL 和一个调用它的程序,代码如下:
//TheDll.cpp
#include <windows.h>
__declspec(dllexport) int WINAPI MyAdd(int a,int b){
return (a+b);
}BOOL WINAPI DllMain(HANDLE, DWORD, LPVOID){
return TRUE;
}//TheApp.cpp
#include <windows.h>
#include <stdio.h>__declspec(dllimport) int __stdcall MyAdd(int a,int b);
typedef int (WINAPI *FUNC)(int ,int);int main(int argc,char **argv){ HMODULE hInst = LoadLibrary("TheDll.dll");
if(hInst == NULL){
printf("LoadLibrary Error.\n");
return 0;
}

FUNC pFunc = NULL;
pFunc = (FUNC)GetProcAddress(hInst,"MyAdd");
if (pFunc == NULL){
printf("GetProcAddress Error.\n");
}else{
int res = pFunc(4,5);
printf("Result is %d\n",res);
} if(hInst != NULL)
FreeLibrary(hInst);

return 1;
}
运行 TheApp.exe 时提示 : GetProcAddress Error请问这个问题怎么解决??

解决方案 »

  1.   

    你必须添加一个thedll.def文件。 
    里面写上: LIBRARY "thedll" 
    DESCRIPTION 'thedll Windows Dynamic Link Library' 
    EXPORTS 
         MyAdd @1 
      

  2.   

    用GetProcAddress获得DLL函数,不是用__declspec(dllexport)导出的。这个方式是为用.LIB连接准备的。 
      

  3.   

    我知道怎么做了
    原来在导出申明的时候要用 extern "C"