【发布时间】:2014-08-29 07:47:15
【问题描述】:
我有一个名为 AirFoil 的应用程序。我联系了他们的支持,因为我需要在我的应用程序中访问他们程序的功能。 他们有一个基于进程外 COM 的 API。如何通过 C# 与此 COM 对象进行交互?
他们给我发了一个 Javascript 示例:
// This script sample demonstrates how to enumerate the list of recent sources
// and the list of running sources that Airfoil for Windows sees.
// You can run this from the command line using cscript.exe.
function endsWith(str, suffix)
{
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
var airfoilApp = WScript.CreateObject("RogueAmoeba.Airfoil");
var recentSources = airfoilApp.GetRecentSources();
for(var i = 0; i < recentSources.Count(); i++)
{
var audioSource = recentSources.Item(i);
WScript.Echo("Recent source " + i + " is " + audioSource.Name());
}
var runningSources = airfoilApp.GetRunningSources();
for(var i = 0; i < runningSources.Count(); i++)
{
var audioSource = runningSources.Item(i);
WScript.Echo("Running source " + i + " is " + audioSource.Name());
if(endsWith(audioSource.Id().toLowerCase(),"firefox.exe"))
{
airfoilApp.SetCurrentSource(audioSource);
}
}
那么我怎样才能在 C# 中做同样的事情呢?如何实例化对象?我需要哪些参考资料?
var airfoilApp = WScript.CreateObject("RogueAmoeba.Airfoil");
抱歉,我没有关于 API 的更多信息。
感谢您的回复。
【问题讨论】:
-
他们向您展示了如何使用后期绑定调用来访问他们的 api。在 .NET 中,您无需添加对任何内容的引用来执行相同的操作,而是使用 dynamic 关键字。