foobar2000 SDK  2015-01-14
Functions
win32_misc.cpp File Reference

Go to the source code of this file.

Functions

static bool FetchWineInfoAppend (pfc::string_base &out)
 
void GetOSVersionString (pfc::string_base &out)
 
void GetOSVersionStringAppend (pfc::string_base &out)
 
bool IsMenuNonEmpty (HMENU menu)
 
unsigned QueryScreenDPI ()
 
SIZE QueryScreenDPIEx ()
 
static bool running_under_wine (void)
 
bool SetClipboardDataBlock (UINT p_format, const void *p_block, t_size p_block_size)
 
void SetDefaultMenuItem (HMENU p_menu, unsigned p_id)
 
void WIN32_OP_D_FAIL (const wchar_t *_Message, const wchar_t *_File, unsigned _Line)
 
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL ()
 
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL_CRITICAL (const char *what)
 

Function Documentation

static bool FetchWineInfoAppend ( pfc::string_base out)
static

Definition at line 90 of file win32_misc.cpp.

90  {
91  typedef const char *(__cdecl *t_wine_get_build_id)(void);
92  typedef void (__cdecl *t_wine_get_host_version)( const char **sysname, const char **release );
93  const HMODULE ntdll = GetModuleHandle(_T("ntdll.dll"));
94  if (ntdll == NULL) return false;
95  t_wine_get_build_id wine_get_build_id;
96  t_wine_get_host_version wine_get_host_version;
97  wine_get_build_id = (t_wine_get_build_id)GetProcAddress(ntdll, "wine_get_build_id");
98  wine_get_host_version = (t_wine_get_host_version)GetProcAddress(ntdll, "wine_get_host_version");
99  if (wine_get_build_id == NULL || wine_get_host_version == NULL) {
100  if (GetProcAddress(ntdll, "wine_server_call") != NULL) {
101  out << "wine (unknown version)";
102  return true;
103  }
104  return false;
105  }
106  const char * sysname = NULL; const char * release = NULL;
107  wine_get_host_version(&sysname, &release);
108  out << wine_get_build_id() << ", on: " << sysname << " / " << release;
109  return true;
110 }
void GetOSVersionString ( pfc::string_base out)

Definition at line 81 of file win32_misc.cpp.

81  {
82  out.reset(); GetOSVersionStringAppend(out);
83 }
void GetOSVersionStringAppend(pfc::string_base &out)
Definition: win32_misc.cpp:111
void GetOSVersionStringAppend ( pfc::string_base out)

Definition at line 111 of file win32_misc.cpp.

111  {
112 
113  if (FetchWineInfoAppend(out)) return;
114 
115  OSVERSIONINFO ver = {}; ver.dwOSVersionInfoSize = sizeof(ver);
116  WIN32_OP( GetVersionEx(&ver) );
117  SYSTEM_INFO info = {};
118  GetNativeSystemInfo(&info);
119 
120  out << "Windows " << (int)ver.dwMajorVersion << "." << (int)ver.dwMinorVersion << "." << (int)ver.dwBuildNumber;
121  if (ver.szCSDVersion[0] != 0) out << " " << pfc::stringcvt::string_utf8_from_os(ver.szCSDVersion, PFC_TABSIZE(ver.szCSDVersion));
122 
123  switch(info.wProcessorArchitecture) {
124  case PROCESSOR_ARCHITECTURE_AMD64:
125  out << " x64"; break;
126  case PROCESSOR_ARCHITECTURE_IA64:
127  out << " IA64"; break;
128  case PROCESSOR_ARCHITECTURE_INTEL:
129  out << " x86"; break;
130  }
131 }
void info(const char *p_message)
Definition: console.cpp:4
string_utf8_from_wide string_utf8_from_os
Definition: string_conv.h:517
static bool FetchWineInfoAppend(pfc::string_base &out)
Definition: win32_misc.cpp:90
bool IsMenuNonEmpty ( HMENU  menu)

Definition at line 43 of file win32_misc.cpp.

43  {
44  unsigned n,m=GetMenuItemCount(menu);
45  for(n=0;n<m;n++) {
46  if (GetSubMenu(menu,n)) return true;
47  if (!(GetMenuState(menu,n,MF_BYPOSITION)&MF_SEPARATOR)) return true;
48  }
49  return false;
50 }
unsigned QueryScreenDPI ( )

