Home C/C++ C语言调用DLL文件

主程序代码:

#include <stdio.h>
#include <conio.h>
#include <windows.h>

#define LIBRARY “DLL.dll”

typedef int (*PFUNC)(char *);

int main()
{
 HMODULE hModule=LoadLibrary(LIBRARY);
 if(hModule==0)
 {
  printf(“动态库加载失败。\n”);
  getch();
  return -1;
 }
 PFUNC func=(PFUNC)GetProcAddress(hModule,”show”);
 if(func==NULL)
 {
  printf(“定位函数失败。\n”);
  getch();
  return -1;
 }
 func(“Hello word!”);

 return 0;
}

 

 

DLL代码:

#include <stdio.h>
#include <windows.h>

extern “C”

int  _declspec( dllexport )  show(char *str)
{
 MessageBox(NULL,str,NULL,MB_OK);
 return 0;
}

0 comment

You may also like

Leave a Comment