www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Mixin bug?

reply Lox <Lox_member pathlink.com> writes:
Hi guys,
I'm new to D but very very used to C/C++, and as any C/C++ folk i'm fighting
against the lack of preprocessor's macros, recently i've discovered the use of
mixins with templates which seems to enable the creation of parametrized inline
code so one week ago i wrote this little test:

[Code]

extern(Windows)
{
alias uint UINT;
alias void *PVOID;
alias PVOID HANDLE;

alias HANDLE HWND;
alias HANDLE HINSTANCE;

alias wchar WCHAR;
alias WCHAR *LPCWSTR;

alias char CHAR;
alias CHAR *LPSTR;

enum
{
MB_OK = 0x00000000,
MB_OKCANCEL = 0x00000001,
MB_ABORTRETRYIGNORE = 0x00000002,
MB_YESNOCANCEL = 0x00000003,
MB_YESNO = 0x00000004,
MB_RETRYCANCEL = 0x00000005,
MB_CANCELTRYCONTINUE = 0x00000006,
MB_ICONHAND = 0x00000010,
MB_ICONQUESTION = 0x00000020,
MB_ICONEXCLAMATION = 0x00000030,
MB_ICONASTERISK = 0x00000040,
MB_USERICON = 0x00000080,
MB_ICONWARNING = MB_ICONEXCLAMATION,
MB_ICONERROR = MB_ICONHAND,
MB_ICONINFORMATION = MB_ICONASTERISK,
MB_ICONSTOP = MB_ICONHAND,
MB_DEFBUTTON1 = 0x00000000,
MB_DEFBUTTON2 = 0x00000100,
MB_DEFBUTTON3 = 0x00000200,
MB_DEFBUTTON4 = 0x00000300,
MB_APPLMODAL = 0x00000000,
MB_SYSTEMMODAL = 0x00001000,
MB_TASKMODAL = 0x00002000,
MB_HELP = 0x00004000,
MB_NOFOCUS = 0x00008000,
MB_SETFOREGROUND = 0x00010000,
MB_DEFAULT_DESKTOP_ONLY = 0x00020000,
MB_TOPMOST = 0x00040000,
MB_RIGHT = 0x00080000,
MB_RTLREADING = 0x00100000,
MB_SERVICE_NOTIFICATION = 0x00200000,
MB_SERVICE_NOTIFICATION = 0x00040000,
MB_SERVICE_NOTIFICATION_NT3X = 0x00040000,
MB_TYPEMASK = 0x0000000F,
MB_ICONMASK = 0x000000F0,
MB_DEFMASK = 0x00000F00,
MB_MODEMASK = 0x00003000,
MB_MISCMASK = 0x0000C000
}

export int MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT
uType);
}

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

template MainFunc(alias b)
{
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 = b(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 myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int
nCmdShow)
{
return MessageBoxW(null, "Prova riuscita :-D", "Prova in D", MB_OK |
MB_ICONEXCLAMATION);
}

mixin MainFunc!(myWinMain);

[/Code]

now the problem is that with DMD 0.114 it compiled and linked without problems,
but now using DMD 0.116 the linker complains about the undefined simbol
_WinMain 16 and the undefined reference _WinMain 16;
I still haven't tried with the last release U(0.118), anyone can be of any help?

Thnx in advance :-)

"When Rome will Fall
Then the World"
Mar 14 2005
parent Manfred Nowak <svv1999 hotmail.com> writes:
Lox <Lox_member pathlink.com> wrote:
[...]
 now the problem is that with DMD 0.114 it compiled and linked
 without problems
[...] Not confirmed. dmd 0.114 issues the same error message. I see the problem, but I do not understand it fully. In std.c.windows.windows `HANDLE' and thereby `HINSTANCE' are `typedef'-ed to `void*'. Because this type is not introduced into your module the needed object `WinMain' cannot be found, because the `WinMain' declared in your module has the wrong signature. But importing that type from std.c.windows.windows and aliasing HANDLE to it does not solve the problem: import std.c.windows.windows; alias std.c.windows.windows.HANDLE hdl; // ... alias hdl HANDLE; // ... And it can be confirmed, that `WinMain' exists at the end of the source by introducing a further `alias' declaration: alias WinMain xxx; which compiles flawlessly and can compile only if WinMain is declared at that point. -manfred
Mar 14 2005