disable defining ntstatus codes in windows.h/winnt.h when using ndk
[reactos.git] / rosapps / devutils / genguid / genguid.c
1 /*
2 * genguid utility for WINE and ReactOS
3 *
4 * Copyright 2003 Jonathan Wilson
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21 #include <objbase.h>
22 #include <stdio.h>
23
24 int main(int argc, char *argv[])
25 {
26 GUID m_guid;
27 m_guid = GUID_NULL;
28 int arg;
29 HRESULT result;
30 char *strfmt = "";
31 if (argc < 2) {
32 printf("usage: %s n\n",argv[0]);
33 printf("n = format of output\n");
34 printf("values are:\n");
35 printf("1 = IMPLEMENT_OLECREATE defintion\n");
36 printf("2 = DEFINE_GUID definition\n");
37 printf("3 = static const GUID definition\n");
38 printf("4 = registry format\n");
39 printf("5 = uuidgen.exe format\n");
40 return 1;
41 }
42 arg = atoi(argv[1]);
43 if ((arg > 5) || (arg <= 0)) {
44 printf("invalid argument\n");
45 return 1;
46 }
47 if (CoInitialize(NULL) != S_OK)
48 {
49 printf("Unable to initalize OLE libraries\n");
50 return 1;
51 }
52 result = CoCreateGuid(&m_guid);
53 if (result != S_OK) {
54 printf("Unable to create GUID\n");
55 CoUninitialize();
56 return 1;
57 }
58 switch (arg) {
59 case 1:
60 strfmt = "// {%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X}\r\nIMPLEMENT_OLECREATE(<<class>>, <<external_name>>, \r\n0x%lx, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x);\r\n";
61 break;
62 case 2:
63 strfmt = "// {%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X}\r\nDEFINE_GUID(<<name>>, \r\n0x%lx, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x);\r\n";
64 break;
65 case 3:
66 strfmt = "// {%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X}\r\nstatic const GUID <<name>> = \r\n{ 0x%lx, 0x%x, 0x%x, { 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x } };\r\n";
67 break;
68 case 4:
69 strfmt = "{%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X}\r\n";
70 break;
71 case 5:
72 strfmt = "%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X\r\n";
73 break;
74 }
75 printf(strfmt,m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0],
76 m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5],
77 m_guid.Data4[6],m_guid.Data4[7],m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0],
78 m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5],
79 m_guid.Data4[6],m_guid.Data4[7]);
80 CoUninitialize();
81 return 0;
82 }
83
84