added a genguid helper function based on genguid by Jon Wilson. Will be needed later...
[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 #include <objbase.h>
24 #include <stdio.h>
25
26 static HRESULT (*pCoInitialize)(PVOID);
27 static void (*pCoUninitialize)(void);
28 static HRESULT (*pCoCreateGuid)(GUID*);
29
30 void gen_guid()
31 {
32 GUID m_guid;
33 HRESULT result;
34 char *strfmt = "";
35 HMODULE olelib;
36
37 /* Load ole32. We will need it later on */
38 olelib = LoadLibraryA( "ole32.dll" );
39
40 if (olelib != NULL)
41 pCoInitialize = (HRESULT (*)(void*))GetProcAddress( olelib, "CoInitialize" );
42 pCoUninitialize = (void (*)())GetProcAddress( olelib, "CoUninitialize" );
43 pCoCreateGuid = (HRESULT (*)(GUID*))GetProcAddress( olelib, "CoCreateGuid" );
44
45 if (pCoInitialize(NULL) != S_OK)
46 {
47 printf("Unable to initalize OLE libraries\n");
48 }
49 result = pCoCreateGuid(&m_guid);
50 if (result != S_OK) {
51 printf("Unable to create GUID\n");
52 pCoUninitialize();
53 }
54 strfmt = "%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X\r\n";
55 printf(strfmt,m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0],
56 m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5],
57 m_guid.Data4[6],m_guid.Data4[7],m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0],
58 m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5],
59 m_guid.Data4[6],m_guid.Data4[7]);
60 pCoUninitialize();
61 }