<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1632085368384154" crossorigin="anonymous"></script><script src="https://autohotkey.top/gtag.js"></script></head> <body> <h1>SoundGetInterface</h1> <p>检索声音设备或组件的原生 COM 接口.</p> <pre class="Syntax">InterfacePtr := <span class="func">SoundGetInterface</span>(IID, <span class="optional">Component, Device</span>)</pre> <h2 id="Parameters">参数</h2> <dl> <dt>IID</dt> <dd> <p>类型: <a href="../Concepts.htm#strings">字符串</a></p> <p>格式为 "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" 的接口标识符(GUID).</p> </dd> <dt>Component</dt> <dd> <p>类型: <a href="../Concepts.htm#strings">字符串</a>或<a href="../Concepts.htm#numbers">整数</a></p> <p>组件的显示名称和/或索引. 例如, <code>1</code>, <code>"Line in"</code> 或 <code>"Line in:2"</code>.</p> <p>如果省略或留空, 则检索由设备本身实现的接口.</p> <p>有关详情, 请参阅 <a href="Sound.htm#component">Component (Sound 函数)</a>.</p> </dd> <dt>Device</dt> <dd> <p>类型: <a href="../Concepts.htm#strings">字符串</a>或<a href="../Concepts.htm#numbers">整数</a></p> <p>设备的显示名称和/或索引. 例如, <code>1</code>, <code>"Speakers"</code>, <code>"Speakers:2"</code> 或 <code>"Speakers (Example HD Audio)"</code>.</p> <p>如果省略该参数, 则它默认为系统的默认回放设备(不一定是设备 1).</p> <p>有关详情, 请参阅 <a href="Sound.htm#device">Device (Sound 函数)</a>.</p> </dd> </dl> <h2 id="Return_Value">返回值</h2> <p>类型: <a href="../Concepts.htm#numbers">整数</a>或<a href="../Concepts.htm#nothing">字符串(空值)</a></p> <p>如果成功, 返回值是接口指针.</p> <p>如果失败, 返回值是空字符串.</p> <h2 id="Error_Handling">错误处理</h2> <p>失败时可能会抛出以下异常之一:</p> <table class="info"> <tr><th abbr="Class">Error 类</th><th>消息</th></tr> <tr><td rowspan="3"><a href="../objects/Error.htm#TargetError">TargetError</a></td><td>Device not found(无法找到设备)</td></tr> <tr><td>Component not found(无法找到组件)</td></tr> <tr><td>Component doesn't support this control type(组件不支持此控件类型)</td></tr> <tr><td><a href="../objects/Error.htm#OSError">OSError</a></td><td><em>System-generated.(由系统生成)</em></td></tr> </table> <h2 id="Remarks">备注</h2> <p>接口是从以下来源之一检索的:</p> <ul> <li>如果省略 <em>Component</em>, 则调用 <a href="https://docs.microsoft.com/en-us/windows/win32/api/mmdeviceapi/nf-mmdeviceapi-immdevice-activate">IMMDevice::Activate</a> 检索接口.</li> <li>为 <em>Component</em> 连接器标识调用 <a href="http://msdn.microsoft.com/en-us/library/ms682521.aspx">QueryInterface</a>, 如果成功, 则返回接口指针. 这可以用于检索连接器的 <a href="https://docs.microsoft.com/en-us/windows/win32/api/devicetopology/nn-devicetopology-ipart">IPart</a> 或 <a href="https://docs.microsoft.com/en-us/windows/win32/api/devicetopology/nn-devicetopology-iconnector">IConnector</a> 接口.</li> <li>对于给定 <em>Component</em> 唯一的每个子单元, 都会调用 <a href="https://docs.microsoft.com/en-us/windows/win32/api/devicetopology/nf-devicetopology-ipart-activate">IPart::Activate</a>. 例如, <em>IID</em> 可以是 <code>"{7FB7B48F-531D-44A2-BCB3-5AD5A134B3DC}"</code> 检索 IAudioVolumeLevel 接口, 该接口提供对每个通道音量级别控件的访问.</li> </ul> <p>一旦检索到接口指针, 可用 <a href="ComCall.htm">ComCall</a> 来调用它的方法. 参考 Windows SDK 头文件来识别正确的方法索引.</p> <p>接口指针必须在不再需要时通过传递给 <a href="ObjAddRef.htm">ObjRelease</a> 来释放. 这可以通过使用 <a href="ComValue.htm">ComValue</a> "包装" 它来实现. 包装的值(对象) 可以直接传递给 <a href="ComCall.htm">ComCall</a>.</p> <pre>Interface := ComValue(13, InterfacePtr)</pre> <h2 id="Related">相关</h2> <p><a href="Sound.htm">Sound 函数</a>, <a href="https://docs.microsoft.com/en-us/windows/win32/coreaudio/devicetopology-api">DeviceTopology API</a></p> <h2 id="Examples">示例</h2> <div class="ex" id="ExPeakMeter"> <p><a class="ex_number" href="#ExPeakMeter"></a> 峰值表. 将显示带有当前峰值的工具提示, 但峰值为零时除外(无声音播放).</p> <pre><em>; IAudioMeterInformation</em> audioMeter := SoundGetInterface("{C02216F6-8C67-4B5B-9D00-D008E73E0064}") if audioMeter { try loop <em>; 直到脚本退出或发生错误.</em> { <em>; audioMeter-&gt;GetPeakValue(&amp;peak)</em> ComCall 3, audioMeter, "float*", &amp;peak:=0 ToolTip peak &gt; 0 ? peak : "" Sleep 15 } ObjRelease audioMeter } else MsgBox "Unable to get audio meter" </pre> </div> <a href="https://dftg.net">dftg</a><!-- Cloudflare Pages Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "d5a9c4fcb9b6482fa53ce820d892f969"}'></script><!-- Cloudflare Pages Analytics --><script defer src="https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon='{"rayId":"93e51102ec4e223e","version":"2025.4.0-1-g37f21b1","r":1,"serverTiming":{"name":{"cfExtPri":true,"cfL4":true,"cfSpeedBrain":true,"cfCacheStatus":true}},"token":"51750bb5dc4f40cc91a5ec55c63bbc01","b":1}' crossorigin="anonymous"></script> </body> </html>