diff --git a/dlls/commdlg/colordlg.c b/dlls/commdlg/colordlg.c index 565e4e7621a..2e2d69ea182 100644 --- a/dlls/commdlg/colordlg.c +++ b/dlls/commdlg/colordlg.c @@ -3,7 +3,6 @@ * * Copyright 1994 Martin Ayotte * Copyright 1996 Albrecht Kleine - * Copyright 1999 Klaas van Gend */ #include @@ -14,20 +13,15 @@ #include "wine/winuser16.h" #include "win.h" #include "heap.h" -#include "message.h" #include "commdlg.h" #include "resource.h" #include "dialog.h" #include "dlgs.h" #include "module.h" -#include "drive.h" #include "debug.h" -#include "font.h" #include "winproc.h" #include "cderr.h" -extern DWORD CommDlgLastError; - /*********************************************************************** * ChooseColor (COMMDLG.5) */ @@ -46,7 +40,7 @@ BOOL16 WINAPI ChooseColor16(LPCHOOSECOLOR16 lpChCol) { if (!(template = LockResource16( lpChCol->hInstance ))) { - CommDlgLastError = CDERR_LOADRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } } @@ -57,13 +51,13 @@ BOOL16 WINAPI ChooseColor16(LPCHOOSECOLOR16 lpChCol) lpChCol->lpTemplateName, RT_DIALOG16))) { - CommDlgLastError = CDERR_FINDRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); return FALSE; } if (!(hDlgTmpl = LoadResource16( lpChCol->hInstance, hResInfo )) || !(template = LockResource16( hDlgTmpl ))) { - CommDlgLastError = CDERR_LOADRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } } diff --git a/dlls/commdlg/filedlg.c b/dlls/commdlg/filedlg.c index 55ac7feead8..0330bf93b9a 100644 --- a/dlls/commdlg/filedlg.c +++ b/dlls/commdlg/filedlg.c @@ -3,7 +3,6 @@ * * Copyright 1994 Martin Ayotte * Copyright 1996 Albrecht Kleine - * Copyright 1999 Klaas van Gend */ #include @@ -22,12 +21,9 @@ #include "module.h" #include "drive.h" #include "debug.h" -#include "font.h" #include "winproc.h" #include "cderr.h" -extern DWORD CommDlgLastError; - static HICON16 hFolder = 0; static HICON16 hFolder2 = 0; static HICON16 hFloppy = 0; @@ -106,7 +102,7 @@ BOOL16 WINAPI GetOpenFileName16( { if (!(template = LockResource( MapHModuleSL(lpofn->hInstance )))) { - CommDlgLastError = CDERR_LOADRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } } @@ -115,14 +111,14 @@ BOOL16 WINAPI GetOpenFileName16( if (!(hResInfo = FindResourceA(MapHModuleSL(lpofn->hInstance), PTR_SEG_TO_LIN(lpofn->lpTemplateName), RT_DIALOGA))) { - CommDlgLastError = CDERR_FINDRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); return FALSE; } if (!(hDlgTmpl = LoadResource( MapHModuleSL(lpofn->hInstance), hResInfo )) || !(template = LockResource( hDlgTmpl ))) { - CommDlgLastError = CDERR_LOADRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } } else { @@ -134,7 +130,7 @@ BOOL16 WINAPI GetOpenFileName16( { if (!(template = LockResource16( lpofn->hInstance ))) { - CommDlgLastError = CDERR_LOADRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } } @@ -144,13 +140,13 @@ BOOL16 WINAPI GetOpenFileName16( lpofn->lpTemplateName, RT_DIALOG16))) { - CommDlgLastError = CDERR_FINDRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); return FALSE; } if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) || !(template = LockResource16( hDlgTmpl ))) { - CommDlgLastError = CDERR_LOADRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } } else { @@ -243,7 +239,7 @@ BOOL16 WINAPI GetSaveFileName16( { if (!(template = LockResource( MapHModuleSL(lpofn->hInstance )))) { - CommDlgLastError = CDERR_LOADRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } } @@ -254,14 +250,14 @@ BOOL16 WINAPI GetSaveFileName16( PTR_SEG_TO_LIN(lpofn->lpTemplateName), RT_DIALOGA))) { - CommDlgLastError = CDERR_FINDRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); return FALSE; } if (!(hDlgTmpl = LoadResource(MapHModuleSL(lpofn->hInstance), hResInfo)) || !(template = LockResource(hDlgTmpl))) { - CommDlgLastError = CDERR_LOADRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } win32Format= TRUE; @@ -274,7 +270,7 @@ BOOL16 WINAPI GetSaveFileName16( { if (!(template = LockResource16( lpofn->hInstance ))) { - CommDlgLastError = CDERR_LOADRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } } @@ -285,13 +281,13 @@ BOOL16 WINAPI GetSaveFileName16( lpofn->lpTemplateName, RT_DIALOG16))) { - CommDlgLastError = CDERR_FINDRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); return FALSE; } if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) || !(template = LockResource16( hDlgTmpl ))) { - CommDlgLastError = CDERR_LOADRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } } else { diff --git a/dlls/commdlg/finddlg.c b/dlls/commdlg/finddlg.c index c111d55bea3..bf4cd03f8a1 100644 --- a/dlls/commdlg/finddlg.c +++ b/dlls/commdlg/finddlg.c @@ -3,7 +3,6 @@ * * Copyright 1994 Martin Ayotte * Copyright 1996 Albrecht Kleine - * Copyright 1999 Klaas van Gend */ #include @@ -13,28 +12,15 @@ #include "wine/winbase16.h" #include "wine/winuser16.h" #include "win.h" -#include "heap.h" #include "message.h" #include "commdlg.h" #include "resource.h" #include "dialog.h" #include "dlgs.h" #include "module.h" -#include "drive.h" #include "debug.h" -#include "font.h" #include "winproc.h" -extern DWORD CommDlgLastError; -/* -extern HBITMAP16 hFolder; -extern HBITMAP16 hFolder2; -extern HBITMAP16 hFloppy; -extern HBITMAP16 hHDisk; -extern HBITMAP16 hCDRom; -extern HBITMAP16 hBitmapTT; -extern const char defaultfilter[]; -*/ /*********************************************************************** * FindText16 (COMMDLG.11) diff --git a/dlls/commdlg/fontdlg.c b/dlls/commdlg/fontdlg.c index c4a56df9398..64f67366057 100644 --- a/dlls/commdlg/fontdlg.c +++ b/dlls/commdlg/fontdlg.c @@ -3,7 +3,6 @@ * * Copyright 1994 Martin Ayotte * Copyright 1996 Albrecht Kleine - * Copyright 1999 Klaas van Gend */ #include @@ -20,14 +19,11 @@ #include "dialog.h" #include "dlgs.h" #include "module.h" -#include "drive.h" #include "debug.h" #include "font.h" #include "winproc.h" #include "cderr.h" -extern DWORD CommDlgLastError; - static HBITMAP16 hBitmapTT = 0; @@ -77,7 +73,7 @@ BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont) { if (!(template = LockResource16( lpChFont->hInstance ))) { - CommDlgLastError = CDERR_LOADRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } } @@ -88,13 +84,13 @@ BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont) lpChFont->lpTemplateName, RT_DIALOG16))) { - CommDlgLastError = CDERR_FINDRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); return FALSE; } if (!(hDlgTmpl = LoadResource16( lpChFont->hInstance, hResInfo )) || !(template = LockResource16( hDlgTmpl ))) { - CommDlgLastError = CDERR_LOADRESFAILURE; + COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } } diff --git a/dlls/commdlg/generic.c b/dlls/commdlg/generic.c index 9ff26e2824b..688ca628e57 100644 --- a/dlls/commdlg/generic.c +++ b/dlls/commdlg/generic.c @@ -1,8 +1,9 @@ /* - * COMMDLG functions + * COMMDLG/COMDLG32 functions * * Copyright 1994 Martin Ayotte * Copyright 1996 Albrecht Kleine + * Copyright 1998 Bertho Stultiens * Copyright 1999 Klaas van Gend */ @@ -10,31 +11,88 @@ #include #include #include "winbase.h" -#include "wine/winbase16.h" -#include "wine/winuser16.h" #include "win.h" -#include "heap.h" -#include "message.h" #include "commdlg.h" -#include "resource.h" -#include "dialog.h" -#include "dlgs.h" #include "module.h" -#include "drive.h" #include "debug.h" -#include "font.h" #include "winproc.h" -static DWORD CommDlgLastError = 0; + +#define COMDLG32_LAST_ERROR_NOT_ALLOCATED 0xF684F684 +static DWORD COMDLG32_TlsIndex = COMDLG32_LAST_ERROR_NOT_ALLOCATED; + +/*********************************************************************** + * COMDLG32_DllEntryPoint [COMDLG32.entry] + * + * Initialisation code for the COMDLG32 DLL + * This call should implement the allocation of the TLS. + * + * RETURNS: + * + * BUGS: + * Remains unimplemented until Bertho finishes his ELF-DLL code + */ +BOOL WINAPI COMDLG32_DllEntryPoint(HINSTANCE hInstance, + DWORD Reason, + LPVOID Reserved + ); /*********************************************************************** - * CommDlgExtendedError (COMMDLG.26) + * COMDLG32_AllocTlsForCommDlgExtError [internal] + * + * Allocates Thread Local Storage for the ComDlg32 local + * last extended error + * + * RETURNS: + * nothing. + * + * BUGS: + * 1) FIXME: This function is only temporary, as this code *SHOULD* + * be executed in the DLL Entrypoint. For now, it is done + * this way. + * 2) This allocated memory is NEVER freed again! */ -DWORD WINAPI CommDlgExtendedError(void) +void COMDLG32_AllocTlsForCommDlgExtError() { - return CommDlgLastError; + FIXME(commdlg, "TLS for CommDlgExtendedError allocated on-the-fly\n"); + if (COMDLG32_TlsIndex == COMDLG32_LAST_ERROR_NOT_ALLOCATED) + COMDLG32_TlsIndex = TlsAlloc(); + if (COMDLG32_TlsIndex == 0xFFFFFFFF) + ERR(commdlg, "No space for COMDLG32 TLS\n"); +} + +/*********************************************************************** + * COMDLG32_SetCommDlgExtendedError [internal] + * + * Used to set the thread's local error value if a comdlg32 function fails. + */ +void COMDLG32_SetCommDlgExtendedError(DWORD err) +{ + /*FIXME: This check and the resulting alloc should be removed + * when the DLL Entry code is finished + */ + if (COMDLG32_TlsIndex==COMDLG32_LAST_ERROR_NOT_ALLOCATED) + COMDLG32_AllocTlsForCommDlgExtError(); + TlsSetValue(COMDLG32_TlsIndex, (void *)err); } +/*********************************************************************** + * CommDlgExtendedError [COMDLG32.5] + * [COMMDLG.26] + * Get the thread's local error value if a comdlg32 function fails. + * RETURNS + * Current error value which might not be valid + * if a previous call succeeded. + */ +DWORD WINAPI CommDlgExtendedError(void) +{ + /*FIXME: This check and the resulting alloc should be removed + * when the DLL Entry code is finished + */ + if (COMDLG32_TlsIndex==COMDLG32_LAST_ERROR_NOT_ALLOCATED) + COMDLG32_AllocTlsForCommDlgExtError(); + return (DWORD)TlsGetValue(COMDLG32_TlsIndex); +} diff --git a/dlls/commdlg/printdlg.c b/dlls/commdlg/printdlg.c index 3096009b227..57112d2e4cd 100644 --- a/dlls/commdlg/printdlg.c +++ b/dlls/commdlg/printdlg.c @@ -13,32 +13,16 @@ #include "wine/winbase16.h" #include "wine/winuser16.h" #include "win.h" -#include "heap.h" #include "message.h" #include "commdlg.h" #include "resource.h" #include "dialog.h" #include "dlgs.h" #include "module.h" -#include "drive.h" #include "debug.h" -#include "font.h" #include "winproc.h" #include "cderr.h" -DWORD CommDlgLastError = 0; - -extern HBITMAP16 hFolder; -extern HBITMAP16 hFolder2; -extern HBITMAP16 hFloppy; -extern HBITMAP16 hHDisk; -extern HBITMAP16 hCDRom; -extern HBITMAP16 hBitmapTT; -extern const char defaultfilter[]; - - - - /*********************************************************************** * PrintDlg16 (COMMDLG.20) */ @@ -136,14 +120,15 @@ BOOL WINAPI PrintDlgA( { WARN(commdlg, ": PrintDlg was requested to return printer info only." "\n The return value currently does NOT provide these.\n"); - CommDlgLastError=PDERR_NODEVICES; /* return TRUE, thus never checked! */ + COMDLG32_SetCommDlgExtendedError(PDERR_NODEVICES); + /* return TRUE, thus never checked! */ return(TRUE); } if (lppd->Flags & PD_PRINTSETUP) { FIXME(commdlg, ": PrintDlg was requested to display PrintSetup box.\n"); - CommDlgLastError=PDERR_INITFAILURE; + COMDLG32_SetCommDlgExtendedError(PDERR_INITFAILURE); return(FALSE); } diff --git a/include/commdlg.h b/include/commdlg.h index 4d1b162e3e5..eeac60613b3 100644 --- a/include/commdlg.h +++ b/include/commdlg.h @@ -645,6 +645,9 @@ LRESULT WINAPI FormatCharDlgProc16(HWND16,UINT16,WPARAM16,LPARAM); LRESULT WINAPI FormatCharDlgProcA(HWND,UINT,WPARAM,LPARAM); LRESULT WINAPI FormatCharDlgProcW(HWND,UINT,WPARAM,LPARAM); #define FormatCharDlgProc WINELIB_NAME_AW(FormatCharDlgProc) + +void COMDLG32_SetCommDlgExtendedError(DWORD err); + #ifdef __cplusplus } #endif