0

I'm creating a program that does multiple things, and one of them is using the iTunes COM to open iTunes and play music. The one machine I'm compiling on has iTunes, the other does not. On the one that does not have iTunes, I must comment out code, but I was wondering if there was a way though #ifdef or something that I could still compile without having to do that.

Edit: The whole point is so I may compile on both machines without having to install iTunes on the machine that does not have it.

Dustin Jensen
  • 465
  • 1
  • 6
  • 16
  • Can you add your code? – HavelTheGreat Feb 13 '15 at 16:03
  • 1
    You should be able to run the same code fine, you'll just get a COM error when you try to create the iTunes interface object. Can't you just handle that error gracefully? Or did you mean how can you compile the same code on both machines? You can probably extract an interface definition, a .tlb, from the iTunes COM objects and check that in to build against whether the build machine has it installed or not. – Rup Feb 13 '15 at 16:04
  • @Rup yes I'd like to be able to compile on both machines. I'm not sure I understand about extracting the interface definition. Do you have any reading you could point me towards? – Dustin Jensen Feb 13 '15 at 16:07
  • 1
    Oops, I missed that this is C#. In that case you don't need a typelib, you can just [generate an interop assembly for the COM component](http://stackoverflow.com/a/5108972/243245) and compile against that without the COM object present. Or you can [extract the TLB](http://stackoverflow.com/a/4547830/243245) (which is the COM object and interface definition stored in the DLL that provides the COM objects) and add that to your project and have the interop assemblies generated at build time. – Rup Feb 13 '15 at 16:53
  • @Rup So if I understand correctly by extracting the TLB I'll be able to reference all the necessary functions for compiling, and then at runtime I can catch the COM error gracefully (as you mentioned previously) on machines without iTunes? – Dustin Jensen Feb 13 '15 at 19:25
  • 1
    I believe so, yes, although it's been a few years (and a few versions of the .NET tools) since I've actually done anything with COM. – Rup Feb 13 '15 at 19:28
  • @Rup I'll give this a whirl when I have a bit of time and can test it out :) Thanks Rup :) – Dustin Jensen Feb 13 '15 at 19:51

0 Answers0