PDF 다운로드 PDF 다운로드

DLL 파일은 C++로 작성하고 제어하는 동적 링크 라이브러리 파일이다. DLL은 코드를 간편하게 공유하고 저장할 수 있다. 이 글을 통해 PC용 비주얼 스튜디오 나 맥용 비주얼 스튜디오 ]로 DLL 파일을 만드는 방법을 알아보자. 설치할 때 "C++를 사용한 데스크톱 개발"에 체크해야 한다. 이미 비주얼 스튜디오가 있지만 체크를 하지 않은 경우 설치 프로그램을 다시 실행해 확실히 설치한다.

  1. 시작 메뉴나 응용 프로그램 폴더에서 있다. DLL은 정보 라이브러리이기 때문에 프로젝트의 일부일 뿐이며 액세스하려면 관련 응용 프로그램이 필요하다.
  2. 을 클릭한다. 프로젝트 공간(PC)위 또는 화면 상단(맥)에 있다.
  3. 프로젝트 를 클릭한다. "새 프로젝트 만들기" 대화 상자가 나타난다.
  4. 이에 따라 프로젝트 템플릿이 정해진다.
    • "언어"를 클릭해 드롭다운 메뉴를 펼치고 "C++"를 클릭한다.
  5. 를 클릭한다. 파란색으로 강조된다. "다음"을 클릭해 계속한다.
  6. 예를 들어 이름 상자에 "MathLibrary"를 입력한다.
  7. 를 클릭한다. DLL 프로젝트가 생성된다.
  8. 메뉴 모음의 "프로젝트"에서 "새 항목 추가"를 클릭한다.
    • 대화 상자의 왼쪽 메뉴에서 "Visual C++"를 선택한다.
    • 대화 상자 가운데에서 "헤더 파일(.h)"을 선택한다.
    • 메뉴 선택 아래 이름란에 "MathLibrary.h"를 입력한다.
    • "추가"를 클릭해 빈 헤더 파일을 만든다.
    •  // 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 
       (); 
      
    • 이것은 마이크로소프트 도움말 사이트에서 제공하는 샘플 코드이다.
  9. 메뉴 모음의 "프로젝트"에서 "새 항목 추가"를 클릭한다.
    • 대화 상자의 왼쪽 메뉴에서 "Visual C++"를 선택한다.
    • 대화 상자 가운데에서 "C++파일(.cpp)"을 선택한다.
    • 메뉴 선택 아래 이름란에 "MathLibrary.cpp"을 입력한다.
    • "추가"를 클릭해 빈 파일을 만든다.
    •  // 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_ 
       ; 
       } 
      
    • 이것은 마이크로소프트 도움말 사이트에서 제공하는 샘플 코드이다.
  10. 프로젝트 공간(PC)위 또는 화면 상단(맥)에 있다.
  11. 를 클릭한다. 클릭하면 다음과 같은 텍스트가 나타난다.
       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 ==========
    • DLL 만들기에 성공했다면 여기에서 볼 수 있다. 오류가 발생한 경우 수정할 수 있도록 여기에 나타난다. [1]
    광고


이 위키하우에 대하여

이 문서는 10,956 번 조회 되었습니다.

이 글이 도움이 되었나요?

광고