use strict; use Win32::API; use constant S_OK => 0x00000000; use constant CLSCTX_INPROC_SERVER => 1; use constant CLSCTX_INPROC_HANDLER => 2; use constant CLSCTX_LOCAL_SERVER => 4; my $CoInitialize = new Win32::API("ole32.dll", "CoInitialize", 'P', 'N') or die "new CoInitialize: $!"; my $ret = $CoInitialize->Call(0); if ($ret != S_OK) { printf "CoInitialize->Call error: ret=%d (%08x)\n", $ret, $ret; exit; } print "CoInitialize->Call good\n"; my $CoCreateInstance = new Win32::API("ole32.dll", "CoCreateInstance", 'PPNPP', 'N') or die "new CoCreateInstance: $!"; # CLSID bits: 32, 16, 16, 8 x 8 - replace CLSID with correct one: my $class_id = '{ef636391-f343-11d0-9477-00c04fd36226}'; # fixed. 'g' $class_id =~ s/^{|}$//g; my @c = split /-/, $class_id; my $REFCLSID = pack 'LSSC8', hex $c[0], hex $c[1], hex $c[2], hex (substr $c[3], 0, 2), hex (substr $c[3], 2, 2), hex (substr $c[4], 0, 2), hex (substr $c[4], 2, 2), hex (substr $c[4], 4, 2), hex (substr $c[4], 6, 2), hex (substr $c[4], 8, 2), hex (substr $c[4], 10, 2); # empty pointer for returned ptr my $PPV = pack 'P', 0; my $dwClsContext = CLSCTX_INPROC_SERVER; # class context # null interface ID my $refiid = pack 'P', 0; # this interface would normally be a pointer to IUnknown or IClassFactory in UUID.LIB # pointer to accept return ptr my $ppv = pack 'P', $PPV; print "::: ($REFCLSID, 0, $dwClsContext, $refiid, $ppv)\n"; $ret = $CoCreateInstance->Call($REFCLSID, 0, $dwClsContext, $refiid, $ppv); if ($ret != S_OK) { printf "CoCreateInstance->Call error: ret=%d (%08x)\n", $ret, $ret; exit; } print "CoCreateInstance->Call good\n"; __END__ CO_E_FIRST 0x800401F0 CO_E_NOTINITIALIZED 0x800401F0 REGDB_E_CLASSNOTREG 0x80040154 E_OUTOFMEMORY 0x8004000E E_UNEXPECTED 0x8000FFFF CLASS_E_NOAGGREGATION 0x80040110 #define E_INVALIDARG 0x80070057L #define E_NOINTERFACE 0x80004002L #define CO_E_INIT_TLS 0x80004006L #define CO_E_INIT_SHARED_ALLOCATOR 0x80004007L #define CO_E_INIT_MEMORY_ALLOCATOR 0x80004008L #define CO_E_INIT_CLASS_CACHE 0x80004009L #define CO_E_INIT_RPC_CHANNEL 0x8000400AL #define CO_E_INIT_TLS_SET_CHANNEL_CONTROL 0x8000400BL #define CO_E_INIT_TLS_CHANNEL_CONTROL 0x8000400CL #define CO_E_INIT_UNACCEPTED_USER_ALLOCATOR 0x8000400DL #define CO_E_INIT_SCM_MUTEX_EXISTS 0x8000400EL #define CO_E_INIT_SCM_FILE_MAPPING_EXISTS 0x8000400FL #define CO_E_INIT_SCM_MAP_VIEW_OF_FILE 0x80004010L #define CO_E_INIT_SCM_EXEC_FAILURE 0x80004011L #define CO_E_INIT_ONLY_SINGLE_THREADED 0x80004012L #define CO_E_FIRST 0x800401F0L #define CO_E_LAST 0x800401FFL #define CO_E_NOTINITIALIZED 0x800401F0L #define CO_E_ALREADYINITIALIZED 0x800401F1L #define CO_E_CANTDETERMINECLASS 0x800401F2L #define CO_E_CLASSSTRING 0x800401F3L #define CO_E_IIDSTRING 0x800401F4L #define CO_E_APPNOTFOUND 0x800401F5L #define CO_E_ERRORINAPP 0x800401F7L #define CO_E_DLLNOTFOUND 0x800401F8L #define CO_E_ERRORINDLL 0x800401F9L #define CO_E_WRONGOSFORAPP 0x800401FAL #define CO_E_OBJNOTREG 0x800401FBL #define CO_E_OBJISREG 0x800401FCL #define CO_E_OBJNOTCONNECTED 0x800401FDL #define CO_E_APPDIDNTREG 0x800401FEL #define CO_E_RELEASED 0x800401FFL #define CO_E_CLASS_CREATE_FAILED 0x80080001L #define CO_E_SCM_ERROR 0x80080002L #define CO_E_SCM_RPC_FAILURE 0x80080003L #define CO_E_BAD_PATH 0x80080004L #define CO_E_SERVER_EXEC_FAILURE 0x80080005L #define CO_E_OBJSRV_RPC_FAILURE 0x80080006L #define CO_E_SERVER_STOPPING 0x80080008L