summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/uwp/uwpcompat.cpp
blob: e550a42086af008fac59e4c28740ddded0fa7125 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// license:BSD-3-Clause
// copyright-holders:Brad Hughes, Miodrag Milanovic
//============================================================
//
//  uwpcompat.h - Universal Windows Platform compat forced includes
//
//============================================================

#include "uwpcompat.h"

#include <errno.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef interface

#include "emu.h"

extern "C" {

	BOOL WINAPI GetVersionEx(
		_Inout_ LPOSVERSIONINFO lpVersionInfo
	)
	{
		lpVersionInfo->dwMajorVersion = 10;
		return TRUE;
	}

	HANDLE
	WINAPI
	CreateFileW(
		_In_ LPCWSTR lpFileName,
		_In_ DWORD dwDesiredAccess,
		_In_ DWORD dwShareMode,
		_In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
		_In_ DWORD dwCreationDisposition,
		_In_ DWORD dwFlagsAndAttributes,
		_In_opt_ HANDLE hTemplateFile
		)
	{
		// TODO: Handle other arguments that go into last param (pCreateExParams)
		return CreateFile2((wchar_t*)lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
	}

	HANDLE
	WINAPI
	CreateFileA(
		_In_ LPCSTR lpFileName,
		_In_ DWORD dwDesiredAccess,
		_In_ DWORD dwShareMode,
		_In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
		_In_ DWORD dwCreationDisposition,
		_In_ DWORD dwFlagsAndAttributes,
		_In_opt_ HANDLE hTemplateFile
		)
	{
		wchar_t filepath[MAX_PATH + 1];
		if (MultiByteToWideChar(CP_ACP, 0, lpFileName, strlen(lpFileName), filepath, MAX_PATH))
			return CreateFileW(filepath, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);

		SetLastError(E_FAIL);
		return INVALID_HANDLE_VALUE;
	}

	DWORD WINAPI GetTickCount(void)
	{
		return osd_ticks();
	}

	HMODULE WINAPI LoadLibraryExA(
		_In_ LPCSTR lpLibFileName,
		_Reserved_ HANDLE hFile,
		_In_ DWORD dwFlags
		)
	{
		wchar_t libfile_wide[MAX_PATH + 1];
		if (MultiByteToWideChar(CP_ACP, 0, lpLibFileName, strlen(lpLibFileName), libfile_wide, MAX_PATH))
			return LoadPackagedLibrary(libfile_wide, 0);

		return nullptr;
	}

	HMODULE WINAPI LoadLibraryExW(
		_In_ LPCWSTR lpLibFileName,
		_Reserved_ HANDLE hFile,
		_In_ DWORD dwFlags
		)
	{
		return LoadPackagedLibrary(lpLibFileName, 0);
	}

	DWORD WINAPI GetFileSize(
		_In_ HANDLE hFile,
		_Out_opt_ LPDWORD lpFileSizeHigh
	)
	{
		FILE_STANDARD_INFO file_info;
		GetFileInformationByHandleEx(hFile, FileStandardInfo, &file_info, sizeof(file_info));
		if(lpFileSizeHigh!=nullptr)
		{
			*lpFileSizeHigh = file_info.EndOfFile.HighPart;
		}
		return file_info.EndOfFile.LowPart;
	}
}