libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
OnNT.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2002 by J.M.McGuiness, coder@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 #pragma once
20 
21 #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
22 #include<winbase.h> // Ensure the SYSTEM_INFO structure is defined.
23 
24 #include<lmcons.h>
25 
26 namespace jmmcg { namespace LIBJMMCG_VER_NAMESPACE { namespace NTUtils {
27 
28  inline tstring __fastcall GetLocalUsrName(void) {
29  register tchar tmp[UNLEN+1];
30  register unsigned long size=sizeof(tmp)/sizeof(tchar);
31  ::GetUserName(tmp,&size);
32  assert(tmp && size);
33  return tmp;
34  }
35 
36  inline tstring __fastcall GetLocalPCName(void) {
37  register tchar tmp[MAX_COMPUTERNAME_LENGTH+1];
38  register unsigned long size=sizeof(tmp)/sizeof(tchar);
39  ::GetComputerName(tmp,&size);
40  assert(tmp && size);
41  return tmp;
42  }
43 
44  inline void __fastcall GetLocalUsrInfo(tstring &unc,tstring &user) {
45  unc=GetLocalPCName();
46  user=GetLocalUsrName();
47  }
48 
49  inline bool __fastcall OnNT(void) noexcept(true) {
50  register OSVERSIONINFO osinfo;
51  osinfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
52  return ::GetVersionEx(&osinfo) && osinfo.dwPlatformId==VER_PLATFORM_WIN32_NT;
53  }
54 
55 } } }