# win32.cpp File Reference

Implementation of MS Windows system calls. More...

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "debug.h"`
`#include "saveload/saveload.h"`
`#include "gfx_func.h"`
`#include "textbuf_gui.h"`
`#include "fileio_func.h"`
`#include "fios.h"`
`#include "rev.h"`
`#include <windows.h>`
`#include <winnt.h>`
`#include <wininet.h>`
`#include <fcntl.h>`
`#include <shlobj.h>`
`#include "variables.h"`
`#include "win32.h"`
`#include "core/alloc_func.hpp"`
`#include "functions.h"`
`#include "core/random_func.hpp"`
`#include "core/bitmath_func.hpp"`
`#include "string_func.h"`
`#include "gamelog.h"`
`#include <ctype.h>`
`#include <errno.h>`
`#include <sys/types.h>`
`#include <sys/stat.h>`

Go to the source code of this file.

## Defines
#define | W(x) x "A"
## Functions
bool | MyShowCursor (bool show)
bool | LoadLibraryList (Function proc[], const char *dll)
| Helper function needed by dynamically loading libraries XXX: Hurray for MS only having an ANSI GetProcAddress function on normal windows and no Wide version except for in Windows Mobile/CE.
void | ShowOSErrorBox (const char *buf, bool system)
static DIR * | dir_calloc ()
static void | dir_free (DIR *d)
DIR * | opendir (const TCHAR *path)
struct dirent * | readdir (DIR *d)
int | closedir (DIR *d)
bool | FiosIsRoot (const char *file)
void | FiosGetDrives ()
bool | FiosIsValidFile (const char *path, const struct dirent *ent, struct stat *sb)
bool | FiosIsHiddenFile (const struct dirent *ent)
bool | FiosGetDiskFreeSpace (const char *path, uint64 *tot)
static int | ParseCommandLine (char *line, char **argv, int max_argc)
void | CreateConsole ()
void | ShowInfo (const char *str)
int APIENTRY | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
char * | getcwd (char *buf, size_t size)
void | DetermineBasePaths (const char *exe)
bool | InsertTextBufferClipboard (Textbuf *tb)
| Insert a chunk of text from the clipboard onto the textbuffer.
void | CSleep (int milliseconds)
int64 | GetTS ()
| Utility function to get the current timestamp in milliseconds Useful for profiling.
const char * | FS2OTTD (const TCHAR *name)
| Convert to OpenTTD's encoding from that of the local environment.
const TCHAR * | OTTD2FS (const char *name)
| Convert from OpenTTD's encoding to that of the local environment.
char * | convert_from_fs (const wchar_t *name, char *utf8_buf, size_t buflen)
| Convert to OpenTTD's encoding from that of the environment in UNICODE.
wchar_t * | convert_to_fs (const char *name, wchar_t *utf16_buf, size_t buflen)
| Convert from OpenTTD's encoding to that of the environment in UNICODE.
HRESULT | OTTDSHGetFolderPath (HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath)
| Our very own SHGetFolderPath function for support of windows operating systems that don't have this function (eg Win9x, etc.
const char * | GetCurrentLocale (const char *)
| Determine the current user's locale.
## Variables
static bool | _has_console
static bool | cursor_visible = true
static DIR | _global_dir
static LONG | _global_dir_is_in_use = false

## Detailed Description

Implementation of MS Windows system calls.

Definition in file win32.cpp.

## Function Documentation

char* convert_from_fs | ( | const wchar_t * | name,
|  | char * | utf8_buf,
|  | size_t | buflen |
| ) |  |  |

Convert to OpenTTD's encoding from that of the environment in UNICODE.

OpenTTD encoding is UTF8, local is wide

Parameters:

  | name | pointer to a valid string that will be converted
  | utf8_buf | pointer to a valid buffer that will receive the converted string
  | buflen | length in characters of the receiving buffer

Returns:
  pointer to utf8_buf. If conversion fails the string is of zero-length

Definition at line 1269 of file win32.cpp.

