I want to load Win32 API functions using Runtime.loadLibrary
and GetProcAddress(...)
. Using 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;
I can instantiate it (in the class constructor) this way:
mixin GetProcA!("SetWindowLong", "SetWindowLongA");
but if use it again for another function:
mixin GetProcA!("GetWindowLong", "GetWindowLongA");
the compiler complains:
mixin GetProcA!("GetWindowLong","GetWindowLongA") GetProcA isn't a template...
I don't see the point: if the first instantiation created GetProcA
and I can't use it again, so how does it help me here ?
Judging from your code, you want a mixin expression, not template mixin:
Actually, you don't even need a mixin. An inner template function is enough: