1

I have an application called AirFoil. I contacted their support because I need to access functions of their program in my application. They have a API based on out-of-process COM. How can I interact with this COM objects throug C#?

They sent me a Javascript sample:

// 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);
   }
}

So how can I do the same in C#? How to instantiate the object? What references do I need?

var airfoilApp = WScript.CreateObject("RogueAmoeba.Airfoil");

Sorry but I haven't more information about the API.

Thanks for you're reply.

  • They showed you how to use late-bound calls to access their api. You don't add a reference to anything to do the same thing in .NET, you use the *dynamic* keyword instead. – Hans Passant Jul 08 '14 at 17:32

1 Answers1

1

You want to use COM Interop to create a wrapper for the COM+ component.

See MSDN tutorial here: http://msdn.microsoft.com/en-us/library/aa645736(v=vs.71).aspx

Its been a while since I've done any com interop myself, but the tutorial above is pretty thorough!

James S
  • 3,558
  • 16
  • 25