【问题标题】:Call via C# out of process com objects for Airfoil [duplicate]通过 C# 调用 Airfoil 的进程外 com 对象 [重复]
【发布时间】: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 关键字。

标签: c# .net com


【解决方案1】:

您想使用 COM Interop 为 COM+ 组件创建一个包装器。

在此处查看 MSDN 教程:http://msdn.microsoft.com/en-us/library/aa645736(v=vs.71).aspx

我已经有一段时间没有自己做任何com互操作了,但是上面的教程非常详尽!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-01
    • 2014-02-05
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 2011-04-08
    • 2012-01-31
    • 2014-03-05
    相关资源
    最近更新 更多