Merge pull request #2128 from spnethw/handle-description-files-case-insensitive
[far2l.git] / WinPort / WinPort.h
blob344139865674d08c8d1939c0b5710f66b05c1a88
1 #pragma once
2 #ifndef FAR_PYTHON_GEN
3 //#ifdef _WIN32
4 #if 0
5 # include <Windows.h>
6 #else
7 # include "WinCompat.h"
8 # include <sys/stat.h>
9 # include <sys/time.h>
10 # include <time.h>
11 # include <stdarg.h>
12 #endif
14 #define WINPORT_DECL(NAME, RV, ARGS) SHAREDSYMBOL RV WINPORT_##NAME ARGS
15 #define WINPORT(NAME) WINPORT_##NAME
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 int WinPortMain(const char *full_exe_path, int argc, char **argv, int (*AppMain)(int argc, char **argv));
21 void WinPortHelp();
22 const wchar_t *WinPortBackend();
24 ///console API
25 WINPORT_DECL(ForkConsole,HANDLE,());
26 WINPORT_DECL(JoinConsole,VOID,(HANDLE hConsole));
28 WINPORT_DECL(GetLargestConsoleWindowSize,COORD,(HANDLE hConsoleOutput));
29 WINPORT_DECL(SetConsoleWindowInfo,BOOL,(HANDLE hConsoleOutput, BOOL bAbsolute, const SMALL_RECT *lpConsoleWindow));
30 WINPORT_DECL(SetConsoleTitle,BOOL,(HANDLE hConsoleOutput, const WCHAR *title));
31 WINPORT_DECL(GetConsoleTitle,DWORD,(HANDLE hConsoleOutput, WCHAR *title, DWORD max_size));
32 WINPORT_DECL(SetConsoleScreenBufferSize,BOOL,(HANDLE hConsoleOutput,COORD dwSize));
33 WINPORT_DECL(GetConsoleScreenBufferInfo,BOOL,(HANDLE hConsoleOutput,CONSOLE_SCREEN_BUFFER_INFO *lpConsoleScreenBufferInfo));
34 WINPORT_DECL(SetConsoleCursorPosition,BOOL,(HANDLE hConsoleOutput,COORD dwCursorPosition));
35 WINPORT_DECL(SetConsoleCursorInfo,BOOL,(HANDLE hConsoleOutput,const CONSOLE_CURSOR_INFO *lpConsoleCursorInfon));
36 WINPORT_DECL(GetConsoleCursorInfo,BOOL,(HANDLE hConsoleOutput,CONSOLE_CURSOR_INFO *lpConsoleCursorInfon));
37 WINPORT_DECL(GetConsoleMode,BOOL,(HANDLE hConsoleHandle,LPDWORD lpMode));
38 WINPORT_DECL(SetConsoleMode,BOOL,(HANDLE hConsoleHandle, DWORD dwMode));
39 WINPORT_DECL(ScrollConsoleScreenBuffer,BOOL,(HANDLE hConsoleOutput, const SMALL_RECT *lpScrollRectangle, const SMALL_RECT *lpClipRectangle, COORD dwDestinationOrigin, const CHAR_INFO *lpFill));
40 WINPORT_DECL(SetConsoleTextAttribute,BOOL,(HANDLE hConsoleOutput, DWORD64 qAttributes));
41 WINPORT_DECL(CompositeCharRegister,COMP_CHAR,(const WCHAR *lpSequence));
42 WINPORT_DECL(CompositeCharLookup,const WCHAR *,(COMP_CHAR CompositeChar));
43 WINPORT_DECL(WriteConsole,BOOL,(HANDLE hConsoleOutput, const WCHAR *lpBuffer, DWORD nNumberOfCharsToWrite, LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved));
44 WINPORT_DECL(WriteConsoleOutput,BOOL,(HANDLE hConsoleOutput,const CHAR_INFO *lpBuffer,COORD dwBufferSize,COORD dwBufferCoord,PSMALL_RECT lpScreenRegion));
45 WINPORT_DECL(WriteConsoleOutputCharacter,BOOL,(HANDLE hConsoleOutput, const WCHAR *lpCharacter, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfCharsWritten));
46 WINPORT_DECL(WaitConsoleInput, BOOL,(HANDLE hConsoleInput, DWORD dwTimeout));
47 WINPORT_DECL(ReadConsoleOutput, BOOL, (HANDLE hConsoleOutput, CHAR_INFO *lpBuffer, COORD dwBufferSize, COORD dwBufferCoord, PSMALL_RECT lpScreenRegion));
48 WINPORT_DECL(FillConsoleOutputAttribute, BOOL, (HANDLE hConsoleOutput, DWORD64 qAttributes, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfAttrsWritten));
49 WINPORT_DECL(FillConsoleOutputCharacter, BOOL, (HANDLE hConsoleOutput, WCHAR cCharacter, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfCharsWritten));
50 WINPORT_DECL(SetConsoleActiveScreenBuffer, BOOL,(HANDLE hConsoleOutput));
51 WINPORT_DECL(SetConsoleCursorBlinkTime,VOID,(HANDLE hConsoleOutput, DWORD dwMilliseconds ));
53 WINPORT_DECL(FlushConsoleInputBuffer,BOOL,(HANDLE hConsoleInput));
54 WINPORT_DECL(GetNumberOfConsoleInputEvents,BOOL,(HANDLE hConsoleInput, LPDWORD lpcNumberOfEvents));
55 WINPORT_DECL(PeekConsoleInput,BOOL,(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead));
56 WINPORT_DECL(ReadConsoleInput,BOOL,(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead));
57 WINPORT_DECL(WriteConsoleInput,BOOL,(HANDLE hConsoleInput, const INPUT_RECORD *lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsWritten));
59 // Checks if any of specified keys pressed
60 // Optionally preserves specified classes of input events
61 // return one plus array index of pressed key or zero if no one of specified keys is pressed
62 #define CFKP_KEEP_MATCHED_KEY_EVENTS 0x001
63 #define CFKP_KEEP_UNMATCHED_KEY_EVENTS 0x002
64 #define CFKP_KEEP_MOUSE_EVENTS 0x004
65 #define CFKP_KEEP_OTHER_EVENTS 0x100
66 WINPORT_DECL(CheckForKeyPress,DWORD,(HANDLE hConsoleInput, const WORD *KeyCodes, DWORD KeyCodesCount, DWORD Flags));
68 WINPORT_DECL(SetConsoleDisplayMode,BOOL,(DWORD ModeFlags));
69 WINPORT_DECL(GetConsoleDisplayMode,BOOL,(LPDWORD lpModeFlags));
70 WINPORT_DECL(SetConsoleWindowMaximized,VOID,(BOOL Maximized));
71 WINPORT_DECL(GetConsoleColorPalette,BYTE,(HANDLE hConsoleOutput)); // Returns current color resolution: 4, 8, 24
73 WINPORT_DECL(GenerateConsoleCtrlEvent, BOOL, (DWORD dwCtrlEvent, DWORD dwProcessGroupId ));
74 WINPORT_DECL(SetConsoleCtrlHandler, BOOL, (PHANDLER_ROUTINE HandlerRoutine, BOOL Add ));
76 WINPORT_DECL(SetConsoleScrollRegion, VOID, (HANDLE hConsoleOutput, SHORT top, SHORT bottom));
77 WINPORT_DECL(GetConsoleScrollRegion, VOID, (HANDLE hConsoleOutput, SHORT *top, SHORT *bottom));
79 WINPORT_DECL(SetConsoleScrollCallback, VOID, (HANDLE hConsoleOutput, PCONSOLE_SCROLL_CALLBACK pCallback, PVOID pContext));
80 WINPORT_DECL(BeginConsoleAdhocQuickEdit, BOOL, ());
81 WINPORT_DECL(SetConsoleTweaks, DWORD64, (DWORD64 tweaks));
82 #define EXCLUSIVE_CTRL_LEFT 0x00000001
83 #define EXCLUSIVE_CTRL_RIGHT 0x00000002
84 #define EXCLUSIVE_ALT_LEFT 0x00000004
85 #define EXCLUSIVE_ALT_RIGHT 0x00000008
86 #define EXCLUSIVE_WIN_LEFT 0x00000010
87 #define EXCLUSIVE_WIN_RIGHT 0x00000020
89 #define CONSOLE_PAINT_SHARP 0x00010000
90 #define CONSOLE_OSC52CLIP_SET 0x00020000
92 #define CONSOLE_TTY_PALETTE_OVERRIDE 0x00040000
94 #define TWEAK_STATUS_SUPPORT_EXCLUSIVE_KEYS 0x01
95 #define TWEAK_STATUS_SUPPORT_PAINT_SHARP 0x02
96 #define TWEAK_STATUS_SUPPORT_OSC52CLIP_SET 0x04
97 #define TWEAK_STATUS_SUPPORT_CHANGE_FONT 0x08
98 #define TWEAK_STATUS_SUPPORT_TTY_PALETTE 0x10
99 #define TWEAK_STATUS_SUPPORT_BLINK_RATE 0x20
101 WINPORT_DECL(SaveConsoleWindowState,VOID,());
102 WINPORT_DECL(ConsoleChangeFont, VOID, ());
103 WINPORT_DECL(IsConsoleActive, BOOL, ());
104 WINPORT_DECL(ConsoleDisplayNotification, VOID, (const WCHAR *title, const WCHAR *text));
105 WINPORT_DECL(ConsoleBackgroundMode, BOOL, (BOOL TryEnterBackgroundMode));
106 WINPORT_DECL(SetConsoleFKeyTitles, BOOL, (HANDLE hConsoleOutput, const CHAR **titles));
107 WINPORT_DECL(OverrideConsoleColor, VOID, (HANDLE hConsoleOutput, DWORD Index, DWORD *ColorFG, DWORD *ColorBK)); // 0xffffffff - to apply default color
108 WINPORT_DECL(SetConsoleRepaintsDefer, VOID, (HANDLE hConsoleOutput, BOOL Deferring));
110 #ifdef WINPORT_REGISTRY
111 ///registry API
112 WINPORT_DECL(RegOpenKeyEx, LONG, (HKEY hKey,LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult));
113 WINPORT_DECL(RegCreateKeyEx, LONG, (HKEY hKey, LPCWSTR lpSubKey, DWORD Reserved, LPWSTR lpClass, DWORD dwOptions,
114 REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition));
115 WINPORT_DECL(RegCloseKey, LONG, (HKEY hKey));
116 WINPORT_DECL(RegDeleteKey, LONG, (HKEY hKey, LPCWSTR lpSubKey));
117 WINPORT_DECL(RegDeleteValue, LONG, (HKEY hKey, LPCWSTR lpValueName));
118 WINPORT_DECL(RegSetValueEx, LONG, (HKEY hKey, LPCWSTR lpValueName, DWORD Reserved,
119 DWORD dwType, const BYTE *lpData, DWORD cbData));
120 WINPORT_DECL(RegEnumKeyEx, LONG, (HKEY hKey, DWORD dwIndex, LPWSTR lpName, LPDWORD lpcName,
121 LPDWORD lpReserved, LPWSTR lpClass,LPDWORD lpcClass, PFILETIME lpftLastWriteTime));
122 WINPORT_DECL(RegEnumKey, LONG, (HKEY hKey, DWORD dwIndex, LPWSTR lpName, DWORD cchName));
123 WINPORT_DECL(RegEnumValue, LONG, (HKEY hKey, DWORD dwIndex, LPWSTR lpValueName, LPDWORD lpcchValueName,
124 LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData));
125 WINPORT_DECL(RegQueryValueEx, LONG, (HKEY hKey, LPCWSTR lpValueName,
126 LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData));
127 WINPORT_DECL(RegSetValueEx, LONG, (HKEY hKey, LPCWSTR lpValueName,
128 DWORD lpReserved, DWORD lpType, CONST BYTE * lpData, DWORD cbData));
129 WINPORT_DECL(RegQueryInfoKey, LONG, (HKEY hKey, LPTSTR lpClass, LPDWORD lpcClass,
130 LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen,
131 LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen,
132 LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime));
134 WINPORT_DECL(RegWipeBegin, VOID, ());
135 WINPORT_DECL(RegWipeEnd, VOID, ());
136 #endif
138 //other
139 WINPORT_DECL(GetLastError, DWORD, ());
140 WINPORT_DECL(SetLastError, VOID, (DWORD code));
141 WINPORT_DECL(GetCurrentProcessId, DWORD, ());
142 WINPORT_DECL(GetDoubleClickTime, DWORD, ());
144 //files
145 WINPORT_DECL(CreateDirectory, BOOL, (LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes ));
146 WINPORT_DECL(RemoveDirectory, BOOL, ( LPCWSTR lpDirName));
147 WINPORT_DECL(DeleteFile, BOOL, ( LPCWSTR lpFileName));
148 WINPORT_DECL(CreateFile, HANDLE, ( LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
149 const DWORD *UnixMode, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile));
150 WINPORT_DECL(GetFileDescriptor, int, (HANDLE hFile));
151 WINPORT_DECL(CloseHandle, BOOL, (HANDLE hObject));
152 WINPORT_DECL(MoveFile, BOOL, (LPCWSTR ExistingFileName, LPCWSTR NewFileName ));
153 WINPORT_DECL(MoveFileEx, BOOL, (LPCWSTR ExistingFileName, LPCWSTR NewFileName,DWORD dwFlags));
154 WINPORT_DECL(GetCurrentDirectory, DWORD, (DWORD nBufferLength, LPWSTR lpBuffer));
155 WINPORT_DECL(SetCurrentDirectory, BOOL, (LPCWSTR lpPathName));
156 WINPORT_DECL(GetFileSizeEx, BOOL, ( HANDLE hFile, PLARGE_INTEGER lpFileSize));
157 WINPORT_DECL(GetFileSize, DWORD, ( HANDLE hFile, LPDWORD lpFileSizeHigh));
158 WINPORT_DECL(GetFileSize64, DWORD64, ( HANDLE hFile));
159 WINPORT_DECL(ReadFile, BOOL, ( HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
160 LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped));
161 WINPORT_DECL(WriteFile, BOOL, ( HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
162 LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped));
163 WINPORT_DECL(SetFilePointerEx, BOOL, ( HANDLE hFile, LARGE_INTEGER liDistanceToMove,
164 PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod));
166 // hints that file will soon grow up to specified size, doesnt change actual size of file
167 WINPORT_DECL(FileAllocationHint, VOID, (HANDLE hFile, DWORD64 HintFileSize));
168 // grows file to specified size if it was smaller, ensuring that disk space is actually allocated
169 WINPORT_DECL(FileAllocationRequire, BOOL, (HANDLE hFile, DWORD64 RequireFileSize));
171 WINPORT_DECL(SetFilePointer, DWORD, ( HANDLE hFile,
172 LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod));
173 WINPORT_DECL(GetFileTime, BOOL, ( HANDLE hFile, LPFILETIME lpCreationTime,
174 LPFILETIME lpLastAccessTime, LPFILETIME lpLastWriteTime));
175 WINPORT_DECL(SetFileTime, BOOL, ( HANDLE hFile, const FILETIME *lpCreationTime,
176 const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime));
177 WINPORT_DECL(SetEndOfFile, BOOL, ( HANDLE hFile));
178 WINPORT_DECL(FlushFileBuffers, BOOL, ( HANDLE hFile));
179 WINPORT_DECL(GetFileType, DWORD, ( HANDLE hFile));
181 WINPORT_DECL(GetFileAttributes, DWORD, (LPCWSTR lpFileName));
182 WINPORT_DECL(SetFileAttributes, DWORD, (LPCWSTR lpFileName, DWORD dwAttributes));
184 #define FIND_FILE_FLAG_NO_DIRS 0x01
185 #define FIND_FILE_FLAG_NO_FILES 0x02
186 #define FIND_FILE_FLAG_NO_LINKS 0x04
187 #define FIND_FILE_FLAG_NO_DEVICES 0x08
188 #define FIND_FILE_FLAG_NO_CUR_UP 0x10 //skip virtual . and ..
189 #define FIND_FILE_FLAG_CASE_INSENSITIVE 0x1000 //currently affects only english characters
190 #define FIND_FILE_FLAG_NOT_ANNOYING 0x2000 //avoid sudo prompt if can't query some not very important information without it
192 WINPORT_DECL(FindFirstFileWithFlags, HANDLE, (LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags));
193 WINPORT_DECL(FindFirstFile, HANDLE, (LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData));
194 WINPORT_DECL(FindNextFile, BOOL, (HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData));
195 WINPORT_DECL(FindClose, BOOL, (HANDLE hFindFile));
197 WINPORT_DECL(GetDriveType, UINT, (LPCWSTR lpRootPathName));
198 WINPORT_DECL(GetTempFileName, UINT,( LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR buffer ));
199 WINPORT_DECL(GetFullPathName, DWORD, (LPCTSTR lpFileName, DWORD nBufferLength, LPTSTR lpBuffer, LPTSTR *lpFilePart));
201 WINPORT_DECL(EvaluateAttributes, DWORD,( uint32_t unix_mode, const WCHAR *name ));
202 WINPORT_DECL(EvaluateAttributesA, DWORD,( uint32_t unix_mode, const char *name ));
204 //time/date
205 SHAREDSYMBOL clock_t GetProcessUptimeMSec();//use instead of Windows's clock()
206 WINPORT_DECL(Sleep, VOID, (DWORD dwMilliseconds));
207 WINPORT_DECL(GetTickCount, DWORD, ());
208 WINPORT_DECL(GetLocalTime, VOID, (LPSYSTEMTIME lpSystemTime));
209 WINPORT_DECL(GetSystemTime, VOID, (LPSYSTEMTIME lpSystemTime));
210 WINPORT_DECL(SystemTimeToFileTime, BOOL, (const SYSTEMTIME *lpSystemTime, LPFILETIME lpFileTime));
211 WINPORT_DECL(LocalFileTimeToFileTime, BOOL, (const FILETIME *lpLocalFileTime, LPFILETIME lpFileTime));
212 WINPORT_DECL(CompareFileTime, LONG, (const FILETIME *lpFileTime1, const FILETIME *lpFileTime2));
213 WINPORT_DECL(FileTimeToLocalFileTime, BOOL, (const FILETIME *lpFileTime, LPFILETIME lpLocalFileTime));
214 WINPORT_DECL(FileTimeToSystemTime, BOOL, (const FILETIME *lpFileTime, LPSYSTEMTIME lpSystemTime));
215 WINPORT_DECL(GetSystemTimeAsFileTime, VOID, (FILETIME *lpFileTime));
216 WINPORT_DECL(FileTimeToDosDateTime, BOOL, (const FILETIME *lpFileTime, LPWORD lpFatDate, LPWORD lpFatTime));
217 WINPORT_DECL(DosDateTimeToFileTime, BOOL, ( WORD fatdate, WORD fattime, LPFILETIME ft));
218 WINPORT_DECL(FileTime_UnixToWin32, VOID, (struct timespec ts, FILETIME *lpFileTime));
219 WINPORT_DECL(FileTime_Win32ToUnix, VOID, (const FILETIME *lpFileTime, struct timespec *ts));
221 //string
222 WINPORT_DECL(LCMapString, INT, (LCID lcid, DWORD flags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen));
223 WINPORT_DECL(CharUpperBuff, DWORD, (LPWSTR lpsz, DWORD cchLength));
224 WINPORT_DECL(CharLowerBuff, DWORD, (LPWSTR lpsz, DWORD cchLength));
225 WINPORT_DECL(IsCharLower, BOOL, (WCHAR ch));
226 WINPORT_DECL(IsCharUpper, BOOL, (WCHAR ch));
227 WINPORT_DECL(IsCharAlpha, BOOL, (WCHAR ch));
228 WINPORT_DECL(IsCharAlphaNumeric, BOOL, (WCHAR ch));
229 WINPORT_DECL(CompareString, int, ( LCID Locale, DWORD dwCmpFlags, LPCWSTR lpString1, int cchCount1, LPCWSTR lpString2, int cchCount2));
230 WINPORT_DECL(CompareStringA, int, ( LCID Locale, DWORD dwCmpFlags, LPCSTR lpString1, int cchCount1, LPCSTR lpString2, int cchCount2));
231 WINPORT_DECL(WideCharToMultiByte, int, ( UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr,
232 int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar));
233 WINPORT_DECL(MultiByteToWideChar, int, ( UINT CodePage, DWORD dwFlags,
234 LPCSTR lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar));
235 WINPORT_DECL(CharUpper, LPWSTR, (LPWSTR lpsz));
236 WINPORT_DECL(CharLower, LPWSTR, (LPWSTR lpsz));
237 WINPORT_DECL(GetOEMCP, UINT, ());
238 WINPORT_DECL(GetACP, UINT, ());
239 WINPORT_DECL(GetCPInfo, BOOL, (UINT CodePage, LPCPINFO lpCPInfo));
240 WINPORT_DECL(GetCPInfoEx, BOOL, (UINT codepage, DWORD dwFlags, LPCPINFOEX cpinfo));
241 WINPORT_DECL(EnumSystemCodePages, BOOL, (CODEPAGE_ENUMPROCW lpfnCodePageEnum, DWORD flags));
243 //clipboard
244 WINPORT_DECL(RegisterClipboardFormat, UINT, (LPCWSTR lpszFormat));
245 WINPORT_DECL(OpenClipboard, BOOL, (PVOID Reserved));
246 WINPORT_DECL(CloseClipboard, BOOL, ());
247 WINPORT_DECL(EmptyClipboard, BOOL, ());
248 WINPORT_DECL(IsClipboardFormatAvailable, BOOL, (UINT format));
250 // use Clipboard-Alloc/-Free/-Size to operate data pointers
251 WINPORT_DECL(GetClipboardData, PVOID, (UINT format));
252 WINPORT_DECL(SetClipboardData, PVOID, (UINT format, HANDLE mem));
254 // these are simplified analogs for Win32's Global* APIs, that dedicated to reference clipboard data
255 WINPORT_DECL(ClipboardAlloc, PVOID, (SIZE_T len)); // allocates zero-initialized memory
256 WINPORT_DECL(ClipboardSize, SIZE_T, (PVOID mem)); // return _exact_ allocation size
258 // note that like in win32, clipboard data is mostly owned by clipboard so ClipboardFree actually useful
259 // only in case of SetClipboardData's failure.
260 WINPORT_DECL(ClipboardFree, VOID, (PVOID mem));
262 //keyboard
263 WINPORT_DECL(GetKeyboardLayoutList, int, (int nBuff, HKL *lpList));
264 WINPORT_DECL(MapVirtualKey, UINT, (UINT uCode, UINT uMapType));
265 WINPORT_DECL(VkKeyScan, SHORT, (WCHAR ch));
266 WINPORT_DECL(ToUnicodeEx, int, (UINT wVirtKey, UINT wScanCode, CONST BYTE *lpKeyState,
267 LPWSTR pwszBuff, int cchBuff, UINT wFlags, HKL dwhkl));
269 //%s -> %ls, %ws -> %ls
270 SHAREDSYMBOL int vswprintf_ws2ls(wchar_t * ws, size_t len, const wchar_t * format, va_list arg );
271 SHAREDSYMBOL int swprintf_ws2ls (wchar_t* ws, size_t len, const wchar_t* format, ...);
273 SHAREDSYMBOL void SetPathTranslationPrefix(const wchar_t *prefix);
275 SHAREDSYMBOL const wchar_t *GetPathTranslationPrefix();
276 SHAREDSYMBOL const char *GetPathTranslationPrefixA();
277 #ifdef __cplusplus
280 #ifdef WINPORT_REGISTRY
281 struct RegWipeScope
283 inline RegWipeScope()
285 WINPORT(RegWipeBegin)();
287 inline ~RegWipeScope()
289 WINPORT(RegWipeEnd)();
292 #endif
294 #include <vector>
296 template <class CHAR_T, class LEN_T>
297 void *ClipboardAllocFromVector(const std::vector<CHAR_T> &src, LEN_T &len)
299 len = LEN_T(src.size() * sizeof(CHAR_T));
300 if (size_t(len) != (src.size() * sizeof(CHAR_T)))
301 return nullptr;
303 void *out = len ? WINPORT(ClipboardAlloc)(len) : nullptr;
304 if (out) {
305 memcpy(out, src.data(), len);
307 return out;
310 template <class CHAR_T>
311 void *ClipboardAllocFromVector(const std::vector<CHAR_T> &src)
313 size_t len;
314 return ClipboardAllocFromVector<CHAR_T, size_t>(src, len);
317 template <class CHAR_T>
318 void *ClipboardAllocFromZeroTerminatedString(const CHAR_T *src)
320 const size_t len = tzlen(src) + 1;
321 void *out = len ? WINPORT(ClipboardAlloc)(len * sizeof(CHAR_T)) : nullptr;
322 if (out) {
323 memcpy(out, src, len * sizeof(CHAR_T));
325 return out;
328 struct ConsoleRepaintsDeferScope
330 HANDLE _con_out;
332 ConsoleRepaintsDeferScope(HANDLE hConOut) : _con_out(hConOut)
334 WINPORT(SetConsoleRepaintsDefer)(_con_out, TRUE);
336 ~ConsoleRepaintsDeferScope()
338 WINPORT(SetConsoleRepaintsDefer)(_con_out, FALSE);
342 #endif
343 #endif /* FAR_PYTHON_GEN */