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 <objbase.h>
#include <stdio.h> #include <stdio.h>
static HRESULT (*pCoInitialize)(PVOID); typedef HRESULT _stdcall CoInitializeFunc ( PVOID );
static void (*pCoUninitialize)(void); typedef void _stdcall CoUninitializeFunc ( void );
static HRESULT (*pCoCreateGuid)(GUID*); typedef HRESULT _stdcall CoCreateGuidFunc ( GUID* );
static CoInitializeFunc *pCoInitialize = NULL;
static CoUninitializeFunc *pCoUninitialize = NULL;
static CoCreateGuidFunc *pCoCreateGuid = NULL;
void gen_guid() void gen_guid()
{ {
GUID m_guid; GUID m_guid;
HRESULT result; HRESULT result;
char *strfmt = ""; bool good_guid = false;
HMODULE olelib;
/* Load ole32. We will need it later on */ // Load ole32. We will need it later on
olelib = LoadLibraryA( "ole32.dll" ); HMODULE olelib = LoadLibrary ( "ole32.dll" );
if ( olelib != NULL )
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)
{ {
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 ( !good_guid )
if (result != S_OK) { {
printf("Unable to create GUID\n"); // TODO FIXME - fall-back to random #'s
pCoUninitialize();
} }
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], 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[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[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[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.Data4[6],m_guid.Data4[7]);
pCoUninitialize();
} }
#else /* Linux, etc */ #else /* Linux, etc */