Yuav Ua Li Cas Tsim DLL Cov Ntaub Ntawv: 10 Kauj Ruam (nrog Duab)

Cov txheej txheem:

Yuav Ua Li Cas Tsim DLL Cov Ntaub Ntawv: 10 Kauj Ruam (nrog Duab)
Yuav Ua Li Cas Tsim DLL Cov Ntaub Ntawv: 10 Kauj Ruam (nrog Duab)

Video: Yuav Ua Li Cas Tsim DLL Cov Ntaub Ntawv: 10 Kauj Ruam (nrog Duab)

Video: Yuav Ua Li Cas Tsim DLL Cov Ntaub Ntawv: 10 Kauj Ruam (nrog Duab)
Video: Xov xwm 23/07/2023 7 Tu Suav Coj Pab Nkauj Hmoob Rau Ceev Xwm Khi Lawm 2024, Kaum ib hlis
Anonim

DLL cov ntaub ntawv yog cov ntaub ntawv txuas nrog cov ntaub ntawv khaws tseg thiab tswj hwm los ntawm C ++ cov lus programming. DLLs ua kom yooj yim rau txheej txheem sib koom thiab khaws cov cai. Qhov wikiHow qhia koj yuav tsim DLL cov ntaub ntawv siv Visual Studio, Windows applications, lossis Visual Studio for Mac. Nco ntsoov tias koj txheeb xyuas "Kev Txhim Kho Duab nrog C ++" kev xaiv hauv cov txheej txheem kev teeb tsa. Yog tias koj twb muaj Visual Studio program, tab sis tsis khij lub npov rau qhov kev xaiv ntawd, koj yuav tsum tau khiav cov ntawv teeb tsa dua kom paub tseeb tias lub thawv tuaj yeem tshawb xyuas.

Kauj ruam

11227960 1
11227960 1

Kauj Ruam 1. Qhib Visual Studio

Koj tuaj yeem pom qhov haujlwm no hauv "Start" menu lossis hauv "Applications" folder. Vim tias DLL cov ntaub ntawv yog lub tsev qiv ntawv xov xwm, nws yog "ntu" ntawm qhov phiaj xwm thiab feem ntau xav tau daim ntawv thov ua khub kom nkag mus tau.

  • Koj tuaj yeem rub Visual Studio rau Windows ntawm lub xaib no:
  • Visual Studio rau Mac tuaj yeem rub tawm ntawm no:
  • Qhov wikiHow siv cov cai los ntawm Microsoft los piav qhia yuav tsim DLL cov ntaub ntawv li cas.
11227960 2
11227960 2

Kauj Ruam 2. Nyem Cov Ntaub Ntawv

Cov ntawv no yog nyob rau sab saum toj ntawm thaj chaw ua haujlwm (Windows) lossis nyob rau sab saum toj ntawm lub vijtsam (Mac).

11227960 3
11227960 3

Kauj Ruam 3. Nyem Tshiab thiab Tej yaam num

Lub thawv "Tsim Txoj Haujlwm Tshiab" yuav tshwm.

11227960 4
11227960 4

Kauj Ruam 4. Qhia meej cov kev xaiv rau “Yam Lus”, “Platform”, thiab “Project Type” yam

Cov yam no yuav lim cov phiaj xwm phiaj xwm uas tau tshwm sim.

Nyem " Lus "Kom pom cov ntawv qhia zaub mov nco-down thiab nyem" C ++ ”.

11227960 5
11227960 5

Kauj Ruam 5. Nyem “Platforms "Kom pom cov ntawv qhia zaub mov nco-down thiab nyem" Windows "ua.

11227960 6
11227960 6

Kauj Ruam 6. Nyem “Hom Project "Kom pom cov ntawv qhia zaub mov nco-down thiab xaiv" Cov tsev qiv ntawv ".

11227960 7
11227960 7

Kauj Ruam 7. Nyem Dynamic-link Library (DLL)

Cov kev xaiv yuav raug cim ua xiav. Nyem " Tom ntej no "mus ntxiv.

11227960 8
11227960 8

