create more correct solution files for different versions of MS Visual Studio
[reactos.git] / reactos / tools / rbuild / backend / msvc / genguid.cpp
1 /*
2 * Based on the genguid utility for WINE and ReactOS
3 *
4 * Copyright 2003 Jonathan Wilson
5 * Copyright 2005 Steven Edwards
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23
24 #include "msvc.h"
25 #include <string>
26
27 using std::string;
28
29 #ifdef _WIN32
30 #include <objbase.h>
31 #include <stdio.h>
32
33 typedef HRESULT _stdcall CoInitializeFunc ( PVOID );
34 typedef void _stdcall CoUninitializeFunc ( void );
35 typedef HRESULT _stdcall CoCreateGuidFunc ( GUID* );
36
37 static CoInitializeFunc *pCoInitialize = NULL;
38 static CoUninitializeFunc *pCoUninitialize = NULL;
39 static CoCreateGuidFunc *pCoCreateGuid = NULL;
40
41
42 std::string
43 MSVCBackend::_gen_guid()
44 {
45 GUID m_guid;
46 HRESULT result;
47 bool good_guid = false;
48 char* guid;
49
50 // Load ole32. We will need it later on
51 HMODULE olelib = LoadLibrary ( "ole32.dll" );
52 if ( olelib != NULL )
53 {
54 pCoInitialize = (CoInitializeFunc *)GetProcAddress( olelib, "CoInitialize" );
55 pCoUninitialize = (CoUninitializeFunc *)GetProcAddress( olelib, "CoUninitialize" );
56 pCoCreateGuid = (CoCreateGuidFunc *)GetProcAddress( olelib, "CoCreateGuid" );
57 if ( !pCoInitialize || !pCoUninitialize || !pCoCreateGuid )
58 printf ( "Missing exports from ole32.dll\n" );
59 else
60 {
61 if (pCoInitialize(NULL) != S_OK)
62 printf("Unable to initalize OLE libraries\n");
63 else
64 {
65 result = pCoCreateGuid(&m_guid);
66 if (result != S_OK)
67 printf("Unable to create GUID\n");
68 else
69 good_guid = true;
70 pCoUninitialize();
71 }
72 }
73 FreeLibrary ( olelib );
74 }
75 if ( !good_guid )
76 {
77 // TODO FIXME - fall-back to random #'s
78 }
79 const char* strfmt = "%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X";
80 sprintf(guid, strfmt,m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0],
81 m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5],
82 m_guid.Data4[6],m_guid.Data4[7],m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0],
83 m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5],
84 m_guid.Data4[6],m_guid.Data4[7]);
85
86 return guid;
87 }
88
89 #else /* Linux, etc */
90
91 std::string
92 MSVCBackend::_gen_guid()
93 {
94 }
95 #endif /* WIN32/Linux */