#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
//假如CreateDll.dll这个dll中有一个函数Add(int a, int b);
//定义一个函数指针
typedefint(*func_Add)(inta, intb);
intmain(intargc, char*argv[])
{
intsum = 0;
HMODULEh = NULL;
func_Add func_Add_from_dll = NULL;
//注意dll的路径,视自己的情况而定
h = LoadLibrary("..\\CreateDll\\CreateDll.dll");
if(NULL == h)
{
printf("LoadLibrary failed!\n");
return0;
}
func_Add_from_dll = (func_Add)GetProcAddress(h, "Add");
if(NULL == func_Add_from_dll)
{
printf("GetProcAddress failed!\n");
return0;
}
sum = (*func_Add_from_dll)(1, 2);
printf("%d\n", sum);
getchar();
return0;
}