1999-04-25 20:31:35 +02:00
|
|
|
/*
|
|
|
|
* Common Dialog Boxes interface (32 bit)
|
|
|
|
* Find/Replace
|
|
|
|
*
|
|
|
|
* Copyright 1999 Bertho A. Stultiens
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "commdlg.h"
|
|
|
|
#include "cderr.h"
|
1999-06-12 17:45:58 +02:00
|
|
|
#include "debugtools.h"
|
1999-04-25 20:31:35 +02:00
|
|
|
|
|
|
|
DEFAULT_DEBUG_CHANNEL(commdlg)
|
|
|
|
|
|
|
|
#include "cdlg.h"
|
|
|
|
|
|
|
|
|
|
|
|
HINSTANCE COMDLG32_hInstance = 0;
|
|
|
|
HINSTANCE16 COMDLG32_hInstance16 = 0;
|
|
|
|
|
|
|
|
static DWORD COMDLG32_TlsIndex;
|
|
|
|
static int COMDLG32_Attach = 0;
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* COMDLG32_DllEntryPoint (COMDLG32.entry)
|
|
|
|
*
|
|
|
|
* Initialization code for the COMDLG32 DLL
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* FALSE if sibling could not be loaded or instantiated twice, TRUE
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI COMDLG32_DllEntryPoint(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved)
|
|
|
|
{
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%08x, %08lx, %p)\n", hInstance, Reason, Reserved);
|
1999-04-25 20:31:35 +02:00
|
|
|
|
|
|
|
switch(Reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
COMDLG32_Attach++;
|
|
|
|
if(COMDLG32_hInstance)
|
|
|
|
{
|
1999-06-12 17:45:58 +02:00
|
|
|
ERR("comdlg32.dll instantiated twice in one address space!\n");
|
1999-04-25 20:31:35 +02:00
|
|
|
/*
|
|
|
|
* We should return FALSE here, but that will break
|
|
|
|
* most apps that use CreateProcess because we do
|
|
|
|
* not yet support seperate address spaces.
|
|
|
|
*/
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
COMDLG32_hInstance = hInstance;
|
|
|
|
DisableThreadLibraryCalls(hInstance);
|
|
|
|
|
|
|
|
if(!COMDLG32_hInstance16)
|
|
|
|
{
|
|
|
|
if(!(COMDLG32_hInstance16 = LoadLibrary16("commdlg.dll")))
|
|
|
|
{
|
1999-06-12 17:45:58 +02:00
|
|
|
ERR("Could not load sibling commdlg.dll\n");
|
1999-04-25 20:31:35 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if((COMDLG32_TlsIndex = TlsAlloc()) == 0xffffffff)
|
|
|
|
{
|
1999-06-12 17:45:58 +02:00
|
|
|
ERR("No space for COMDLG32 TLS\n");
|
1999-04-25 20:31:35 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
if(!--COMDLG32_Attach)
|
|
|
|
{
|
|
|
|
TlsFree(COMDLG32_TlsIndex);
|
|
|
|
COMDLG32_hInstance = 0;
|
|
|
|
if(COMDLG32_hInstance16)
|
|
|
|
FreeLibrary16(COMDLG32_hInstance16);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* COMDLG32_AllocMem (internal)
|
|
|
|
* Get memory for internal datastructure plus stringspace etc.
|
|
|
|
* RETURNS
|
|
|
|
* Pointer to a heap block: Succes
|
|
|
|
* NULL: Failure
|
|
|
|
*/
|
|
|
|
LPVOID COMDLG32_AllocMem(
|
|
|
|
int size /* [in] Block size to allocate */
|
|
|
|
) {
|
|
|
|
LPVOID ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
|
|
|
if(!ptr)
|
|
|
|
{
|
|
|
|
COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* COMDLG32_SetCommDlgExtendedError (internal)
|
|
|
|
*
|
|
|
|
* Used to set the thread's local error value if a comdlg32 function fails.
|
|
|
|
*/
|
|
|
|
void COMDLG32_SetCommDlgExtendedError(DWORD err)
|
|
|
|
{
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%08lx)\n", err);
|
1999-04-25 20:31:35 +02:00
|
|
|
TlsSetValue(COMDLG32_TlsIndex, (void *)err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CommDlgExtendedError (COMDLG32.5)
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
return (DWORD)TlsGetValue(COMDLG32_TlsIndex);
|
|
|
|
}
|