• 0

[C++] iTunes COM Interface


Question

well, i'm trying to make a DLL that uses the iTunes COM Interface (the SDK can be found here), and when i try to create an IiTunes object as described in the documentation, I get the following error:

  Quote
error C2259: 'IiTunes' : cannot instantiate abstract class

that's the code i used:

#include "iTunesCOMInterface.h"

HRESULT hRes;
IiTunes iITunes;

hRes = ::CoCreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER, IID_IiTunes, (PVOID *)&iITunes);

Can anyone explain me how to access the interface through C++?

Thanks a lot!

Link to comment
https://www.neowin.net/forum/topic/170611-c-itunes-com-interface/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

I don't know much about COM, but I think IDispatch inherited objects are abstract, so when you define the object like you have:

IiTunes iITunes;

it attempts to make an instance of, what is an abstract class. Try making a pointer to it instead

IiTunes* iITunes;

And see if that makes a difference.

  • 0
  billyburly said:
when i use
IiTunes* iITunes;

the program crashes when i try to use the object.

586688113[/snapback]

You should always initialise a pointer to NULL and the program is crashing because your pointer is pointing to random memory, you have not created an instance of the object so you need to use the COCreateInstance function as shown in the first post to create an instance of the object.

  • 0

This should work:

int main()
{
IiTunes* piTunes;
CoInitialize(0);

if (FAILED(CoCreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER, IID_IiTunes, (void **)&piTunes))) //create iTunes object
{
	MessageBox(0,"Failed to initialize iTunes","Error",0);
	return 0;
}

piTunes->Play(); //play the current song

piTunes->Release(); //release iTunes object

CoUninitialize();

return 0;
}

This code plays current iTunes track.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I think you forgot there's a ugly huge bar carved in the top of the screen.
    • There won't be any major changes from beta to release.
    • Having been using Windows for 30 years and 3 Surface Pros in the meantime (4,6,9) and recently bought a 15" macbook air m4. The OS is indeed a big deal. Hardware wise the surface pro feels as nice as macbook air, but Windows...man it's it's own enemy now
    • 2013 to 2017...wtf, is Steve on the wacky tabacky? Never heard of this or this Nathan guy in Australia.
    • Dell says it can't be blamed for Windows Night Light breaking on its Arm PCs by Usama Jawad Night Light is a very handy feature that is available by default in Windows 10 and Windows 11. Essentially, when you toggle it on, Windows reduces the emission of blue light from the display which in turn decreases the stress on eyes and can potentially aid in better sleep too. While this feature generally works quite well, this hasn't been the case so far on some Dell PCs. Now, Dell has acknowledged the issue in a recently published support document. As the situation currently stands, Night Light does not work on the secondary display on certain Windows Arm PCs when an external monitor is connected to them. This happens on the following PC models: Inspiron 14 5441 Inspiron 14 Plus 7441 Latitude 5455 Latitude 7455 XPS 13 9345 Now, Dell has confirmed that this is not due to any hardware or software issue on its side, it's just a limitation of the Qualcomm Oryon chipset. In essence, this is a problem that is outside the control of Dell. What this means is that while customers can utilize built-in and third-party tools to adjust the color profiles of their displays, Dell can't really get Windows Night Light to work as-is on external displays connected to any of the Arm PCs listed above. The company has emphasized that there are no plans to support Windows Night Light on its existing Arm PCs, and that customers will just have to make do with what they have. However, this feature will likely work as designed with the "next generation" of Arm computers, which will presumably leverage a chipset that is not held back by this limitation. Windows on Arm has enjoyed decent support from software developers in recent times; Microsoft will be hoping that it can keep the momentum going with its next Snapdragon PCs.
  • Recent Achievements

    • One Month Later
      langat earned a badge
      One Month Later
    • One Month Later
      Nullun earned a badge
      One Month Later
    • Week One Done
      moojay67 earned a badge
      Week One Done
    • Dedicated
      lethalman earned a badge
      Dedicated
    • Week One Done
      B4dM1k3 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      595
    2. 2
      ATLien_0
      219
    3. 3
      Michael Scrip
      198
    4. 4
      +FloatingFatMan
      144
    5. 5
      Xenon
      135
  • Tell a friend

    Love Neowin? Tell a friend!