From ae5026eb5bde9295ba6d209fd98e6a53f8d6867b Mon Sep 17 00:00:00 2001 From: Royce Mitchell III Date: Wed, 24 Aug 2005 02:55:08 +0000 Subject: [PATCH] fix to not crash when built with msvc6 ( bad calling convention on imports ). fix error-handling bugs, added missing error-handling svn path=/trunk/; revision=17499 --- reactos/tools/rbuild/backend/msvc/genguid.cpp | 64 +++++++++++-------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/reactos/tools/rbuild/backend/msvc/genguid.cpp b/reactos/tools/rbuild/backend/msvc/genguid.cpp index d171997f4b5..bfe11b34be7 100644 --- a/reactos/tools/rbuild/backend/msvc/genguid.cpp +++ b/reactos/tools/rbuild/backend/msvc/genguid.cpp @@ -24,41 +24,55 @@ #include #include -static HRESULT (*pCoInitialize)(PVOID); -static void (*pCoUninitialize)(void); -static HRESULT (*pCoCreateGuid)(GUID*); +typedef HRESULT _stdcall CoInitializeFunc ( PVOID ); +typedef void _stdcall CoUninitializeFunc ( void ); +typedef HRESULT _stdcall CoCreateGuidFunc ( GUID* ); + +static CoInitializeFunc *pCoInitialize = NULL; +static CoUninitializeFunc *pCoUninitialize = NULL; +static CoCreateGuidFunc *pCoCreateGuid = NULL; void gen_guid() { GUID m_guid; HRESULT result; - char *strfmt = ""; - HMODULE olelib; + bool good_guid = false; - /* Load ole32. We will need it later on */ - olelib = LoadLibraryA( "ole32.dll" ); - - if (olelib != NULL) - pCoInitialize = (HRESULT (*)(void*))GetProcAddress( olelib, "CoInitialize" ); - pCoUninitialize = (void (*)())GetProcAddress( olelib, "CoUninitialize" ); - pCoCreateGuid = (HRESULT (*)(GUID*))GetProcAddress( olelib, "CoCreateGuid" ); - - if (pCoInitialize(NULL) != S_OK) + // Load ole32. We will need it later on + HMODULE olelib = LoadLibrary ( "ole32.dll" ); + if ( olelib != NULL ) { - printf("Unable to initalize OLE libraries\n"); + pCoInitialize = (CoInitializeFunc *)GetProcAddress( olelib, "CoInitialize" ); + pCoUninitialize = (CoUninitializeFunc *)GetProcAddress( olelib, "CoUninitialize" ); + pCoCreateGuid = (CoCreateGuidFunc *)GetProcAddress( olelib, "CoCreateGuid" ); + if ( !pCoInitialize || !pCoUninitialize || !pCoCreateGuid ) + printf ( "Missing exports from ole32.dll\n" ); + else + { + if (pCoInitialize(NULL) != S_OK) + printf("Unable to initalize OLE libraries\n"); + else + { + result = pCoCreateGuid(&m_guid); + if (result != S_OK) + printf("Unable to create GUID\n"); + else + good_guid = true; + pCoUninitialize(); + } + } + FreeLibrary ( olelib ); } - result = pCoCreateGuid(&m_guid); - if (result != S_OK) { - printf("Unable to create GUID\n"); - pCoUninitialize(); + if ( !good_guid ) + { + // TODO FIXME - fall-back to random #'s } - strfmt = "%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X\r\n"; + const char* strfmt = "%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X\r\n"; printf(strfmt,m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0], - m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5], - m_guid.Data4[6],m_guid.Data4[7],m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0], - m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5], - m_guid.Data4[6],m_guid.Data4[7]); - pCoUninitialize(); + m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5], + m_guid.Data4[6],m_guid.Data4[7],m_guid.Data1,m_guid.Data2,m_guid.Data3,m_guid.Data4[0], + m_guid.Data4[1],m_guid.Data4[2],m_guid.Data4[3],m_guid.Data4[4],m_guid.Data4[5], + m_guid.Data4[6],m_guid.Data4[7]); } #else /* Linux, etc */