Referenced by FS2OTTD(), and InsertTextBufferClipboard().

wchar_t* convert_to_fs | ( | const char * | name,
|  | wchar_t * | utf16_buf,
|  | size_t | buflen |
| ) |  |  |

Convert from OpenTTD's encoding to that of the environment in UNICODE.

OpenTTD encoding is UTF8, local is wide

Parameters:

  | name | pointer to a valid string that will be converted
  | utf16_buf | pointer to a valid wide-char buffer that will receive the converted string
  | buflen | length in wide characters of the receiving buffer

Returns:
  pointer to utf16_buf. If conversion fails the string is of zero-length

Definition at line 1288 of file win32.cpp.

Referenced by OTTD2FS().

const char* FS2OTTD | ( | const TCHAR * | name | ) |

Convert to OpenTTD's encoding from that of the local environment.

When the project is built in UNICODE, the system codepage is irrelevant and the input string is wide. In ANSI mode, the string is in the local codepage which we'll convert to wide-char, and then to UTF-8. OpenTTD internal encoding is UTF8. The returned value's contents can only be guaranteed until the next call to this function. So if the value is needed for anything else, use convert_from_fs

Parameters:

  | name | pointer to a valid string that will be converted (local, or wide)

Returns:
  pointer to the converted string; if failed string is of zero-length

See also:
  the current code-page comes from video\win32_v.cpp, event-notification WM_INPUTLANGCHANGE

Definition at line 1199 of file win32.cpp.

References convert_from_fs(), lastof, lengthof, and Utf8CharLen().

Referenced by FiosGetFileList(), GetLanguageList(), InsertTextBufferClipboard(), SquirrelStd::require(), and ScanPath().

const char* GetCurrentLocale | ( | const char * |  | ) |

Determine the current user's locale.

Definition at line 1349 of file win32.cpp.

References lengthof.

bool InsertTextBufferClipboard | ( | Textbuf * | tb | ) |

Insert a chunk of text from the clipboard onto the textbuffer.

Get TEXT clipboard and append this up to the maximum length (either absolute or screenlength). If maxlength is zero, we don't care about the screenlength but only about the physical length of the string

Parameters:

  | tb | Textbuf type to be changed

Returns:
  true on successful change of Textbuf, or false otherwise

Definition at line 1101 of file win32.cpp.

References convert_from_fs(), FS2OTTD(), GetCharacterWidth(), lastof, lengthof, strecpy(), and Utf8CharLen().

const TCHAR* OTTD2FS | ( | const char * | name | ) |

Convert from OpenTTD's encoding to that of the local environment.

When the project is built in UNICODE the system codepage is irrelevant and the converted string is wide. In ANSI mode, the UTF8 string is converted to multi-byte. OpenTTD internal encoding is UTF8. The returned value's contents can only be guaranteed until the next call to this function. So if the value is needed for anything else, use convert_from_fs

Parameters:

  | name | pointer to a valid string that will be converted (UTF8)

Returns:
  pointer to the converted string; if failed string is of zero-length

See also:
  the current code-page comes from video\win32_v.cpp, event-notification WM_INPUTLANGCHANGE

Definition at line 1236 of file win32.cpp.

References convert_to_fs(), lastof, and lengthof.

Referenced by FiosFileScanner::AddFile(), SQConvert::DefSQAdvancedNonStaticCallback(), SQConvert::DefSQNonStaticCallback(), FioCreateDirectory(), IniFile::SaveToDisk(), and ttd_opendir().

HRESULT OTTDSHGetFolderPath | ( | HWND | hwnd,
|  | int | csidl,
|  | HANDLE | hToken,
|  | DWORD | dwFlags,
|  | LPTSTR | pszPath |
| ) |  |  |

Our very own SHGetFolderPath function for support of windows operating systems that don't have this function (eg Win9x, etc.

). We try using the native function, and if that doesn't exist we will try a more crude approach of environment variables and hope for the best

Definition at line 1303 of file win32.cpp.

References LoadLibraryList().