extern __declspec(dllexport) int FuncTest();
dlltest.cpp
__declspec(dllexport) int FuncTest(int a )
{
if (a = 1)
{
return 100;
}
}
dlltest.def
LIBRARY "testmydll"EXPORTS FuncTest generates dlltest.dlldlltest.lib and creates a WinDLL to copy dlltest. DLL to WinThe Debug directory of 32 is Win32 The dll. CPP file in the project is as follows#include <iostream>
#include "string"
#include <stdio.h>
#include <windows.h>
using namespace std;
int main()
{
HINSTANCE hDLL = LoadLibrary("testmydll.dll");
if (hDLL)
{
HFUNC hFun = (HFUNC)GetProcAddress(hDLL,"FuncTest");
if (hFun)
{
int a =1;
int b = hFun(a);
printf("%dn",b); Dlltest. lib = dlltest.lib = dlltest.lib = dlltest.lib = dlltest.lib = dlltest.lib = dlltest.lib = dlltest.lib = dlltest.lib = dlltest.lib = dlltest.lib = dlltest.lib = dlltest.libinThe code in dlL. CPP in the 32 project is as follows#include <iostream>
#include "string"
#include <stdio.h>
#include <windows.h>
#include "dlltest.h"
using namespace std;
#pragma comment(lib,"testmydll.lib")
__declspec(dllimport) int FuncTest(int a );
int main()
{
int b = FuncTest(1);
printf("%dn",b);
return0; } Compile execution prints out 100Copy the code