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
This commit is contained in:
Royce Mitchell III 2005-08-24 02:55:08 +00:00
parent c905ca8a31
commit ae5026eb5b

View file

@ -24,41 +24,55 @@
#include <objbase.h>
#include <stdio.h>
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 */