module main;

import std.c.windows.windows;
import core.sys.windows.dll;
import std.c.stdio;
import printtlsinfo;

version(dll1) {
	enum name = "DDynamicLib1";
	enum val = 100;
	export extern(C) int get7_1() { return val + 7; }
} else version(dll2) {
	enum name = "DDynamicLib2";
	enum val = 200;
	export extern(C) int get7_2() { return val + 7; }
} else version(dll3) {
	enum name = "DDynamicLib3";
	enum val = 300;
	export extern(C) int get7_3() { return val + 7; }
} else
	static assert(0);

int tlsVar = val;

extern (Windows)
BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved) {
    printf(name ~ ".DllMain: hModule = %X, reason = %i, reserved = %i\n", hInstance, ulReason, pvReserved);
	version(all) final switch (ulReason) {
		case DLL_PROCESS_ATTACH: dll_process_attach( hInstance, true ); break;
		case DLL_PROCESS_DETACH: dll_process_detach( hInstance, true ); break;
		case DLL_THREAD_ATTACH:  dll_thread_attach( true, true ); break;
		case DLL_THREAD_DETACH:  dll_thread_detach( true, true ); break;
    }
	printTlsInfo();
	return true;
}
