in reply to Calling CoInitializeSecurity() from Win32::API
To make a long story short....
use strict; use Win32::OLE qw(HRESULT); use constant CO_E_NOTINITIALIZED => 0x800401F0; my $result = -2147221008; if (HRESULT(CO_E_NOTINITIALIZED) == $result) { print "Eureka! The problem is CO_E_NOTINITIALIZED\n"; }
So the answer is, you must call CoInitialize() first before calling CoInitializeSecurity()...
And yes, this appears to work fine:
use strict; use Data::Dumper; use Win32::API; print "Setting COM security\n"; # CoInitilizeSecurity defined : # http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com +/htm/cmf_a2c_8ayh.asp my $CoInit = Win32::API->new( "OLE32.DLL", "CoInitialize", # input prototypes # 1 P, # reserved "P", "N", # return ) or warn "Can't get DLL"; my $CoInitSec = Win32::API->new( "OLE32.DLL", "CoInitializeSecurity", # input prototypes # 1 P, # Access perms # 2 N, # num of els in asAuthSvr # 3 P, # array of auth services # 4 P, # reserved # 5 N, # default auth level # 6 N, # proxy impersonation level # 7 P, # sole auth list # 8 N, # add'l capabilities # 9 P, # reserved "PNPPNNPNP", "N", # return ) or warn "Can't get DLL"; my $NULL = 0; my $RPC_C_AUTHEN_NONE = 0; my $RPC_C_AUTHEN_LEVEL_NONE = 1; my $RPC_C_IMP_LEVEL_IMP = 3; my $EOAC_NONE = 0; my $result1 = $CoInit->Call( $NULL ); if ($result1 != 0){ warn "Oops: ", Dumper($result1), "\n"; } my $result2 = $CoInitSec->Call( $NULL, 0, $RPC_C_AUTHEN_NONE, $NULL, $RPC_C_AUTHEN_LEVEL_NONE, $RPC_C_IMP_LEVEL_IMP, $NULL, $EOAC_NONE, $NULL, ); if ($result2 != 0){ warn "Oops: ", Dumper($result2), "\n"; } print "done\n";
I should add, it's probably more correct to pass in "undef" for a null pointer instead of your $NULL, because otherwise Win32::API might be passing a real valid pointer to the perl SV containing an integer zero.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Calling CoInitializeSecurity() from Win32::API
by jjohn (Beadle) on Feb 22, 2004 at 19:17 UTC |