ole.html
来自「perl教程」· HTML 代码 · 共 944 行 · 第 1/5 页
HTML
944 行
first OLE object is created. If the <code>Win32::OLE::Const</code> module is
used then the call to the <a href="#item_initialize"><code>Initialize()</code></a> method must be made from a BEGIN
block before the first <a href="../../lib/Pod/perlfunc.html#item_use"><code>use</code></a> statement for the <code>Win32::OLE::Const</code>
module.</p>
</dd>
<dd>
<p>Valid values for COINIT are:</p>
</dd>
<dd>
<pre>
Win32::OLE::COINIT_APARTMENTTHREADED - single threaded
Win32::OLE::COINIT_MULTITHREADED - the default
Win32::OLE::COINIT_OLEINITIALIZE - single threaded, additional OLE stuff</pre>
</dd>
<dd>
<p>COINIT_OLEINITIALIZE is sometimes needed when an OLE object uses
additional OLE compound document technologies not available from the
normal COM subsystem (for example MAPI.Session seems to require it).
Both COINIT_OLEINITIALIZE and COINIT_APARTMENTTHREADED create a hidden
top level window and a message queue for the Perl process. This may
create problems with other application, because Perl normally doesn't
process its message queue. This means programs using synchronous
communication between applications (such as DDE initiation), may hang
until Perl makes another OLE method call/property access or terminates.
This applies to InstallShield setups and many things started to shell
associations. Please try to utilize the <a href="#item_spinmessageloop"><code>Win32::OLE->SpinMessageLoop</code></a>
and <a href="#item_uninitialize"><code>Win32::OLE->Uninitialize</code></a> methods if you can not use the default
COINIT_MULTITHREADED model.</p>
</dd>
</li>
<dt><strong><a name="item_invoke">OBJECT->Invoke(METHOD[, ARGS])</a></strong>
<dd>
<p>The <a href="#item_invoke"><code>Invoke()</code></a> object method is an alternate way to invoke OLE
methods. It is normally equivalent to <code>$OBJECT-</code>METHOD(@ARGS)>. This
function must be used if the METHOD name contains characters not valid
in a Perl variable name (like foreign language characters). It can
also be used to invoke the default method of an object even if the
default method has not been given a name in the type library. In this
case use <undef> or <code>''</code> as the method name. To invoke an OLE objects
native <a href="#item_invoke"><code>Invoke()</code></a> method (if such a thing exists), please use:</p>
</dd>
<dd>
<pre>
<span class="variable">$Object</span><span class="operator">-></span><span class="variable">Invoke</span><span class="operator">(</span><span class="string">'Invoke'</span><span class="operator">,</span> <span class="variable">@Args</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_lasterror">Win32::OLE-><code>LastError()</code></a></strong>
<dd>
<p>The <a href="#item_lasterror"><code>LastError()</code></a> class method returns the last recorded OLE
error. This is a dual value like the <a href="../../lib/Pod/perlvar.html#item___"><code>$!</code></a> variable: in a numeric
context it returns the error number and in a string context it returns
the error message. The error number is a signed HRESULT value. Please
use the <a href="#item_hresult">HRESULT(ERROR)</a> function to convert an unsigned hexadecimal
constant to a signed HRESULT.</p>
</dd>
<dd>
<p>The last OLE error is automatically reset by a successful OLE
call. The numeric value can also explicitly be set by a call (which will
discard the string value):</p>
</dd>
<dd>
<pre>
<span class="variable">Win32::OLE</span><span class="operator">-></span><span class="variable">LastError</span><span class="operator">(</span><span class="number">0</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_letproperty">OBJECT-><code>LetProperty(NAME,ARGS,VALUE)</code></a></strong>
<dd>
<p>In Win32::OLE property assignment using the hash syntax is equivalent
to the Visual Basic <code>Set</code> syntax (<em>by reference</em> assignment):</p>
</dd>
<dd>
<pre>
<span class="variable">$Object</span><span class="operator">-></span><span class="operator">{</span><span class="string">Property</span><span class="operator">}</span> <span class="operator">=</span> <span class="variable">$OtherObject</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<p>corresponds to this Visual Basic statement:</p>
</dd>
<dd>
<pre>
Set Object.Property = OtherObject</pre>
</dd>
<dd>
<p>To get the <em>by value</em> treatment of the Visual Basic <code>Let</code> statement</p>
</dd>
<dd>
<pre>
Object.Property = OtherObject</pre>
</dd>
<dd>
<p>you have to use the <a href="#item_letproperty"><code>LetProperty()</code></a> object method in Perl:</p>
</dd>
<dd>
<pre>
<span class="variable">$Object</span><span class="operator">-></span><span class="variable">LetProperty</span><span class="operator">(</span><span class="variable">$Property</span><span class="operator">,</span> <span class="variable">$OtherObject</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p><a href="#item_letproperty"><code>LetProperty()</code></a> also supports optional arguments for the property assignment.
See <em>OBJECT-</em>SetProperty(NAME,ARGS,VALUE)> for details.</p>
</dd>
</li>
<dt><strong><a name="item_messageloop">Win32::OLE-><code>MessageLoop()</code></a></strong>
<dd>
<p>The <a href="#item_messageloop"><code>MessageLoop()</code></a> class method will run a standard Windows message
loop, dispatching messages until the <a href="#item_quitmessageloop"><code>QuitMessageLoop()</code></a> class method is
called. It is used to wait for OLE events.</p>
</dd>
</li>
<dt><strong><a name="item_option">Win32::OLE-><code>Option(OPTION)</code></a></strong>
<dd>
<p>The <a href="#item_option"><code>Option()</code></a> class method can be used to inspect and modify
<a href="#module_options">Module Options</a>. The single argument form retrieves the value of
an option:</p>
</dd>
<dd>
<pre>
<span class="keyword">my</span> <span class="variable">$CP</span> <span class="operator">=</span> <span class="variable">Win32::OLE</span><span class="operator">-></span><span class="variable">Option</span><span class="operator">(</span><span class="string">'CP'</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>A single call can be used to set multiple options simultaneously:</p>
</dd>
<dd>
<pre>
<span class="variable">Win32::OLE</span><span class="operator">-></span><span class="variable">Option</span><span class="operator">(</span><span class="string">CP</span> <span class="operator">=></span> <span class="variable">CP_ACP</span><span class="operator">,</span> <span class="string">Warn</span> <span class="operator">=></span> <span class="number">3</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_queryobjecttype">Win32::OLE-><code>QueryObjectType(OBJECT)</code></a></strong>
<dd>
<p>The <a href="#item_queryobjecttype"><code>QueryObjectType()</code></a> class method returns a list of the type library
name and the objects class name. In a scalar context it returns the
class name only. It returns <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> when the type information is not
available.</p>
</dd>
</li>
<dt><strong><a name="item_quitmessageloop">Win32::OLE-><code>QuitMessageLoop()</code></a></strong>
<dd>
<p>The <a href="#item_quitmessageloop"><code>QuitMessageLoop()</code></a> class method posts a (user-level) "Quit" message
to the current threads message loop. <a href="#item_quitmessageloop"><code>QuitMessageLoop()</code></a> is typically
called from an event handler. The <a href="#item_messageloop"><code>MessageLoop()</code></a> class method will
return when it receives this "Quit" method.</p>
</dd>
</li>
<dt><strong><a name="item_setproperty">OBJECT-><code>SetProperty(NAME,ARGS,VALUE)</code></a></strong>
<dd>
<p>The <a href="#item_setproperty"><code>SetProperty()</code></a> method allows to modify properties with arguments,
which is not supported by the hash syntax. The hash form</p>
</dd>
<dd>
<pre>
<span class="variable">$Object</span><span class="operator">-></span><span class="operator">{</span><span class="string">Property</span><span class="operator">}</span> <span class="operator">=</span> <span class="variable">$Value</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<p>is equivalent to</p>
</dd>
<dd>
<pre>
<span class="variable">$Object</span><span class="operator">-></span><span class="variable">SetProperty</span><span class="operator">(</span><span class="string">'Property'</span><span class="operator">,</span> <span class="variable">$Value</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>Arguments must be specified between the property name and the new value:</p>
</dd>
<dd>
<pre>
<span class="variable">$Object</span><span class="operator">-></span><span class="variable">SetProperty</span><span class="operator">(</span><span class="string">'Property'</span><span class="operator">,</span> <span class="variable">@Args</span><span class="operator">,</span> <span class="variable">$Value</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>It is not possible to use "named argument" syntax with this function
because the new value must be the last argument to SetProperty().</p>
</dd>
<dd>
<p>This method hides any native OLE object method called SetProperty().
The native method will still be available through the <a href="#item_invoke"><code>Invoke()</code></a> method:</p>
</dd>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?