Using the COM interface with VS2017 and plain C++

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

dplummer
Posts: 7
Joined: Sat Dec 20, 2008 12:55 pm

Using the COM interface with VS2017 and plain C++

Post by dplummer » Sat Jun 09, 2018 12:26 pm

All,

I know that the COM interface is deprecated and also appreciate that C++ is rather long in the tooth but I am where I am, trying to port some existing Python code that works with win32com into an existing c++ console application developed under Visual Studio 2017.

So far I have generated an IDL file from MediaMonkey.exe (4.1.20) and (after addition of some forward definitions) got it to compile .h and .c files which I have added to my project.

My problem now is that I cannot work out how to instantiate an SDB object to start working with.

I was expecting something like: SongsDB::SDBApplication SDB = new SongsDB::SDBApplication();
But SongsDB is not recognised

I have also tried using #import on the MM executable but my .tld file is failing to compile because various terms (such as EOF) have been #defined elsewhere and generate errors.

If someone could give me some pointers please I would be very grateful.

Many thanks
Dave
Best Regards
Dave Plummer
Norwich UK
MMW user since 2008, MMA user since release

PetrCBR
Posts: 1369
Joined: Tue Mar 07, 2006 5:31 pm
Location: Czech
Contact:

Re: Using the COM interface with VS2017 and plain C++

Post by PetrCBR » Mon Jun 11, 2018 5:03 am

Probably something like this could work ?

Code: Select all

ISDB *pSDB;
hr = CoCreateInstance(CLSID_SDB, NULL, CLSCTX_INPROC_SERVER, IID_SDB, reinterpret_cast<void**>(&pSDB));

dplummer
Posts: 7
Joined: Sat Dec 20, 2008 12:55 pm

Re: Using the COM interface with VS2017 and plain C++

Post by dplummer » Tue Jun 12, 2018 11:15 am

Many thanks petrCBR,

With a bit of tweaking that did the trick. Here is a working fragment:

Code: Select all

	CoInitialize(NULL);
	ISDBApplication *pSDB;
	HRESULT hr = CoCreateInstance(CLSID_SDBApplication, NULL, CLSCTX_LOCAL_SERVER, IID_ISDBApplication, reinterpret_cast<void**>(&pSDB));
	if (hr!=S_OK) {
		printf("Failed to create instance: %x\n", hr);
		return;
	}

	// Keep opened instance running after disconnect
	pSDB->put_ShutdownAfterDisconnect(false);    

	// Start the current track playing
	ISDBPlayer* pPlayer;
	pSDB->get_Player(&pPlayer);
	pPlayer->Play();
Best regards

Dave
Best Regards
Dave Plummer
Norwich UK
MMW user since 2008, MMA user since release

Post Reply