Newer
Older
sample / dworld / plugin_template / src / plugin_main.d
// =============================================================================
//  dworld plugin 基本モジュール
// =============================================================================
module plugin_main;

import core.runtime;
import std.c.stdio;
import std.c.stdlib;
import std.string;

import std.stdio;

import dworld.plugin;

/**
 * プラグインのメインクラスをロードして返します.
 * 本メソッドは, dworld.plugin モジュールのメソッドとして下さい.
 */
export Plugin loadPlugin()
{
	return new SamplePlugin();
}


/**
 * Plugin メインクラス.
 */
class SamplePlugin : Plugin
{

	/**
	 * 本プラグインのメジャーバージョンを返します.
	 *
	 * Return:
	 *	Major バージョン
	 */
	public override
	int getMajorVersion() { return 1; }


	/**
	 * 本プラグインのマイナーバージョンを返します.
	 *
	 * Return:
	 *	Minor バージョン
	 */
	public override
	int getMinorVersion() { return 0; }


	/**
	 * プラグイン開始時に呼び出されます.
	 *
	 * Params:
	 *	context = プラグインコンテキスト
	 */
	public override
	void start(PluginContext context)
	{
		writefln("START PLUGIN");
	}


	/**
	 * プラグイン終了時に呼び出されます.
	 *
	 * Params:
	 *	context = プラグインコンテキスト
	 */
	public override
	void stop(PluginContext context)
	{
		writefln("STOP PLUGINS");
	}
}



// -----------------------------------------------------------------------------
//  以下, Windows の場合の DllMain
// -----------------------------------------------------------------------------
version (Windows)
{

import std.c.windows.windows;
extern (Windows)
	BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
{
	switch (ulReason)
	{
		case DLL_PROCESS_ATTACH:
			debug { printf("DLL_PROCESS_ATTACH\n");	}
			Runtime.initialize();
			break;

		case DLL_PROCESS_DETACH:
			debug { printf("DLL_PROCESS_DETACH\n");	}
			std.c.stdio._fcloseallp = null;				// so stdio doesn't get closed
			Runtime.terminate();
			break;

		case DLL_THREAD_ATTACH:
			debug { printf("DLL_THREAD_ATTACH\n");	}
			break;

		case DLL_THREAD_DETACH:
			debug { printf("DLL_THREAD_DETACH\n");	}
			break;

		default:
	}
	return true;
}
}