Definition at line 27 of file win32_misc.cpp.

27  {
28  HDC dc = GetDC(0);
29  unsigned ret = GetDeviceCaps(dc,LOGPIXELSY);
30  ReleaseDC(0,dc);
31  return ret;
32 }
SIZE QueryScreenDPIEx ( )

Definition at line 35 of file win32_misc.cpp.

35  {
36  HDC dc = GetDC(0);
37  SIZE ret = { GetDeviceCaps(dc,LOGPIXELSY), GetDeviceCaps(dc,LOGPIXELSY) };
38  ReleaseDC(0,dc);
39  return ret;
40 }
static bool running_under_wine ( void  )
static

Definition at line 85 of file win32_misc.cpp.

85  {
86  HMODULE module = GetModuleHandle(_T("ntdll.dll"));
87  if (!module) return false;
88  return GetProcAddress(module, "wine_server_call") != NULL;
89 }
bool SetClipboardDataBlock ( UINT  p_format,
const void *  p_block,
t_size  p_block_size 
)

Definition at line 143 of file win32_misc.cpp.

143  {
144  bool success = false;
145  if (OpenClipboard(NULL)) {
146  EmptyClipboard();
147  HANDLE handle = GlobalAlloc(GMEM_MOVEABLE,p_block_size);
148  if (handle == NULL) {
149  CloseClipboard();
150  throw std::bad_alloc();
151  }
152  {CGlobalLock lock(handle);memcpy(lock.GetPtr(),p_block,p_block_size);}
153  if (SetClipboardData(p_format,handle) == NULL) {
154  GlobalFree(handle);//todo?
155  } else {
156  success = true;
157  }
158  CloseClipboard();
159  }
160  return success;
161 }
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
void SetDefaultMenuItem ( HMENU  p_menu,
unsigned  p_id 
)

Definition at line 134 of file win32_misc.cpp.

134  {
135  MENUITEMINFO info = {sizeof(info)};
136  info.fMask = MIIM_STATE;
137  GetMenuItemInfo(p_menu,p_id,FALSE,&info);
138  info.fState |= MFS_DEFAULT;
139  SetMenuItemInfo(p_menu,p_id,FALSE,&info);
140 }
void info(const char *p_message)
Definition: console.cpp:4
void WIN32_OP_D_FAIL ( const wchar_t *  _Message,
const wchar_t *  _File,
unsigned  _Line 
)

Definition at line 66 of file win32_misc.cpp.

66  {
67  const DWORD code = GetLastError();
68  pfc::array_t<wchar_t> msgFormatted; msgFormatted.set_size(pfc::strlen_t(_Message) + 64);
69  wsprintfW(msgFormatted.get_ptr(), L"%s (code: %u)", _Message, code);
70  if (IsDebuggerPresent()) {
71  OutputDebugString(TEXT("WIN32_OP_D() failure:\n"));
72  OutputDebugString(msgFormatted.get_ptr());
73  OutputDebugString(TEXT("\n"));
74  pfc::crash();
75  }
76  _wassert(msgFormatted.get_ptr(),_File,_Line);
77 }
const t_item * get_ptr() const
Definition: array.h:213
t_size strlen_t(const t_char *p_string, t_size p_length=~0)
Definition: primitives.h:771
void crash()
Definition: other.cpp:105
void set_size(t_size p_size)
Definition: array.h:104
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL ( )

Definition at line 52 of file win32_misc.cpp.

52  {
53  const DWORD code = GetLastError();
54  PFC_ASSERT( code != NO_ERROR );
55  throw exception_win32(code);
56 }
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL_CRITICAL ( const char *  what)

Definition at line 58 of file win32_misc.cpp.

58  {
59  const DWORD code = GetLastError();
60  PFC_ASSERT( code != NO_ERROR );
61  pfc::string_formatter msg; msg << what << " failure #" << (uint32_t)code;
62  TRACK_CODE(msg.get_ptr(), uBugCheck());
63 }
string8_fastalloc string_formatter
Definition: string_base.h:614
PFC_NORETURN void SHARED_EXPORT uBugCheck()