Kauj Ruam 8. Ntaus lub npe lub phiaj xwm hauv daim teb "Npe Npe"

Piv txwv li, koj tuaj yeem ntaus “MathLibrary” hauv kab ntawv ua piv txwv lub npe.

11227960 9
11227960 9

Kauj ruam 9. Nyem Tsim

Ib txoj haujlwm DLL yuav raug tsim.

11227960 10
11227960 10

Kauj ruam 10. Ntxiv cov ntaub ntawv header rau DLL project

Koj tuaj yeem ntxiv nws los ntawm txhaj "Ntxiv Yam Khoom Tshiab" los ntawm "Project" ntawm cov ntawv qhia zaub mov.

  • Xaiv " Pom C ++ "Los ntawm cov ntawv qhia zaub mov ntawm sab laug ntawm lub npov lus.
  • Xaiv " Cov ntaub ntawv headers (.h) "Los ntawm nruab nrab ntawm lub thawv sib tham.
  • Ntaus lub npe, piv txwv li, “MathLibrary.h” rau hauv lub npe teb hauv qab cov ntawv qhia zaub mov.
  • Nyem " Ntxiv "Los tsim cov ntaub ntawv header khoob.
11227960 11
11227960 11

Kauj Ruam 11. Ntaus cov cai hauv qab no rau hauv cov ntaub ntawv header dawb

    // MathLibrary.h - Muaj cov lus tshaj tawm ntawm kev ua lej #pragma ib zaug #ifdef MATHLIBRARY_EXPORTS #define MATHLIBRARY_API _declspec (dllexport) #else #define MATHLIBRARY_API _declspec (dllimport) #piav qhia txog qhov twg) yog {n = 0, a // {n = 1, b // {n> 1, F (n-2) + F (n-1) // rau qee qhov pib qhov tseem ceeb a thiab b. // Yog hais tias cov ntu tau pib F (0) = 1, F (1) = 1, // ces qhov kev sib raug zoo no ua rau muaj kev paub Fibonacci // ntu: 1, 1, 2, 3, 5, 8, 13, 21, 34,… // Pib Fibonacci sib txheeb ua ntu zus // xws li F (0) = a, F (1) = b. // Txoj haujlwm no yuav tsum raug hu ua ntej lwm qhov haujlwm. extern "C" MATHLIBRARY_API tsis muaj dab tsi fibonacci_init (const unsigned ntev ntev a, const unsigned ntev ntev b); // Ua tus nqi tom ntej hauv ntu. // Rov qab muaj tseeb ntawm kev ua tiav thiab hloov kho tus nqi tam sim no thiab ntsuas; // tsis tseeb ntawm qhov txeej, tawm tus nqi tam sim no thiab ntsuas tsis hloov pauv. extern "C" MATHLIBRARY_API bool fibonacci_next (); // Tau txais tus nqi tam sim no hauv ntu. extern "C" MATHLIBRARY_API unsigned ntev ntev fibonacci_current (); // Tau txais txoj haujlwm ntawm tus nqi tam sim no hauv ntu. extern "C" MATHLIBRARY_API unsigned fibonacci_index ();

  • Cov cai saum toj no yog tus qauv coj los ntawm Microsoft lub vev xaib pabcuam kev pabcuam.
11227960 12
11227960 12

Kauj Ruam 12. Ntxiv CPP cov ntaub ntawv rau DLL txoj haujlwm

Koj tuaj yeem ntxiv nws los ntawm txhaj "Ntxiv Yam Khoom Tshiab" los ntawm "Project" ntawm cov ntawv qhia zaub mov.

  • Xaiv "Visual C ++" los ntawm cov ntawv qhia zaub mov ntawm sab laug ntawm lub npov lus.
  • Xaiv "C ++ Cov Ntaub Ntawv (.cpp)" los ntawm nruab nrab ntawm lub npov lus sib tham.
  • Ntaus lub npe “MathLibrary.cpp” rau hauv lub npe teb hauv qab cov ntawv qhia zaub mov.
  • Nyem "Ntxiv" los tsim cov ntaub ntawv khoob.
