fix to not crash when built with msvc6 ( bad calling convention on imports ).
[reactos.git] / reactos / tools / rbuild / backend / msvc / genguid.cpp
index d171997..bfe11b3 100644 (file)
 #include <objbase.h>\r
 #include <stdio.h>\r
 \r
-static HRESULT (*pCoInitialize)(PVOID);\r
-static void (*pCoUninitialize)(void);\r
-static HRESULT (*pCoCreateGuid)(GUID*);
+typedef HRESULT _stdcall CoInitializeFunc ( PVOID );\r
+typedef void _stdcall CoUninitializeFunc ( void );\r
+typedef HRESULT _stdcall CoCreateGuidFunc ( GUID* );\r
+\r
+static CoInitializeFunc *pCoInitialize = NULL;\r
+static CoUninitializeFunc *pCoUninitialize = NULL;\r
+static CoCreateGuidFunc *pCoCreateGuid = NULL;
 \r
 void gen_guid()\r
 {\r
        GUID m_guid;\r
        HRESULT result;\r
-       char *strfmt = "";\r
-       HMODULE olelib;\r
-\r
-    /* Load ole32. We will need it later on */\r
-       olelib = LoadLibraryA( "ole32.dll" );\r
+       bool good_guid = false;\r
 \r
-       if (olelib != NULL)\r
-               pCoInitialize = (HRESULT (*)(void*))GetProcAddress( olelib, "CoInitialize" );\r
-               pCoUninitialize = (void (*)())GetProcAddress( olelib, "CoUninitialize" );\r
-               pCoCreateGuid = (HRESULT (*)(GUID*))GetProcAddress( olelib, "CoCreateGuid" );\r
-\r
-       if (pCoInitialize(NULL) != S_OK)\r
+       // Load ole32. We will need it later on\r
+       HMODULE olelib = LoadLibrary ( "ole32.dll" );\r
+       if ( olelib != NULL )\r
        {\r
-               printf("Unable to initalize OLE libraries\n");\r
+               pCoInitialize = (CoInitializeFunc *)GetProcAddress( olelib, "CoInitialize" );\r
+               pCoUninitialize = (CoUninitializeFunc *)GetProcAddress( olelib, "CoUninitialize" );\r
+               pCoCreateGuid = (CoCreateGuidFunc *)GetProcAddress( olelib, "CoCreateGuid" );\r
+               if ( !pCoInitialize || !pCoUninitialize || !pCoCreateGuid )\r
+                       printf ( "Missing exports from ole32.dll\n" );\r
+               else\r
+               {\r
+                       if (pCoInitialize(NULL) != S_OK)\r
+                               printf("Unable to initalize OLE libraries\n");\r
+                       else\r
+                       {\r
+                               result = pCoCreateGuid(&m_guid);\r
+                               if (result != S_OK)\r
+                                       printf("Unable to create GUID\n");\r
+                               else\r
+                                       good_guid = true;\r
+                               pCoUninitialize();\r
+                       }\r
+               }\r
+               FreeLibrary ( olelib );\r
        }\r
-       result = pCoCreateGuid(&m_guid);\r
-       if (result != S_OK) {\r
-               printf("Unable to create GUID\n");\r
-               pCoUninitialize();\r
+       if ( !good_guid )\r
+       {\r
+               // TODO FIXME - fall-back to random #'s\r
        }\r
-       strfmt = "%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X\r\n";\r
+       const char* strfmt = "%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X\r\n";\r
        printf(strfmt,m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0],\r
-       m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5],\r
-       m_guid.Data4[6],m_guid.Data4[7],m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0],\r
-       m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5],\r
-       m_guid.Data4[6],m_guid.Data4[7]);\r
-       pCoUninitialize();\r
+               m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5],\r
+               m_guid.Data4[6],m_guid.Data4[7],m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0],\r
+               m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5],\r
+               m_guid.Data4[6],m_guid.Data4[7]);\r
 }\r
 
 #else /* Linux, etc */