www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Mixins and extern(Windows)

/*--------------------------
test 1
-------------------------*/

template Macro(alias a)
{
int main(char[][] args)
{
a();
return 0;
{
}

int Foo()
{
return 3;
}

mixin Macro!(Foo);

/*----------------------------*/

it compiles flawlessy, no problem in inlining the parametrized mixin code as te
executable's main function, but when it comes to Win32 programming something
strange happens:

/*----------------------------
test 2
----------------------------*/

import std.c.windows.windows;


extern (C) void gc_init();
extern (C) void gc_term();
extern (C) void _minit();
extern (C) void _moduleCtor();
extern (C) void _moduleUnitTests();

template Macro(alias a)
{
extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int
nCmdShow)
{
int result;

gc_init();			// initialize garbage collector
_minit();			// initialize module constructor table

try
{
_moduleCtor();		// call module constructors
_moduleUnitTests();	// run unit tests (optional)

result = a(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}

catch (Object o)		// catch any uncaught exceptions
{
//MessageBoxW(null, cast(wchar *)o.toString(), "Error", MB_OK |
MB_ICONEXCLAMATION);
result = 0;		// failed
}

gc_term();			// run finalizers; terminate garbage collector
return result;
}
}

int pippo(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int
nCmdShow)
{
return 3;
}

mixin Macro!(pippo);

/*-----------------------------------*/

now the strange thing: the linker cannot find _WinMain 16 simbol and reference.
After some tests I've found that it acts like the extern(Windows) attribute is
ignored (in other words it gives the same error if WinMain is declared normally,
not in a template, and the extern(Windows) attribute is missing). So I've tried
putting it on both the template definition and the mixin
statement but there was nothing to do :-(

"When Rome will Fall
Then the World"
Mar 17 2005