Skip to content

Commit 620a388

Browse files
jll63claude
andcommitted
samples/windll: print_answer in plugin, remove copyright notices
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a80aa4d commit 620a388

4 files changed

Lines changed: 10 additions & 28 deletions

File tree

samples/windll/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
# Copyright (c) 2018-2025 Jean-Louis Leroy
2-
# Distributed under the Boost Software License, Version 1.0.
3-
# See accompanying file LICENSE_1_0.txt
4-
# or copy at http://www.boost.org/LICENSE_1_0.txt)
5-
61
# Illustrates the dllvar technique: the exe owns (exports) a variable; the
72
# DLL imports it. Both see static_answer<answer_dllvar, void>::value as the
83
# same linker symbol because the varying base class does not enter the mangled
94
# name; SFINAE selects dllexport in the owner and dllimport in the client.
105

6+
cmake_minimum_required(VERSION 4.2)
7+
118
if (NOT (WIN32 OR CYGWIN))
129
return()
1310
endif()

samples/windll/main.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// Copyright (c) 2018-2025 Jean-Louis Leroy
2-
// Distributed under the Boost Software License, Version 1.0.
3-
// See accompanying file LICENSE_1_0.txt
4-
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5-
61
// Owner: answer_dllvar derives from dllexport_tag here.
72
#define WINDLL_OWNER
83
#include "shared.hpp"
@@ -13,8 +8,9 @@ int main() {
138
answer() = 42;
149
auto plugin = LoadLibraryA("windll_plugin.dll");
1510
assert(plugin);
16-
auto get_answer = reinterpret_cast<int(*)()>(
17-
GetProcAddress(plugin, "get_answer"));
18-
assert(get_answer() == 42);
11+
auto print_answer = reinterpret_cast<void(*)()>(
12+
GetProcAddress(plugin, "print_answer"));
13+
assert(print_answer);
14+
print_answer(); // prints "answer = 42"
1915
FreeLibrary(plugin);
2016
}

samples/windll/plugin.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
// Copyright (c) 2018-2025 Jean-Louis Leroy
2-
// Distributed under the Boost Software License, Version 1.0.
3-
// See accompanying file LICENSE_1_0.txt
4-
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5-
61
// Client: answer_dllvar derives from dllimport_tag here (no WINDLL_OWNER).
72
#include "shared.hpp"
3+
#include <cstdio>
84

9-
// answer() returns a reference to static_answer<answer_dllvar, void>::value —
10-
// the one shared linker symbol — bound via dllimport.
11-
extern "C" __declspec(dllexport) int get_answer() { return answer(); }
5+
extern "C" __declspec(dllexport) void print_answer() {
6+
printf("answer = %d\n", answer());
7+
}

samples/windll/shared.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// Copyright (c) 2018-2025 Jean-Louis Leroy
2-
// Distributed under the Boost Software License, Version 1.0.
3-
// See accompanying file LICENSE_1_0.txt
4-
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5-
61
#pragma once
72
#include <type_traits>
83

@@ -48,6 +43,4 @@ struct static_answer<Tag,
4843
static __declspec(dllimport) int value;
4944
};
5045

51-
// Accessor: always refers to static_answer<answer_dllvar, void>::value —
52-
// the one shared linker symbol — regardless of which specialization is active.
5346
inline int& answer() { return static_answer<answer_dllvar>::value; }

0 commit comments

Comments
 (0)