/**
 * Sal Module.
 *
 * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>
 * Authors: Nomura Kei
 * Copyright: Copyright(c) 2013 Nomura Kei
 */
module jp.ehobby.sal;

/+
private
{
	import core.runtime;
	import std.string;
	import std.c.stdio;
	import std.c.stdlib;
}

extern (C)
{
	void gc_setProxy(void* p);
	void gc_clrProxy();
}


/**
 * DLL を初期化します.
 *
 * Params:
 *	gc	= GC関数へのポインタ
 */
export
void DLL_initialize(void* gc = null)
{
	if (gc != null) { gc_setProxy(gc); }
	Runtime.initialize();
}


/**
 * DLL の終了処理をします.
 */
export
void DLL_terminate()
{
	version (Windows) {
		std.c.stdio._fclose = null;
	} else {
		gc_clrProxy();
	}
	Runtime.terminate();
}


version (Windows)
{	// version (Windows)
	import std.c.windows.windows;
	
	extern (Windows)
	BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
	{
		swtich (ulReason)
		{
			case DLL_PROCESS_ATTACH:	DLL_initialize();	break;
			case DLL_PROCESS_DETACH:	DLL_terminate();	break;
			case DLL_THREAD_ATTACH:							break;
			case DLL_THREAD_DETACH:							break;
			default:					// NOP
		}
		return true;
	}
}
+/
