Commit 3c6253bb authored by Klaas van Gend's avatar Klaas van Gend Committed by Alexandre Julliard

- Reimplementation of the CommDlg ExtendedError mechanism using TLS.

- Some header inclusion cleanup.
parent b8742935
......@@ -3,7 +3,6 @@
*
* Copyright 1994 Martin Ayotte
* Copyright 1996 Albrecht Kleine
* Copyright 1999 Klaas van Gend
*/
#include <ctype.h>
......@@ -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;
}
}
......
......@@ -3,7 +3,6 @@
*
* Copyright 1994 Martin Ayotte
* Copyright 1996 Albrecht Kleine
* Copyright 1999 Klaas van Gend
*/
#include <ctype.h>
......@@ -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 {
......
......@@ -3,7 +3,6 @@
*
* Copyright 1994 Martin Ayotte
* Copyright 1996 Albrecht Kleine
* Copyright 1999 Klaas van Gend
*/
#include <ctype.h>
......@@ -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)
......
......@@ -3,7 +3,6 @@
*
* Copyright 1994 Martin Ayotte
* Copyright 1996 Albrecht Kleine
* Copyright 1999 Klaas van Gend
*/
#include <ctype.h>
......@@ -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;
}
}
......
/*
* 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 <stdlib.h>
#include <string.h>
#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);
}
......@@ -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);
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment