vs2019建立Dll例子

2021-03-04 03:08:52 字數 2445 閱讀 2453

vs2010建立dll例子,並解決執行錯誤:應用程式正常初始化(0xc000000d)失敗。請單擊「確定」,終止應用程式。

呼叫dll的工程遇到應用程式正常初始化(0xc000000d)失敗。請單擊「確定」,終止應用程式。

我的開發環境是win32 xp,vs2010

最終找到原因,之前使用的是debug模式,應該使用release來編譯生成dll,使用才不會出錯,特此記錄整個配置過程以備忘,折騰免疫hoho~:

1、新建win32工程,選擇dll,工程名叫mydll

2、新增header files:testdll.h,內容如下:

[cpp] view plaincopyprint?

1. #ifndeftestdll_h_

2. #defi***estdll_h_

3. 4. #ifdefmydll_exports

5. #definemylibdllextern"c"_declspec(dllexport)

6. #else

7. #definemylibdllextern"c"_declspec(dllimport)

8. #endif

9. 10. extern"c"

11. ;

14. #endif#ifndef testdll_h_

#define testdll_h_

#ifdef mydll_exports

#define mylibdll extern "c" _declspec(dllexport)

#else

#define mylibdll extern "c" _declspec(dllimport)

#endif

extern "c"

;#endif

3、新增source files:testdll.cpp,內容如下:

[cpp] view plaincopyprint?

1. #include"stdafx.h"

2. #include"testdll.h"

3. #include

4. usingnamespacestd;

5. 6. intadd(intplus1,intplus2)

7. #include "stdafx.h"#include "testdll.h"

#include

using namespace std;

int add(int plus1, int plus2)

4、選擇編譯型別為:release(注意,之前我一直使用debug模式就會遇到各種錯誤無法使用,為什麼請知道的大俠賜教,不勝感激?)

5、編譯輸出.lib和.dll檔案。

6、將testdll.h、mydll.lib、mydll.

dll三個檔案放在新建的目錄libs中,並放在下乙個工程的專案資料夾裡(和mydlldemo.sln 同在乙個資料夾下)。

1、新建win32 console工程,命名為mydlldemo

2、修改mydlldemo.cpp檔案內容如下:

[cpp] view plaincopyprint?

1. #include"stdafx.h"

2. 3. #include

4. usingnamespacestd;

5. 6. #include"testdll.h"

7. //#pragma***ment(lib,"mydll.lib")

8. 9. intmain()

10.#include "stdafx.h"

#include

using namespace std;

#include "testdll.h"

//#pragma ***ment(lib,"mydll.lib")

int main()

3、配置標頭檔案查詢路徑:

properties -> c/c++ -> general -> additional include directories -> 輸入libs的絕對目錄,如d:\sonikk\project\c++\console32\mydlldemo\libs

4、配置.lib檔案查詢路徑:

properties -> linker ->general -> additional library directories -> 輸入libs的絕對目錄,如d:\sonikk\project\c++\console32\mydlldemo\libs

5、配置要匯入的.lib檔案(和**中使用 #pragma ***ment(lib,"mydll.lib") 語句效果相同):

properties -> linker -> input -> additional library directories -> mydll.lib

6、配置.dll檔案查詢目錄:

將mydll.lib放在mydlldemo工程的debug目錄下,和編譯生成的exe一起。

最終執行效果,ok~

VS2019快捷鍵大全

ctrl m crtr o摺疊所有大綱 ctrl m crtr p 停止大綱顯示ctrl k crtr c 注釋選定內容ctrl k crtr u 取消選定注釋內容ctrl j 列出成員智慧型感知 shift alt enter 切換全屏編輯ctrl b,t ctrl k,k 切換書籤開關ctrl ...

vs2019快捷方便以及設定方法

vs2010快捷鍵設定 1.進入工具 選項對話方塊 2.選擇環境 鍵盤 3.在 顯示命令包含 下面的對話方塊中輸入 對齊 關鍵字,然後就會在這個編輯框下面乙個文字視窗中顯示關於 對齊 一系列的 某某對齊 操作命令,選中你想檢視的,就會在 選定命令的快捷鍵 一欄中顯示其快捷鍵了 vs2010快捷鍵 c...

VS2019不能除錯的解決方案

解決windows作業系統在處理回環位址 1 第一種解決方案是禁用環迴檢查。步驟如下 a依次單擊 開始 和 執行 鍵入 regedit,然後單擊 確定 b 在登錄檔編輯器中,找到並單擊下面的登錄檔項 hkey local machine system currentcontrolset contro...