Runtime.loadLibrary
と を使用して Win32 API 関数をロードしたいと考えていますGetProcAddress(...)
。使用mixin
:
template GetProcA(alias func, alias name_in_DLL)
{
const char[] GetProcA = func ~ ` = cast(typeof(`~func~`)) GetProcAddress(hModule,"`~name_in_DLL~`");`;
}
...
static extern (Windows) Object function (HWND hWnd, int nIndex) GetWindowLong;
static extern (Windows) Object function (HWND hWnd, int nIndex, Object dwNewLong) SetWindowLong;
この方法で (クラス コンストラクターで) インスタンス化できます。
mixin GetProcA!("SetWindowLong", "SetWindowLongA");
ただし、別の機能に再度使用する場合:
mixin GetProcA!("GetWindowLong", "GetWindowLongA");
コンパイラは文句を言います:
mixin GetProcA!("GetWindowLong","GetWindowLongA") GetProcA isn't a template...
要点がわかりません。最初のインスタンス化が作成されGetProcA
、それを再度使用できない場合、ここでどのように役立ちますか?