mirror of
https://github.com/ElliotKillick/windows-vs-linux-loader-architecture
synced 2026-06-08 10:57:32 +00:00
8f9257c1da
From June to now, most of my time on this project was spent writing "The Rise of Microsoft". Researching and writing that thing took an inordinate amount of time. Also, I took a break to work primarily on another unreleased project I have before switching back to this one. I am proud of what I got here though and I feel like it is all coming together. My plans for the whitepapers are already well drafted and I know they will make an impact. I have learned a ton from working on this project and it has definitely given me something to idly think about and work on in my spare time. Finishing "The Problem with How Windows Uses Threads" was something I thought I wanted done before this release, but oh well. The main README is at about 50K words now, plus all the other smaller documents and you are looking at about a small novel's worth of technical writing. And technical writing takes multiple times longer than typical story writing. Anyway, this project is exciting for me - people who I show it to also really like it - and I am even more excited about what is to come!
59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
#include <windows.h>
|
|
#include <stdio.h>
|
|
|
|
// Layout DllMain before C++ initializtion in the code to try getting it called first (it won't be, the DllMain initializer is always called last)
|
|
|
|
// Yes, puts/printf is unsafe from a module destructor on Windows because it acquires the CRT stdio critical section lock, which could be orphaned
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
|
|
switch (fdwReason) {
|
|
case DLL_PROCESS_ATTACH:
|
|
puts("DllMain: DLL_PROCESS_ATTACH");
|
|
break;
|
|
case DLL_PROCESS_DETACH:
|
|
puts("DllMain: DLL_PROCESS_DETACH");
|
|
break;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
struct A {
|
|
A() {
|
|
puts("A: C++ module constructor");
|
|
}
|
|
|
|
void test() {
|
|
puts("A: Test method");
|
|
}
|
|
|
|
~A() {
|
|
puts("A: C++ module destructor");
|
|
}
|
|
};
|
|
|
|
// Create a new object that is a global instance of the A data type (struct, class, etc.)
|
|
// We create object "a" before object "b" in the code, so object "a" will initialize first
|
|
A a;
|
|
|
|
// A programmer may want to export this object (using __declspec(dllexport)), so other modules can access it
|
|
// Or, a programmer may create an object at the module scope as the C++ way to address cross-cutting concerns
|
|
struct B {
|
|
B() {
|
|
puts("B: C++ module constructor");
|
|
}
|
|
|
|
void test() {
|
|
puts("B: Test method");
|
|
}
|
|
|
|
~B() {
|
|
puts("B: C++ module destructor");
|
|
}
|
|
} b; // Create an instance here, although we could also do it the same way we do for A and even make multiple instances
|
|
|
|
EXTERN_C __declspec(dllexport) void DummyExport() {
|
|
// Exported function that does nothing so we can dynamically link
|
|
puts("Test export");
|
|
}
|