[code=c]extern "C" int __declspec(dllexport)add(int x, int y);
extern "C" int __declspec(dllexport)*add1();
int add(int x, int y)
{
return x + y;
}
int *add1()
{
static int a[3]={1,2,3};
static int *p;
p=a;
return p;
}
[/code]
---------------------------------------------------------------------------以上为DLL_test.dll文件内容,以下为Main主程序
[code=c]#include
#include
typedef int(*lpAddFun)(int, int); //宏定义函数指针类型
typedef int(*lpAddFun1)();???????????????????这里定义似乎不对,因为add1()返回值为指针,但又不知道正确的是怎么写。请帮忙指点
int main(int argc, char *argv[])
{
HINSTANCE hDll; //DLL句柄
lpAddFun addFun; //函数指针
lpAddFun1 addFun1;
hDll = LoadLibrary(L"..\debug\DLL_test.dll");
if (hDll != NULL)
{
addFun = (lpAddFun)GetProcAddress(hDll, "add");
addFun1 = (lpAddFun1)GetProcAddress(hDll, "add1");???这里对吗
if (addFun != NULL)
{
int result = addFun(2, 3);
printf("2 + 3 = %d\n", result);
int *k;-----------------------------------这行和下面的一行,也不对,不知道怎么才行。。
k=addFun1();------------------------
printf("add1中的a[1]的结果是: %d\n", *(k+1));
system("pause");
}
FreeLibrary(hDll);
}
return 0;
}[/code]