1
//============================================================
3
// winutil.c - Win32 OSD core utility functions
5
//============================================================
7
// Copyright Aaron Giles
8
// All rights reserved.
10
// Redistribution and use in source and binary forms, with or
11
// without modification, are permitted provided that the
12
// following conditions are met:
14
// * Redistributions of source code must retain the above
15
// copyright notice, this list of conditions and the
16
// following disclaimer.
17
// * Redistributions in binary form must reproduce the
18
// above copyright notice, this list of conditions and
19
// the following disclaimer in the documentation and/or
20
// other materials provided with the distribution.
21
// * Neither the name 'MAME' nor the names of its
22
// contributors may be used to endorse or promote
23
// products derived from this software without specific
24
// prior written permission.
26
// THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND
27
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
30
// EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
31
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32
// DAMAGE (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
35
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
38
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
//============================================================
42
// standard windows headers
43
#define WIN32_LEAN_AND_MEAN
50
//============================================================
51
// win_error_to_file_error
52
//============================================================
54
file_error win_error_to_file_error(DWORD error)
58
// convert a Windows error to a file_error
65
case ERROR_OUTOFMEMORY:
66
filerr = FILERR_OUT_OF_MEMORY;
69
case ERROR_FILE_NOT_FOUND:
70
case ERROR_PATH_NOT_FOUND:
71
filerr = FILERR_NOT_FOUND;
74
case ERROR_ACCESS_DENIED:
75
filerr = FILERR_ACCESS_DENIED;
78
case ERROR_SHARING_VIOLATION:
79
filerr = FILERR_ALREADY_OPEN;
83
filerr = FILERR_FAILURE;
91
//============================================================
92
// win_attributes_to_entry_type
93
//============================================================
95
osd_dir_entry_type win_attributes_to_entry_type(DWORD attributes)
97
if (attributes == 0xFFFFFFFF)
99
else if (attributes & FILE_ATTRIBUTE_DIRECTORY)
107
//============================================================
108
// win_is_gui_application
109
//============================================================
111
BOOL win_is_gui_application(void)
113
static BOOL is_gui_frontend;
114
static BOOL is_first_time = TRUE;
117
IMAGE_DOS_HEADER *dos_header;
118
IMAGE_NT_HEADERS *nt_headers;
119
IMAGE_OPTIONAL_HEADER *opt_header;
121
// is this the first time we've been ran?
124
is_first_time = FALSE;
126
// get the current module
127
module = GetModuleHandle(NULL);
130
image_ptr = (BYTE*) module;
132
// access the DOS header
133
dos_header = (IMAGE_DOS_HEADER *) image_ptr;
134
if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
137
// access the NT headers
138
nt_headers = (IMAGE_NT_HEADERS *) ((BYTE*)(dos_header) + (DWORD)(dos_header->e_lfanew));
139
if (nt_headers->Signature != IMAGE_NT_SIGNATURE)
142
// access the optional header
143
opt_header = &nt_headers->OptionalHeader;
144
switch (opt_header->Subsystem)
146
case IMAGE_SUBSYSTEM_WINDOWS_GUI:
147
is_gui_frontend = TRUE;
150
case IMAGE_SUBSYSTEM_WINDOWS_CUI:
151
is_gui_frontend = FALSE;
155
return is_gui_frontend;