해석 VC에서 DLL을 만들고 전역 변수, 함수 및 클래스를 내보내는 심도 있는 분석
1. VC에서 Win32 빈 항목MathLib을 새로 만듭니다.2. 사전 컴파일 헤더 파일 stdafx를 추가합니다.h, 가져오기 내보내기 제어 기호를 정의합니다.
//stdafx.h
#pragma once
#define MATHLIB_EXPORT
3. 내보낼 전역 변수, 함수 및 클래스를 포함하는 헤더 파일MathLib을 추가합니다.h:
//MathLib.h
#pragma once
#ifdef MATHLIB_EXPORT
#define MATHLIBAPI __declspec(dllexport)
#else
#define MATHLIBAPI __declspec(dllimport)
#endif
//macro
#define PI 3.14149
//Global variable
extern MATHLIBAPI int GlobalVariable;
//Function
MATHLIBAPI int Add(int a,int b);
//Class
class MATHLIBAPI Math
{
public:
int Multiply(int a,int b);
};
4. 내보낸 요소의 구현 파일인 MathLib을 추가합니다.cpp
//MathLib.cpp
#include "stdafx.h"
#include "MathLib.h"
int GlobalVariable = 100;
int Add(int a,int b)
{
return a+b;
}
int Math::Multiply(int a,int b)
{
return a*b;
}
둘째, 생성된 DLL 테스트 코드를 테스트합니다.
#include "stdafx.h"
#include
using namespace std;
#include "../MathLib/MathLib.h"
#pragma comment(lib,"../Debug/MathLib.lib")
int _tmain(int argc, _TCHAR* argv[])
{
cout<
cout<
int a = 20,b = 30;
cout< cout<
Math math;
cout<
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.