www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - difficulties getting SetTimer () to work

reply llee <llee_member pathlink.com> writes:
There has to be a simple explanation for this. I've tried to compile the
following code several times, but the compiler doesn't recognize the SetTimer
identifier. Each time I've tried the following compiler settings:

 dmd timer.d gdi32.lib user32.lib winsamp.def

The msdn site says that SetTimer is defined under user32.lib. the error that I get in return is as follows:
 timer.d(46): undefined identifier SetTimer
 timer.d(46): function expected before (), not SetTimer of type int

Listed here is the source code: _______________________________________________________________________________ // application demonstrates the timer event function. // note: windows data types are case sensitive // note: compile by typing; // 'dmd timer.d gdi32.lib user32.lib winsamp.def' import std.c.windows.windows; import std.c.stdio; extern (C) void _minit(); extern (C) void gc_init(); extern (C) void gc_term(); extern (C) void _moduleCtor(); extern (C) void _moduleUnitTests(); extern (Windows) int WindowProc (HWND hWnd, uint msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_PAINT: { HDC dc; // handle to the device context RECT r; PAINTSTRUCT ps; // specifies region to be redrawn dc = BeginPaint (hWnd, &ps); GetClientRect (hWnd, &r); EndPaint (hWnd, &ps); break; } case WM_DESTROY: { PostQuitMessage (0); break; } case WM_CREATE: { int timer_status = 1; // 1 - continue, -1 - stop int timer_duration = 10; // duration in milliseconds SetTimer (hWnd, timer_status, timer_duration, null); } case WM_TIMER: // now called every 10 milliseconds { } default: { break; } } return DefWindowProcA (hWnd, msg, wParam, lParam); } int WindowInitialization () { // declarations: MSG msg; HWND hWnd; WNDCLASS wc; HINSTANCE hInst; // definitions: hInst = GetModuleHandleA (null); wc.lpszClassName = "DWndClass"; wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = &WindowProc; wc.hInstance = hInst; wc.hIcon = LoadIconA (cast (HINSTANCE) null, IDI_APPLICATION); wc.hCursor = LoadCursorA (cast (HINSTANCE) null, IDC_CROSS); wc.hbrBackground = cast (HBRUSH) (COLOR_WINDOW + 1); wc.lpszMenuName = null; wc.cbClsExtra = 0; wc.cbWndExtra = 0; // operations: RegisterClassA (&wc); hWnd = CreateWindowA ( "DWndClass" , "just a window" , WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE , CW_USEDEFAULT , CW_USEDEFAULT , 400 , 300 , HWND_DESKTOP , cast (HMENU) null , hInst , null ); assert (hWnd); while (GetMessageA (&msg, cast (HWND) null, 0, 0)) { TranslateMessage (&msg); DispatchMessageA (&msg); } return 1; } extern (Windows) int WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { int result; gc_init (); // initialize garbage collector _minit (); // initialize module constructor try { _moduleCtor (); // call module consructor _moduleUnitTests(); // run unit tests (optional) result = WindowInitialization (); } catch (Object o) // catch any uncaught exceptions { MessageBoxA ( null , cast (char*) o.toString , "Error" , MB_OK | MB_ICONEXCLAMATION ); result = 0; // failed } gc_term (); // terminate garbage collection return result; } any help would be appreciated. _______________________________________________________________________________
Jul 11 2006
parent Don Clugston <dac nospam.com.au> writes:
llee wrote:
 There has to be a simple explanation for this. I've tried to compile the
 following code several times, but the compiler doesn't recognize the SetTimer
 identifier. Each time I've tried the following compiler settings:
 
 dmd timer.d gdi32.lib user32.lib winsamp.def

The msdn site says that SetTimer is defined under user32.lib. the error that I get in return is as follows:
 timer.d(46): undefined identifier SetTimer
 timer.d(46): function expected before (), not SetTimer of type int


The windows headers supplied with DMD are horribly incomplete. More complete ones are available in the win32 section of the bindings project at www.dsource.org.
Jul 11 2006