33,311
社区成员
发帖
与我相关
我的任务
分享
//===============mydef.cpp===
#define DLL extern "C" _declspec(dllexport)
#include "mydef.h"
int DLL add_(int x,int y)
{
return x+y;
}
//=====mydef.h=========
#ifndef MYDEF_H
#define DLL extern "C"_declspec(dllimport)
int DLL add_(int x,int y);
#endif
//===============mydef.cpp===
#define DLL extern "C"_declspec(dllexport)
#include "mydef.h"
int DLL add_(int x,int y)
{
return x+y;
}
#include "mydef.h"
int DLL add_(int x,int y)
{
return x+y;
}
#include <stdio.h>
#include "mydef.h"
#include <windows.h>
void main()
{
int sd;
char *str="add";
typedef int (*mydef_add)(int,int);
HINSTANCE k=LoadLibrary("F:\\program\\pj1208202\\Debug\\pj1208201.dll");
if (k)
{
mydef_add p=(mydef_add)GetProcAddress(k,"add_");
if (p!=NULL)
sd=p(2,3);
printf("hello!%d\n",sd);
FreeLibrary(k);
}
}