PDF download Unduh PDF PDF download Unduh PDF

Berkas DLL adalah berkas pustaka tertaut dinamika yang ditulis dan dikendalikan melalui bahasa pemrograman C++. DLL mempermudah proses pembagian dan penyimpanan kode. Artikel wikiHow ini akan mengajarkan kepada Anda cara membuat berkas DLL menggunakan Visual Studio , aplikasi Windows, atau Visual Studio untuk Mac. Pastikan Anda menandai opsi “ Desktop Development with C++ ” pada proses instalasi program. Jika Anda sudah memiliki program Visual Studio, tetapi tidak mencentang kotak opsi tersebut, Anda harus menjalankan kembali berkas pemasangan untuk memastikan kotak dapat ditandai.

Langkah

PDF download Unduh PDF
  1. Anda bisa menemukan program ini pada menu “Start” atau folder “ Applications ”. Karena berkas DLL merupakan pustaka informasi, berkas ini merupakan satu “potongan” proyek dan biasanya membutuhkan aplikasi pendamping agar dapat diakses.
  2. Tab ini berada di atas area proyek (Windows) atau di atas layar (Mac).
  3. Kotak dialog “ Create a New Project ” akan ditampilkan.
  4. Aspek-aspek ini akan menyaring templat-templat proyek yang ditampilkan.
    • Klik “ Language ” untuk menampilkan menu drop-down dan klik “ C++ ”.
  5. Pilihan akan ditandai dengan warna biru. Klik “ Next ” untuk melanjutkan.
  6. Sebagai contoh, Anda bisa mengetikkan “MathLibrary” pada kolom sebagai contoh nama.
  7. Proyek DLL akan dibuat.
  8. Anda bisa menambahkannya dengan mengeklik “ Add New Item ” dari “ Project ” pada bilah menu.
    • Pilih “ Visual C++ ” dari menu di sisi kiri kotak dialog.
    • Pilih “ Header file (.h) ” dari tengah kotak dialog.
    • Tikkan nama, misalnya, “MathLibrary.h” pada kolom nama di bawah opsi-opsi menu.
    • Klik “ Add ” untuk membuat berkas kepala kosong.
    •  // MathLibrary.h - Contains declarations of math functions 
       #pragma once 
       #ifdef MATHLIBRARY_EXPORTS 
       #define MATHLIBRARY_API __declspec(dllexport) 
       #else 
       #define MATHLIBRARY_API __declspec(dllimport) 
       #endif 
       // The Fibonacci recurrence relation describes a sequence F 
       // where F(n) is { n = 0, a 
       //               { n = 1, b 
       //               { n > 1, F(n-2) + F(n-1) 
       // for some initial integral values a and b. 
       // If the sequence is initialized F(0) = 1, F(1) = 1, 
       // then this relation produces the well-known Fibonacci 
       // sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34, ... 
       // Initialize a Fibonacci relation sequence 
       // such that F(0) = a, F(1) = b. 
       // This function must be called before any other function. 
       extern 
       "C" 
       MATHLIBRARY_API 
       void 
       fibonacci_init 
       ( 
       const 
       unsigned 
       long 
       long 
       a 
       , 
       const 
       unsigned 
       long 
       long 
       b 
       ); 
       // Produce the next value in the sequence. 
       // Returns true on success and updates current value and index; 
       // false on overflow, leaves current value and index unchanged. 
       extern 
       "C" 
       MATHLIBRARY_API 
       bool 
       fibonacci_next 
       (); 
       // Get the current value in the sequence. 
       extern 
       "C" 
       MATHLIBRARY_API 
       unsigned 
       long 
       long 
       fibonacci_current 
       (); 
       // Get the position of the current value in the sequence. 
       extern 
       "C" 
       MATHLIBRARY_API 
       unsigned 
       fibonacci_index 
       (); 
      
    • Kode di atas merupakan contoh kode yang diambil dari situs web layanan bantuan Microsoft.
  9. Anda bisa menambahkannya dengan mengeklik “ Add New Item ” dari “ Project ” pada bilah menu.
    • Pilih “ Visual C++ ” dari menu di sisi kiri kotak dialog.
    • Pilih “ C++ File (.cpp) ” dari bagian tengah kotak dialog.
    • Tikkan nama “MathLibrary.cpp” pada kolom nama di bawah opsi-opsi menu.
    • Klik “ Add ” untuk membuat berkas kosong.
    •  // MathLibrary.cpp : Defines the exported functions for the DLL. 
       #include 
       "stdafx.h" // use pch.h in Visual Studio 2019 
        
       #include 
       <utility> 
        
       #include 
       <limits.h> 
        
       #include 
       "MathLibrary.h" 
        
       // DLL internal state variables: 
       static 
       unsigned 
       long 
       long 
       previous_ 
       ; 
       // Previous value, if any 
       static 
       unsigned 
       long 
       long 
       current_ 
       ; 
       // Current sequence value 
       static 
       unsigned 
       index_ 
       ; 
       // Current seq. position 
       // Initialize a Fibonacci relation sequence 
       // such that F(0) = a, F(1) = b. 
       // This function must be called before any other function. 
       void 
       fibonacci_init 
       ( 
       const 
       unsigned 
       long 
       long 
       a 
       , 
       const 
       unsigned 
       long 
       long 
       b 
       ) 
       { 
       index_ 
       = 
       0 
       ; 
       current_ 
       = 
       a 
       ; 
       previous_ 
       = 
       b 
       ; 
       // see special case when initialized 
       } 
       // Produce the next value in the sequence. 
       // Returns true on success, false on overflow. 
       bool 
       fibonacci_next 
       () 
       { 
       // check to see if we'd overflow result or position 
       if 
       (( 
       ULLONG_MAX 
       - 
       previous_ 
       < 
       current_ 
       ) 
       || 
       ( 
       UINT_MAX 
       == 
       index_ 
       )) 
       { 
       return 
       false 
       ; 
       } 
       // Special case when index == 0, just return b value 
       if 
       ( 
       index_ 
       > 
       0 
       ) 
       { 
       // otherwise, calculate next sequence value 
       previous_ 
       += 
       current_ 
       ; 
       } 
       std 
       :: 
       swap 
       ( 
       current_ 
       , 
       previous_ 
       ); 
       ++ 
       index_ 
       ; 
       return 
       true 
       ; 
       } 
       // Get the current value in the sequence. 
       unsigned 
       long 
       long 
       fibonacci_current 
       () 
       { 
       return 
       current_ 
       ; 
       } 
       // Get the current index position in the sequence. 
       unsigned 
       fibonacci_index 
       () 
       { 
       return 
       index_ 
       ; 
       } 
      
    • Kode di atas merupakan contoh kode yang diambil dari situs web layanan bantuan Microsoft.
  10. Opsi ini berada di atas area proyek (Windows) atau di atas layar (Mac).
  11. Setelah opsi diklik, Anda dapat melihat teks seperti ini:
       1 
       >------ 
       Build 
       started 
       : 
       Project 
       : 
       MathLibrary 
       , 
       Configuration 
       : 
       Debug 
       Win32 
       
      1 > MathLibrary . cpp 1 > dllmain . cpp 1 > Generating Code ... 1 > Creating library C : \ Users \ username \ Source \ Repos \ MathLibrary \ Debug \ MathLibrary . lib and 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 ( Partial PDB ) ========== Build : 1 succeeded , 0 failed , 0 up - to - date , 0 skipped ==========
    • Jika kreasi atau proyek DLL Anda berhasil, Anda bisa melihatnya pada halaman ini. Jika terdapat galat pada proyek, galat akan ditampilkan agar Anda bisa memperbaikinya. [1]
    Iklan

Tentang wikiHow ini

Halaman ini telah diakses sebanyak 3.184 kali.

Apakah artikel ini membantu Anda?

Iklan