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 = GUID_NULL; 27 int arg; 28 HRESULT result; 29 char *strfmt = ""; 30 if (argc < 2) { 31 printf("usage: %s n\n",argv[0]); 32 printf("n = format of output\n"); 33 printf("values are:\n"); 34 printf("1 = IMPLEMENT_OLECREATE defintion\n"); 35 printf("2 = DEFINE_GUID definition\n"); 36 printf("3 = static const GUID definition\n"); 37 printf("4 = registry format\n"); 38 printf("5 = uuidgen.exe format\n"); 39 return 1; 40 } 41 arg = atoi(argv[1]); 42 if ((arg > 5) || (arg <= 0)) { 43 printf("invalid argument\n"); 44 return 1; 45 } 46 if (CoInitialize(NULL) != S_OK) 47 { 48 printf("Unable to initialize OLE libraries\n"); 49 return 1; 50 } 51 result = CoCreateGuid(&m_guid); 52 if (result != S_OK) { 53 printf("Unable to create GUID\n"); 54 CoUninitialize(); 55 return 1; 56 } 57 switch (arg) { 58 case 1: 59 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"; 60 break; 61 case 2: 62 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"; 63 break; 64 case 3: 65 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"; 66 break; 67 case 4: 68 strfmt = "{%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X}\r\n"; 69 break; 70 case 5: 71 strfmt = "%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X\r\n"; 72 break; 73 } 74 printf(strfmt,m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0], 75 m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5], 76 m_guid.Data4[6],m_guid.Data4[7],m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0], 77 m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5], 78 m_guid.Data4[6],m_guid.Data4[7]); 79 CoUninitialize(); 80 return 0; 81 } 82 83 84