#ifndef _MYCODE_H_
#define _MYCODE_H_
#ifdef DLLDEMO1_EXPORTS
#define EXPORTS_DEMO _declspec( dllexport )
#else
#define EXPORTS_DEMO _declspec(dllimport)
#endif
extern "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);
}
}
C++参考demo-dll
最新推荐文章于 2023-10-09 10:51:25 发布