www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Bad function type declarations in std.c.windows.windows

reply Stewart Gordon <smjg_1998 yahoo.com> writes:
On upgrading to DMD 0.86, I got this error:

dialog.d(118): function DialogBoxParamA (HANDLE 
hInstance,char*lpTemplateName,HANDLE hWndParent,int(Windows 
*lpDialogFunc)(),int dwInitParam) does not match argument types (HANDLE 
,char*,HANDLE ,int(Windows *)(HANDLE ,uint,uint,int),int)


The cause is right in windows.d:

----------
     alias int (*FARPROC)();
// ...
alias FARPROC DLGPROC;
alias FARPROC TIMERPROC;
alias FARPROC GRAYSTRINGPROC;
alias FARPROC WNDENUMPROC;
alias FARPROC HOOKPROC;
alias FARPROC SENDASYNCPROC;
// etc.
----------

None of these are functions that take no arguments and return an int. 
They are functions that take various argument lists and return various 
types.  All that's been done here is to take the non-strict path through 
the C headers, i.e. don't bother to list the arguments, back in the days 
when a () signature meant 'don't care'.  Of course, such 'don't care' 
declarations are useless for D.  It is therefore necessary to have 
specific function signatures.

Rather than leaving an exercise for the reader, here's the fix:

----------
alias BOOL function(HWND, UINT, WPARAM, LPARAM) DLGPROC;
alias VOID function(HWND, UINT, UINT, DWORD) TIMERPROC;
alias BOOL function(HDC, LPARAM, int) GRAYSTRINGPROC;
alias BOOL function(HWND, LPARAM) WNDENUMPROC;
alias LRESULT function(int code, WPARAM wParam, LPARAM lParam) HOOKPROC;
alias VOID function(HWND, UINT, DWORD, LRESULT) SENDASYNCPROC;

alias BOOL function(HWND, LPCSTR, HANDLE) PROPENUMPROCA;
alias BOOL function(HWND, LPCWSTR, HANDLE) PROPENUMPROCW;

alias BOOL function(HWND, LPSTR, HANDLE, DWORD) PROPENUMPROCEXA;
alias BOOL function(HWND, LPWSTR, HANDLE, DWORD) PROPENUMPROCEXW;

alias int function(LPSTR lpch, int ichCurrent, int cch, int code)
   EDITWORDBREAKPROCA;
alias int function(LPWSTR lpch, int ichCurrent, int cch, int code)
   EDITWORDBREAKPROCW;

alias BOOL function(HDC hdc, LPARAM lData, WPARAM wData, int cx, int cy)
   DRAWSTATEPROC;
----------

(NTS, it didn't take me long to grow into this style rather than the 
old-fashioned C notation!)

And here's the fix for asserterror.d:
http://www.digitalmars.com/drn-bin/wwwnews?D/27203

Stewart.

-- 
My e-mail is valid but not my primary mailbox, aside from its being the 
unfortunate victim of intensive mail-bombing at the moment.  Please keep 
replies on the 'group where everyone may benefit.
May 04 2004
parent "Walter" <newshound digitalmars.com> writes:
Thanks. This will go in the next update. -Walter
May 07 2004