日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

VS2010中 C++创建DLL图解

發(fā)布時(shí)間:2023/12/20 c/c++ 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VS2010中 C++创建DLL图解 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、DLL的創(chuàng)建?
創(chuàng)建項(xiàng)目: Win32->Win32項(xiàng)目,名稱:MyDLL


選擇DLL (D) ->完成.

1、新建頭文件testdll.h
testdll.h代碼如下:

#ifndef TestDll_H_
#define TestDll_H_
#ifdef MYLIBDLL
#define MYLIBDLL extern "C" _declspec(dllimport)?
#else
#define MYLIBDLL extern "C" _declspec(dllexport)?
#endif
MYLIBDLL int Add(int plus1, int plus2);
//You can also write like this:
//extern "C" {
//_declspec(dllexport) int Add(int plus1, int plus2);
//};
#endif


------------------------------------------------------

testdll.h也可以寫為:

#pragma once

#ifndef __AFXWIN_H__

? ? //........

#endif

#include<string>

using namespace std;

//數(shù)據(jù)、類型定義等

#define OUTAPI __declspec(dllexport)

OUTAPI int Add(int a, int b);



2、新建源文件testdll.cpp
testdll.cpp代碼如下:

#include "stdafx.h"
#include "testdll.h"
#include <iostream>
using namespace std;
int Add(int plus1, int plus2)
{
int add_result = plus1 + plus2;
return add_result;
}




3、新建模塊定義文件mydll.def
mydll.def代碼如下:

LIBRARY "MyDLL"
EXPORTS
Add ??@1


4、vs2010自動創(chuàng)建dllmain.cpp文件,它定義了DLL 應(yīng)用程序的入口點(diǎn)。

dllmain.cpp代碼如下:
// dllmain.cpp : 定義 DLL 應(yīng)用程序的入口點(diǎn)。
#include "stdafx.h"
BOOL APIENTRY DllMain( HMODULE hModule,
? ?? ?? ?? ?? ?? ?? ???DWORD??ul_reason_for_call,
? ?? ?? ?? ?? ?? ?? ???LPVOID lpReserved
? ?? ?)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
??break;
}
return TRUE;
}

最后,編譯生成MyDLL.dll文件和MyDLL.lib文件。



1>------ 已啟動生成: 項(xiàng)目: MyDLL, 配置: Debug Win32 ------

1> ?dllmain.cpp

========== 生成: 成功 1 個(gè),失敗 0 個(gè),最新 0 個(gè),跳過 0 個(gè) ==========

?

1>------ 已啟動生成: 項(xiàng)目: MyDLL, 配置: Debug Win32 ------

1> ?stdafx.cpp

1> ?testdll.cpp

1> ?MyDLL.cpp

1> ?正在生成代碼...

1> ? ? 正在創(chuàng)建庫 D:\Visual C++\工程\Libaray\MyDLL\Debug\MyDLL.lib 和對象 D:\Visual C++\工程\Libaray\MyDLL\Debug

【生成的DLL用DLL查看器,看到的導(dǎo)出函數(shù)名:Add,沒有多余的奇怪字符】

總結(jié)

以上是生活随笔為你收集整理的VS2010中 C++创建DLL图解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。