2006-04-12 01:59:08 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : win_internal.h
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : shared (private) header for Windows-specific code.
|
|
|
|
*
|
|
|
|
* @author Jan.Wassenberg@stud.uni-karlsruhe.de
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2002-2005 Jan Wassenberg
|
|
|
|
*
|
|
|
|
* Redistribution and/or modification are also permitted under the
|
|
|
|
* terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation (version 2 or later, at your option).
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*/
|
2005-01-27 17:18:22 +01:00
|
|
|
|
2005-01-23 19:17:46 +01:00
|
|
|
#ifndef WIN_INTERNAL_H
|
|
|
|
#define WIN_INTERNAL_H
|
|
|
|
|
2005-08-09 18:23:19 +02:00
|
|
|
#if !OS_WIN
|
|
|
|
#error "win_internal.h: do not include if not compiling for Windows"
|
2004-03-03 00:56:51 +01:00
|
|
|
#endif
|
|
|
|
|
2006-06-22 20:26:08 +02:00
|
|
|
#include "lib/lib.h" // BIT
|
2005-01-23 19:17:46 +01:00
|
|
|
#include "lib/types.h" // intptr_t
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Win32 socket decls aren't portable (e.g. problems with socklen_t)
|
2005-03-18 23:09:44 +01:00
|
|
|
// => skip winsock.h; wposix wsock.h should be used instead
|
2004-03-03 00:56:51 +01:00
|
|
|
#define _WINSOCKAPI_
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#define VC_EXTRALEAN
|
|
|
|
|
|
|
|
|
|
|
|
// the public header, win.h, has defined _WINDOWS_ so that
|
|
|
|
// other code doesn't include <windows.h> when it shouldn't (e.g. zconf.h)
|
|
|
|
#undef _WINDOWS_
|
|
|
|
|
|
|
|
// set version; needed for EnumDisplayDevices
|
2005-02-02 04:26:38 +01:00
|
|
|
#define _WIN32_WINNT 0x0501
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
|
2004-05-06 19:14:30 +02:00
|
|
|
|
2005-03-18 23:09:44 +01:00
|
|
|
#define NOGDICAPMASKS // CC_*, LC_*, PC_*, CP_*, TC_*, RC_
|
2004-03-03 00:56:51 +01:00
|
|
|
//#define NOVIRTUALKEYCODES // VK_*
|
|
|
|
//#define NOWINMESSAGES // WM_*, EM_*, LB_*, CB_*
|
|
|
|
//#define NOWINSTYLES // WS_*, CS_*, ES_*, LBS_*, SBS_*, CBS_*
|
2005-03-18 23:09:44 +01:00
|
|
|
#define NOSYSMETRICS // SM_*
|
|
|
|
#define NOMENUS // MF_*
|
|
|
|
#define NOICONS // IDI_*
|
|
|
|
#define NOKEYSTATES // MK_*
|
2004-03-03 00:56:51 +01:00
|
|
|
//#define NOSYSCOMMANDS // SC_*
|
2005-03-18 23:09:44 +01:00
|
|
|
#define NORASTEROPS // Binary and Tertiary raster ops
|
2004-03-03 00:56:51 +01:00
|
|
|
//#define NOSHOWWINDOW // SW_*
|
2005-03-18 23:09:44 +01:00
|
|
|
#define OEMRESOURCE // OEM Resource values
|
|
|
|
#define NOATOM // Atom Manager routines
|
2004-03-03 00:56:51 +01:00
|
|
|
//#define NOCLIPBOARD // Clipboard routines
|
2005-03-18 23:09:44 +01:00
|
|
|
#define NOCOLOR // Screen colors
|
2004-06-13 18:06:23 +02:00
|
|
|
//#define NOCTLMGR // Control and Dialog routines
|
2005-03-18 23:09:44 +01:00
|
|
|
#define NODRAWTEXT // DrawText() and DT_*
|
2004-03-03 00:56:51 +01:00
|
|
|
//#define NOGDI // All GDI defines and routines
|
|
|
|
//#define NOKERNEL // All KERNEL defines and routines
|
|
|
|
//#define NOUSER // All USER defines and routines
|
2005-03-18 23:09:44 +01:00
|
|
|
#define NONLS // All NLS defines and routines
|
2004-03-03 00:56:51 +01:00
|
|
|
//#define NOMB // MB_* and MessageBox()
|
2005-03-18 23:09:44 +01:00
|
|
|
#define NOMEMMGR // GMEM_*, LMEM_*, GHND, LHND, associated routines
|
|
|
|
#define NOMETAFILE // typedef METAFILEPICT
|
|
|
|
#define NOMINMAX // Macros min(a,b) and max(a,b)
|
2004-03-03 00:56:51 +01:00
|
|
|
//#define NOMSG // typedef MSG and associated routines
|
2005-03-18 23:09:44 +01:00
|
|
|
#define NOOPENFILE // OpenFile(), OemToAnsi, AnsiToOem, and OF_*
|
|
|
|
#define NOSCROLL // SB_* and scrolling routines
|
|
|
|
#define NOSERVICE // All Service Controller routines, SERVICE_ equates, etc.
|
2004-03-03 00:56:51 +01:00
|
|
|
//#define NOSOUND // Sound driver routines
|
2005-03-18 23:09:44 +01:00
|
|
|
#define NOTEXTMETRIC // typedef TEXTMETRIC and associated routines
|
2004-03-03 00:56:51 +01:00
|
|
|
//#define NOWH // SetWindowsHook and WH_*
|
2005-03-18 23:09:44 +01:00
|
|
|
#define NOWINOFFSETS // GWL_*, GCL_*, associated routines
|
2004-03-03 00:56:51 +01:00
|
|
|
//#define NOCOMM // COMM driver routines
|
2005-03-18 23:09:44 +01:00
|
|
|
#define NOKANJI // Kanji support stuff.
|
|
|
|
#define NOHELP // Help engine interface.
|
|
|
|
#define NOPROFILER // Profiler interface.
|
|
|
|
#define NODEFERWINDOWPOS // DeferWindowPos routines
|
|
|
|
#define NOMCX // Modem Configuration Extensions
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
2004-05-18 02:38:39 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// fixes for VC6 platform SDK
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2004-03-03 00:56:51 +01:00
|
|
|
// VC6 windows.h doesn't define these
|
|
|
|
#ifndef DWORD_PTR
|
|
|
|
#define DWORD_PTR DWORD
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef INVALID_FILE_ATTRIBUTES
|
|
|
|
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PROCESSOR_ARCHITECTURE_AMD64
|
|
|
|
#define PROCESSOR_ARCHITECTURE_AMD64 9
|
|
|
|
#endif
|
|
|
|
|
2004-05-18 02:38:39 +02:00
|
|
|
#if WINVER < 0x500
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2004-05-18 02:38:39 +02:00
|
|
|
// can't test for macro definition -
|
|
|
|
// actual definitions in winnt.h are typedefs.
|
2004-05-29 14:04:42 +02:00
|
|
|
typedef unsigned __int64 DWORDLONG;
|
2004-05-18 02:38:39 +02:00
|
|
|
typedef DWORD ULONG_PTR;
|
|
|
|
|
|
|
|
typedef struct _MEMORYSTATUSEX
|
|
|
|
{
|
2005-03-18 23:09:44 +01:00
|
|
|
DWORD dwLength;
|
|
|
|
DWORD dwMemoryLoad;
|
|
|
|
DWORDLONG ullTotalPhys;
|
|
|
|
DWORDLONG ullAvailPhys;
|
|
|
|
DWORDLONG ullTotalPageFile;
|
|
|
|
DWORDLONG ullAvailPageFile;
|
|
|
|
DWORDLONG ullTotalVirtual;
|
|
|
|
DWORDLONG ullAvailVirtual;
|
|
|
|
DWORDLONG ullAvailExtendedVirtual;
|
|
|
|
} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
|
2004-05-18 02:38:39 +02:00
|
|
|
|
|
|
|
#endif // #if WINVER < 0x500
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2004-03-03 00:56:51 +01:00
|
|
|
// powrprof.h (not there at all in VC6, missing some parts in VC7)
|
2004-05-18 02:38:39 +02:00
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2005-03-18 23:09:44 +01:00
|
|
|
// MinGW headers are already correct; only change on VC
|
2005-08-09 18:23:19 +02:00
|
|
|
#if MSC_VERSION
|
2005-02-26 16:14:55 +01:00
|
|
|
|
2004-03-03 00:56:51 +01:00
|
|
|
#ifndef NTSTATUS
|
|
|
|
#define NTSTATUS long
|
|
|
|
#endif
|
|
|
|
#ifndef STATUS_SUCCESS
|
|
|
|
#define STATUS_SUCCESS 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if WINVER < 0x500
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
SystemPowerPolicyAc,
|
|
|
|
SystemPowerPolicyDc,
|
|
|
|
VerifySystemPolicyAc,
|
|
|
|
VerifySystemPolicyDc,
|
|
|
|
SystemPowerCapabilities,
|
|
|
|
SystemBatteryState,
|
|
|
|
SystemPowerStateHandler,
|
|
|
|
ProcessorStateHandler,
|
|
|
|
SystemPowerPolicyCurrent,
|
|
|
|
AdministratorPowerPolicy,
|
|
|
|
SystemReserveHiberFile,
|
|
|
|
ProcessorInformation,
|
|
|
|
SystemPowerInformation,
|
|
|
|
ProcessorStateHandler2,
|
|
|
|
LastWakeTime, // Compare with KeQueryInterruptTime()
|
|
|
|
LastSleepTime, // Compare with KeQueryInterruptTime()
|
|
|
|
SystemExecutionState,
|
|
|
|
SystemPowerStateNotifyHandler,
|
|
|
|
ProcessorPowerPolicyAc,
|
|
|
|
ProcessorPowerPolicyDc,
|
|
|
|
VerifyProcessorPowerPolicyAc,
|
|
|
|
VerifyProcessorPowerPolicyDc,
|
|
|
|
ProcessorPowerPolicyCurrent,
|
|
|
|
SystemPowerStateLogging,
|
|
|
|
SystemPowerLoggingEntry
|
|
|
|
} POWER_INFORMATION_LEVEL;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DWORD Granularity;
|
|
|
|
DWORD Capacity;
|
|
|
|
} BATTERY_REPORTING_SCALE, *PBATTERY_REPORTING_SCALE;
|
|
|
|
|
|
|
|
typedef enum _SYSTEM_POWER_STATE {
|
|
|
|
PowerSystemUnspecified = 0,
|
|
|
|
PowerSystemWorking = 1,
|
|
|
|
PowerSystemSleeping1 = 2,
|
|
|
|
PowerSystemSleeping2 = 3,
|
|
|
|
PowerSystemSleeping3 = 4,
|
|
|
|
PowerSystemHibernate = 5,
|
|
|
|
PowerSystemShutdown = 6,
|
|
|
|
PowerSystemMaximum = 7
|
|
|
|
} SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
// Misc supported system features
|
|
|
|
BOOLEAN PowerButtonPresent;
|
|
|
|
BOOLEAN SleepButtonPresent;
|
|
|
|
BOOLEAN LidPresent;
|
|
|
|
BOOLEAN SystemS1;
|
|
|
|
BOOLEAN SystemS2;
|
|
|
|
BOOLEAN SystemS3;
|
|
|
|
BOOLEAN SystemS4; // hibernate
|
|
|
|
BOOLEAN SystemS5; // off
|
|
|
|
BOOLEAN HiberFilePresent;
|
|
|
|
BOOLEAN FullWake;
|
|
|
|
BOOLEAN VideoDimPresent;
|
|
|
|
BOOLEAN ApmPresent;
|
|
|
|
BOOLEAN UpsPresent;
|
|
|
|
|
|
|
|
// Processors
|
|
|
|
BOOLEAN ThermalControl;
|
|
|
|
BOOLEAN ProcessorThrottle;
|
|
|
|
BYTE ProcessorMinThrottle;
|
|
|
|
BYTE ProcessorMaxThrottle;
|
|
|
|
BYTE spare2[4];
|
|
|
|
|
|
|
|
// Disk
|
|
|
|
BOOLEAN DiskSpinDown;
|
|
|
|
BYTE spare3[8];
|
|
|
|
|
|
|
|
// System Battery
|
|
|
|
BOOLEAN SystemBatteriesPresent;
|
|
|
|
BOOLEAN BatteriesAreShortTerm;
|
|
|
|
BATTERY_REPORTING_SCALE BatteryScale[3];
|
|
|
|
|
|
|
|
// Wake
|
|
|
|
SYSTEM_POWER_STATE AcOnLineWake;
|
|
|
|
SYSTEM_POWER_STATE SoftLidWake;
|
|
|
|
SYSTEM_POWER_STATE RtcWake;
|
|
|
|
SYSTEM_POWER_STATE MinDeviceWakeState; // note this may change on driver load
|
|
|
|
SYSTEM_POWER_STATE DefaultLowLatencyWake;
|
|
|
|
} SYSTEM_POWER_CAPABILITIES, *PSYSTEM_POWER_CAPABILITIES;
|
|
|
|
|
|
|
|
#endif // WINVER < 0x500
|
|
|
|
|
|
|
|
typedef struct _SYSTEM_POWER_INFORMATION
|
|
|
|
{
|
|
|
|
ULONG MaxIdlenessAllowed;
|
|
|
|
ULONG Idleness;
|
|
|
|
ULONG TimeRemaining;
|
|
|
|
UCHAR CoolingMode;
|
|
|
|
} SYSTEM_POWER_INFORMATION, *PSYSTEM_POWER_INFORMATION;
|
|
|
|
|
|
|
|
// SPI.CoolingMode
|
|
|
|
#define PO_TZ_INVALID_MODE 0 // The system does not support CPU throttling,
|
|
|
|
// or there is no thermal zone defined [..]
|
|
|
|
|
2005-08-09 18:23:19 +02:00
|
|
|
#endif // #if MSC_VERSION
|
2005-02-26 16:14:55 +01:00
|
|
|
|
|
|
|
// neither VC7.1 nor MinGW define this
|
|
|
|
typedef struct _PROCESSOR_POWER_INFORMATION
|
|
|
|
{
|
|
|
|
ULONG Number;
|
|
|
|
ULONG MaxMhz;
|
|
|
|
ULONG CurrentMhz;
|
|
|
|
ULONG MhzLimit;
|
|
|
|
ULONG MaxIdleState;
|
|
|
|
ULONG CurrentIdleState;
|
|
|
|
} PROCESSOR_POWER_INFORMATION, *PPROCESSOR_POWER_INFORMATION;
|
|
|
|
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2005-01-25 19:54:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2005-06-04 20:17:29 +02:00
|
|
|
// fixes for dbghelp.h 6.4
|
2005-01-25 19:54:48 +01:00
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// the macros defined "for those without specstrings.h" are incorrect -
|
|
|
|
// parameter definition is missing.
|
|
|
|
#ifndef __specstrings
|
|
|
|
# define __specstrings // prevent dbghelp from changing these
|
|
|
|
|
|
|
|
# define __in
|
|
|
|
# define __out
|
|
|
|
# define __inout
|
|
|
|
# define __in_opt
|
|
|
|
# define __out_opt
|
|
|
|
# define __inout_opt
|
|
|
|
# define __in_ecount(s)
|
|
|
|
# define __out_ecount(s)
|
|
|
|
# define __inout_ecount(s)
|
|
|
|
# define __in_bcount(s)
|
|
|
|
# define __out_bcount(s)
|
|
|
|
# define __inout_bcount(s)
|
|
|
|
# define __deref_opt_out
|
|
|
|
# define __deref_out
|
|
|
|
|
2005-07-02 23:42:55 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// (VC2005 defines __specstrings, but doesn't define (or use) __out_xcount,
|
|
|
|
// so this is not inside the above #ifndef section)
|
|
|
|
//
|
2005-01-25 19:54:48 +01:00
|
|
|
// missing from dbghelp's list
|
2005-03-18 23:09:44 +01:00
|
|
|
# define __out_xcount(s)
|
|
|
|
|
2005-01-25 19:54:48 +01:00
|
|
|
|
2005-06-04 20:17:29 +02:00
|
|
|
//
|
2005-01-25 19:54:48 +01:00
|
|
|
// not defined by dbghelp; these values are taken from DIA cvconst.h
|
2005-06-04 20:17:29 +02:00
|
|
|
//
|
|
|
|
|
2005-01-25 19:54:48 +01:00
|
|
|
enum BasicType
|
|
|
|
{
|
|
|
|
btNoType = 0,
|
|
|
|
btVoid = 1,
|
|
|
|
btChar = 2,
|
|
|
|
btWChar = 3,
|
|
|
|
btInt = 6,
|
|
|
|
btUInt = 7,
|
|
|
|
btFloat = 8,
|
|
|
|
btBCD = 9,
|
|
|
|
btBool = 10,
|
|
|
|
btLong = 13,
|
|
|
|
btULong = 14,
|
|
|
|
btCurrency = 25,
|
|
|
|
btDate = 26,
|
|
|
|
btVariant = 27,
|
|
|
|
btComplex = 28,
|
|
|
|
btBit = 29,
|
|
|
|
btBSTR = 30,
|
|
|
|
btHresult = 31
|
|
|
|
};
|
|
|
|
|
2005-06-04 20:17:29 +02:00
|
|
|
enum DataKind
|
|
|
|
{
|
|
|
|
DataIsUnknown,
|
|
|
|
DataIsLocal,
|
|
|
|
DataIsStaticLocal,
|
|
|
|
DataIsParam,
|
|
|
|
DataIsObjectPtr,
|
|
|
|
DataIsFileStatic,
|
|
|
|
DataIsGlobal,
|
|
|
|
DataIsMember,
|
|
|
|
DataIsStaticMember,
|
|
|
|
DataIsConstant
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-05-18 02:38:39 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
|
2004-06-11 19:55:24 +02:00
|
|
|
#ifndef _CRTIMP
|
2005-01-27 17:18:22 +01:00
|
|
|
# ifdef _DLL
|
|
|
|
# define _CRTIMP __declspec(dllimport)
|
|
|
|
# else
|
|
|
|
# define _CRTIMP
|
|
|
|
# endif
|
|
|
|
#endif
|
2004-06-11 19:55:24 +02:00
|
|
|
|
2004-03-03 00:56:51 +01:00
|
|
|
extern "C" {
|
2005-01-30 17:13:15 +01:00
|
|
|
extern _CRTIMP intptr_t _get_osfhandle(int);
|
|
|
|
extern _CRTIMP int _open_osfhandle(intptr_t, int);
|
|
|
|
extern _CRTIMP int _open(const char* fn, int mode, ...);
|
2005-06-22 05:23:22 +02:00
|
|
|
extern _CRTIMP int _read (int fd, void* buf, size_t nbytes);
|
|
|
|
extern _CRTIMP int _write(int fd, void* buf, size_t nbytes);
|
2005-01-30 17:13:15 +01:00
|
|
|
extern _CRTIMP int _close(int);
|
|
|
|
|
|
|
|
extern _CRTIMP char* _getcwd(char*, size_t);
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
#ifndef NO_WINSOCK
|
|
|
|
extern __declspec(dllimport) int __stdcall WSAStartup(unsigned short, void*);
|
2005-01-23 19:17:46 +01:00
|
|
|
extern __declspec(dllimport) int __stdcall WSACleanup(void);
|
2004-03-03 00:56:51 +01:00
|
|
|
extern __declspec(dllimport) int __stdcall WSAAsyncSelect(int s, HANDLE hWnd, unsigned int wMsg, long lEvent);
|
2005-01-23 19:17:46 +01:00
|
|
|
extern __declspec(dllimport) int __stdcall WSAGetLastError(void);
|
2004-03-03 00:56:51 +01:00
|
|
|
#endif // #ifndef NO_WINSOCK
|
|
|
|
|
2005-06-26 19:12:48 +02:00
|
|
|
#ifdef USE_WINMAIN
|
|
|
|
extern int WinMainCRTStartup(void);
|
|
|
|
#else
|
2005-06-21 18:31:55 +02:00
|
|
|
extern int mainCRTStartup(void);
|
2005-06-26 19:12:48 +02:00
|
|
|
#endif
|
2004-03-03 00:56:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define FD_READ BIT(0)
|
|
|
|
#define FD_WRITE BIT(1)
|
|
|
|
#define FD_ACCEPT BIT(3)
|
|
|
|
#define FD_CONNECT BIT(4)
|
|
|
|
#define FD_CLOSE BIT(5)
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// locking
|
|
|
|
//
|
|
|
|
|
|
|
|
// critical sections used by win-specific code
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ONCE_CS,
|
2005-05-11 06:35:21 +02:00
|
|
|
WTIME_CS,
|
2004-03-03 00:56:51 +01:00
|
|
|
WAIO_CS,
|
2004-05-27 19:30:06 +02:00
|
|
|
WIN_CS,
|
2005-05-11 06:35:21 +02:00
|
|
|
WDBG_CS,
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
NUM_CS
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extern void win_lock(uint idx);
|
|
|
|
extern void win_unlock(uint idx);
|
|
|
|
|
2005-06-21 18:31:55 +02:00
|
|
|
// used in a desperate attempt to avoid deadlock in wdbg_exception_handler.
|
|
|
|
extern int win_is_locked(uint idx);
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2005-01-30 18:40:24 +01:00
|
|
|
|
|
|
|
extern void* win_alloc(size_t size);
|
|
|
|
extern void win_free(void* p);
|
|
|
|
|
|
|
|
|
2004-03-03 00:56:51 +01:00
|
|
|
// thread safe, useable in constructors
|
|
|
|
#define WIN_ONCE(code) \
|
|
|
|
{ \
|
|
|
|
win_lock(ONCE_CS); \
|
|
|
|
static bool ONCE_init_; /* avoid name conflict */ \
|
|
|
|
if(!ONCE_init_) \
|
|
|
|
{ \
|
|
|
|
ONCE_init_ = true; \
|
|
|
|
code; \
|
|
|
|
} \
|
|
|
|
win_unlock(ONCE_CS); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-02 04:46:50 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
// init and shutdown mechanism: register a function to be called at
|
|
|
|
// pre-main init or shutdown.
|
2005-01-27 17:18:22 +01:00
|
|
|
//
|
2004-09-02 04:46:50 +02:00
|
|
|
// the "segment name" determines when and in what order the functions are
|
2005-01-27 17:18:22 +01:00
|
|
|
// called: "LIB$W{type}{group}", where {type} is C for pre-libc init,
|
|
|
|
// I for pre-main init, or T for terminators (last of the atexit handlers).
|
2004-09-02 04:46:50 +02:00
|
|
|
// {group} is [B, Y]; groups are called in alphabetical order, but
|
|
|
|
// call order within the group itself is unspecified.
|
|
|
|
//
|
|
|
|
// define the segment via #pragma data_seg(name), register any functions
|
|
|
|
// to be called via WIN_REGISTER_FUNC, and then restore the previous segment
|
|
|
|
// with #pragma data_seg() .
|
|
|
|
|
2005-12-11 23:23:55 +01:00
|
|
|
#define WIN_REGISTER_FUNC(func) static LibError func(void); static LibError (*p##func)(void) = func
|
2004-05-27 19:30:06 +02:00
|
|
|
|
2005-06-23 01:38:04 +02:00
|
|
|
#define WIN_CALLBACK_PRE_LIBC(group) ".LIB$WC" #group
|
|
|
|
#define WIN_CALLBACK_PRE_MAIN(group) ".LIB$WI" #group
|
2005-06-21 18:31:55 +02:00
|
|
|
#define WIN_CALLBACK_POST_ATEXIT(group) ".LIB$WT" #group
|
2004-05-27 19:30:06 +02:00
|
|
|
|
2004-09-02 04:46:50 +02:00
|
|
|
|
|
|
|
|
2004-07-12 16:25:39 +02:00
|
|
|
#define WIN_SAVE_LAST_ERROR DWORD last_err__ = GetLastError();
|
|
|
|
#define WIN_RESTORE_LAST_ERROR STMT(if(last_err__ != 0 && GetLastError() == 0) SetLastError(last_err__););
|
|
|
|
|
|
|
|
|
2005-12-11 23:23:55 +01:00
|
|
|
// return the LibError equivalent of GetLastError(), or ERR_FAIL if
|
|
|
|
// there's no equal.
|
|
|
|
// you should SetLastError(0) before calling whatever will set ret
|
|
|
|
// to make sure we do not return any stale errors.
|
2006-04-03 03:00:45 +02:00
|
|
|
extern LibError LibError_from_win32(DWORD ret, bool warn_if_failed = true);
|
2005-12-11 23:23:55 +01:00
|
|
|
|
|
|
|
|
2004-11-19 23:41:37 +01:00
|
|
|
extern char win_sys_dir[MAX_PATH+1];
|
2004-11-22 08:40:32 +01:00
|
|
|
extern char win_exe_dir[MAX_PATH+1];
|
2004-11-19 23:41:37 +01:00
|
|
|
|
|
|
|
|
2005-06-21 18:31:55 +02:00
|
|
|
// this isn't nice (ideally we would avoid coupling win.cpp and wdbg.cpp), but
|
|
|
|
// necessary; see rationale at function definition.
|
|
|
|
extern LONG WINAPI wdbg_exception_filter(EXCEPTION_POINTERS* ep);
|
|
|
|
|
2004-05-06 19:14:30 +02:00
|
|
|
#endif // #ifndef WIN_INTERNAL_H
|