C++参考demo-dll

来源:互联网 发布:如何修改tomcat端口 编辑:程序博客网 时间:2024/06/06 17:58
#ifndef _MYCODE_H_#define _MYCODE_H_#ifdef DLLDEMO1_EXPORTS#define EXPORTS_DEMO _declspec( dllexport )#else#define EXPORTS_DEMO _declspec(dllimport)#endifextern "C" EXPORTS_DEMO int Add (int a , int b);#endif#include "stdafx.h"#include "MyCode.h"int Add ( int a , int b ){       return ( a + b );}#include <windows.h>#include <iostream>//#include "..\\DLLDemo1\\MyCode.h"using namespace std;#pragma comment(lib, "..\\debug\\DLLDemo1.lib")extern "C" _declspec(dllimport) int Add(int a, int b);int main(int argc, char *argv[]){      cout<<Add(2, 3)<<endl;      return 0;}#include <windows.h>#include <iostream>using namespace std;typedef int (*AddFunc)(int a, int b);int main(int argc, char *argv[]){      HMODULE hDll = LoadLibrary("DLLDemo1.dll");      if (hDll != NULL)      {            AddFunc add = (AddFunc)GetProcAddress(hDll, "Add");            if (add != NULL)            {                  cout<<add(2, 3)<<endl;            }            FreeLibrary(hDll);      }}
原创粉丝点击