Dll2.dll
This file defines the interface for applications using the DLL.
#pragma once #ifdef DLL2_EXPORTS #define DLL2_API __declspec(dllexport) #else #define DLL2_API __declspec(dllimport) #endif // Exported function extern "C" DLL2_API int AddNumbers(int a, int b); // Exported class class DLL2_API Dll2Class { public: Dll2Class(void); int MultiplyNumbers(int a, int b); }; Use code with caution. 2. Dll2.cpp (Source File) This file contains the actual logic. Dll2.dll
#include "pch.h" // Remove if not using precompiled headers #include "Dll2.h" #include // Initialize DLL_EXPORTS symbol in project properties #define DLL2_EXPORTS // Implementation of the exported function extern "C" DLL2_API int AddNumbers(int a, int b) { return a + b; } // Implementation of the exported class Dll2Class::Dll2Class(void) {} int Dll2Class::MultiplyNumbers(int a, int b) { return a * b; } Use code with caution. 3. dllmain.cpp (DLL Entry Point) This is standard Windows code for initializing the DLL. This file defines the interface for applications using
This example creates a simple DLL that exports an addition function and a class method. 1. Dll2.h (Header File) dllmain
You must compile this project as a "Dynamic-Link Library (DLL)" in your IDE to generate the .dll and .lib files.