libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
GetGUID.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 // DESCRIPTION:
19 // Get a GUID, return it as a string, that is _UNICODE compatible.
20 
21 #pragma once
22 
23 #include"../../../core/ttypes.hpp"
24 #include<objbase.h>
25 #include<string>
26 
27 // This is all implemented inline in the header file for raw speed. It *must* be
28 // as FAST AS POSSIBLE....
29 
30 namespace jmmcg { namespace LIBJMMCG_VER_NAMESPACE { namespace NTUtils {
31 
32  // Used to get unique names for the shared objects. These names are placed on an
33  // NT-global list, that other processes can access to get a handle to the
34  // underlying memory mapped file.
35  typedef tchar guid_type[39];
36 
37  inline tstring __fastcall GetGUID(void) {
38  GUID guid;
39  ::CoCreateGuid(&guid);
40 #ifdef _UNICODE
41  guid_type szName;
42  ::StringFromGUID2(guid, szName, sizeof(guid_type)/sizeof(wchar_t));
43 #else
44  wchar_t wszName[sizeof(wchar_t)*sizeof(guid_type)];
45  ::StringFromGUID2(guid, wszName, sizeof(wszName)/sizeof(wchar_t));
46  guid_type szName;
47  ::WideCharToMultiByte(CP_ACP, 0, wszName, -1, szName, sizeof(guid_type), NULL, NULL);
48 #endif _UNICODE
49  return szName;
50  }
51 
52 } } }