Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
4.2 KiB

  1. # Compatibility layer for applications using the old toplevel OLE.pm.
  2. # New code should use Win32::OLE
  3. # This file is based on ../lib/OLE.pm from ActiveState build 315.
  4. # Compatibility notes:
  5. # - "GetObject" -> "GetActiveObject"
  6. # - "keys %$collection" -> "Win32::OLE::Enum->All($collection)"
  7. # or "in $Collection"
  8. # - "unnamed" default method retries
  9. ########################################################################
  10. package Win32;
  11. ########################################################################
  12. sub OLELastError {return OLE->LastError()}
  13. ########################################################################
  14. package OLE::Variant;
  15. ########################################################################
  16. use Win32::OLE qw(CP_ACP);
  17. use Win32::OLE::Variant;
  18. use strict;
  19. use vars qw($AUTOLOAD @ISA $LCID $CP $Warn $LastError);
  20. @ISA = qw(Win32::OLE::Variant);
  21. $Warn = 0;
  22. $LCID = 2 << 10; # LOCALE_SYSTEM_DEFAULT
  23. $CP = CP_ACP;
  24. sub new {
  25. my $self = shift;
  26. my $variant = $self->SUPER::new(@_);
  27. $OLE::LastError = $Win32::OLE->LastError unless defined $variant;
  28. return $variant;
  29. }
  30. ########################################################################
  31. package OLE::Tie;
  32. ########################################################################
  33. use strict;
  34. use vars qw(@ISA);
  35. @ISA = qw(Win32::OLE::Tie);
  36. # !!! It is VERY important that Win32::OLE::Tie::DESTROY gets called. !!!
  37. # If you subclass DESTROY, don't forget to call $self->SUPER::DESTROY.
  38. # Otherwise the OLE interfaces will not be released until process termination!
  39. # Retry default method if property doesn't exist
  40. sub FETCH {
  41. my ($self,$key) = @_;
  42. return $self->SUPER::Fetch($key, 1);
  43. }
  44. sub STORE {
  45. my ($self,$key,$value) = @_;
  46. $self->SUPER::Store($key, $value, 1);
  47. }
  48. # Enumerate collection members, not object properties
  49. *FIRSTKEY = *Win32::OLE::Tie::FIRSTENUM;
  50. *NEXTKEY = *Win32::OLE::Tie::NEXTENUM;
  51. ########################################################################
  52. package OLE;
  53. ########################################################################
  54. use Win32::OLE qw(CP_ACP);
  55. # Use OleInitialize() instead of CoInitializeEx:
  56. Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
  57. use strict;
  58. # Disable overload; unfortunately "no overload" doesn't do it :-(
  59. # Overloading is no longer enabled by default in Win32::OLE
  60. #use overload '""' => sub {overload::StrVal($_[0])},
  61. # '0+' => sub {overload::StrVal($_[0])};
  62. use vars qw($AUTOLOAD @ISA $LCID $CP $Warn $LastError $Tie);
  63. @ISA = qw(Win32::OLE);
  64. $Warn = 0;
  65. $LCID = 2 << 10; # LOCALE_SYSTEM_DEFAULT
  66. $CP = CP_ACP;
  67. $Tie = 'OLE::Tie';
  68. sub new {
  69. my $class = shift;
  70. $class = shift if $class eq 'OLE';
  71. return OLE->SUPER::new($class);
  72. }
  73. sub copy {
  74. my $class = shift;
  75. $class = shift if $class eq 'OLE';
  76. return OLE->SUPER::GetActiveObject($class);
  77. }
  78. sub AUTOLOAD {
  79. my $self = shift;
  80. my $retval;
  81. $AUTOLOAD =~ s/.*:://o;
  82. Carp::croak("Cannot autoload class method \"$AUTOLOAD\"")
  83. unless ref($self) && UNIVERSAL::isa($self,'OLE');
  84. local $^H = 0; # !hack alert!
  85. unless (defined $self->Dispatch($AUTOLOAD, $retval, @_)) {
  86. # Retry default method
  87. $self->Dispatch(undef, $retval, $AUTOLOAD, @_);
  88. }
  89. return $retval;
  90. }
  91. *CreateObject = \&new;
  92. *GetObject = \&copy;
  93. # Automation data types.
  94. sub VT_EMPTY {0;}
  95. sub VT_NULL {1;}
  96. sub VT_I2 {2;}
  97. sub VT_I4 {3;}
  98. sub VT_R4 {4;}
  99. sub VT_R8 {5;}
  100. sub VT_CY {6;}
  101. sub VT_DATE {7;}
  102. sub VT_BSTR {8;}
  103. sub VT_DISPATCH {9;}
  104. sub VT_ERROR {10;}
  105. sub VT_BOOL {11;}
  106. sub VT_VARIANT {12;}
  107. sub VT_UNKNOWN {13;}
  108. sub VT_I1 {16;}
  109. sub VT_UI1 {17;}
  110. sub VT_UI2 {18;}
  111. sub VT_UI4 {19;}
  112. sub VT_I8 {20;}
  113. sub VT_UI8 {21;}
  114. sub VT_INT {22;}
  115. sub VT_UINT {23;}
  116. sub VT_VOID {24;}
  117. sub VT_HRESULT {25;}
  118. sub VT_PTR {26;}
  119. sub VT_SAFEARRAY {27;}
  120. sub VT_CARRAY {28;}
  121. sub VT_USERDEFINED {29;}
  122. sub VT_LPSTR {30;}
  123. sub VT_LPWSTR {31;}
  124. sub VT_FILETIME {64;}
  125. sub VT_BLOB {65;}
  126. sub VT_STREAM {66;}
  127. sub VT_STORAGE {67;}
  128. sub VT_STREAMED_OBJECT {68;}
  129. sub VT_STORED_OBJECT {69;}
  130. sub VT_BLOB_OBJECT {70;}
  131. sub VT_CF {71;}
  132. sub VT_CLSID {72;}
  133. sub TKIND_ENUM {0;}
  134. sub TKIND_RECORD {1;}
  135. sub TKIND_MODULE {2;}
  136. sub TKIND_INTERFACE {3;}
  137. sub TKIND_DISPATCH {4;}
  138. sub TKIND_COCLASS {5;}
  139. sub TKIND_ALIAS {6;}
  140. sub TKIND_UNION {7;}
  141. sub TKIND_MAX {8;}
  142. 1;