11227960 13
11227960 13

Kauj Ruam 13. Ntaus cov cai hauv qab no rau hauv daim ntawv uas tsis muaj dab tsi

    // MathLibrary.cpp: Txhais cov haujlwm xa tawm rau DLL. #include "stdafx.h" // siv pch.h hauv Visual Studio 2019 #include #include #include "MathLibrary.h" // DLL sab hauv lub xeev hloov pauv: zoo li tsis tau kos npe ntev ntev dhau los_; // Tus nqi yav dhau los, yog tias muaj qhov tsis zoo li qub tsis tau kos npe ntev ntev tam sim no_; // Tam sim no ntu ntu tus nqi zoo li qub unsigned index_; // Tam sim no seq txoj hauj lwm // Pib ua Fibonacci sib txheeb sib xws // xws li F (0) = a, F (1) = b. // Txoj haujlwm no yuav tsum raug hu ua ntej lwm qhov haujlwm. tsis muaj dab tsi fibonacci_init (const unsigned ntev ntev a, const unsigned ntev ntev b) {index_ = 0; current_ = ua; ua ntej_ = b; // pom cov ntaub ntawv tshwj xeeb thaum pib ua haujlwm} // Ua tus nqi tom ntej hauv ntu // Rov qab muaj tseeb ntawm kev ua tiav, cuav ntawm kev hla. bool fibonacci_next () {// xyuas seb peb puas yuav dhau los lossis txoj haujlwm yog ((ULLONG_MAX - yav dhau los <<tam sim no)) || (UINT_MAX == index_)) {rov tsis tseeb; } // Cov ntaub ntawv tshwj xeeb thaum ntsuas == 0, tsuas yog xa rov qab b tus nqi yog (index_> 0) {// txwv tsis pub, suav cov lej tom ntej ua ntej dhau los + += tam sim no; } std:: swap (tam sim no, yav dhau los_); ++ index_; rov muaj tseeb; } // Tau txais tus nqi tam sim no hauv ntu. unsigned ntev ntev fibonacci_current () {xa tam sim no_; } // Tau txais txoj haujlwm ntsuas tam sim no hauv ntu. unsigned fibonacci_index () {rov qab index_; }

  • Cov cai saum toj no yog tus qauv coj los ntawm Microsoft lub vev xaib pabcuam kev pabcuam.
11227960 14
11227960 14

Kauj Ruam 14. Nyem Tsim ntawm cov ntawv qhia zaub mov

Qhov kev xaiv no yog nyob rau sab saum toj ntawm qhov project (Windows) lossis nyob rau sab saum toj ntawm lub vijtsam (Mac).

11227960 15
11227960 15

Kauj Ruam 15. Nyem Tsim Kho

Thaum qhov kev xaiv raug nyem, koj tuaj yeem pom cov ntawv zoo li no:

    1> ------ Tsim pib: Project: MathLibrary, Kev teeb tsa: Debug Win32 ------ 1> MathLibrary.cpp 1> dllmain.cpp 1> Tsim Code… 1> Tsim tsev qiv ntawv C: / Cov neeg siv npe / Source / Repos / MathLibrary / Debug / MathLibrary.lib thiab object C: / Users / username / Source / Repos / MathLibrary / Debug / MathLibrary.exp 1> MathLibrary.vcxproj -> C: / Users / username / Source / Repos / MathLibrary / Debug / MathLibrary.dll 1> MathLibrary.vcxproj -> C: / Users / username / Source / Repos / MathLibrary / Debug / MathLibrary.pdb (Ib nrab PDB) ========== Tsim: 1 ua tiav, 0 ua tsis tiav, 0 hloov tshiab, 0 hla ==========

  • Yog tias koj qhov kev tsim lossis DLL txoj haujlwm ua tiav, koj tuaj yeem pom nws ntawm nplooj ntawv no. Yog tias muaj qhov ua yuam kev hauv txoj haujlwm, qhov yuam kev yuav tshwm sim yog li koj tuaj yeem kho nws.

Pom zoo: