Click here to Skip to main content
15,889,281 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ATL compiler error Pin
David Crow12-Mar-10 2:56
David Crow12-Mar-10 2:56 
GeneralRe: ATL compiler error Pin
Roger Stoltz12-Mar-10 3:53
Roger Stoltz12-Mar-10 3:53 
GeneralRe: ATL compiler error Pin
David Crow12-Mar-10 4:13
David Crow12-Mar-10 4:13 
GeneralRe: ATL compiler error Pin
Roger Stoltz12-Mar-10 5:08
Roger Stoltz12-Mar-10 5:08 
GeneralRe: ATL compiler error Pin
David Crow12-Mar-10 5:14
David Crow12-Mar-10 5:14 
GeneralRe: ATL compiler error Pin
Roger Stoltz12-Mar-10 5:43
Roger Stoltz12-Mar-10 5:43 
QuestionRe: ATL compiler error Pin
David Crow12-Mar-10 5:55
David Crow12-Mar-10 5:55 
AnswerRe: ATL compiler error Pin
Roger Stoltz12-Mar-10 8:34
Roger Stoltz12-Mar-10 8:34 
DavidCrow wrote:
It appears that I have steps 1-5 in place. Do you agree?


Nope, I don't agree.
Not unless you've altered the code you presented earlier where you tried to create an instance of CMyEventHandler by calling CreateInstance() into what I suggested, e.g. using new.


DavidCrow wrote:
Does the duck sample talk about how to avoid the GUID error that I'm battling?


Nope.
The question is irrelevant as a CLSID for CMyEventHandler won't be needed when you create a CMyEventHandler on the heap or the stack.
Note that what the compiler complains about is a missing "Class ID", CLSID, since it refers to the 'object' CMyEventHandler. The CLSID is the identity of the server one is trying to create with a call to CreateInstance(). This is not the same as the identity of the interface you're trying to use called "Interface ID" or IID, which also has a Globally Unique IDentifier assigned to it.


Your CMyEventHandler declaration should look something like this:
class ATL_NO_VTABLE CMyEventHandler : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public IWMPEvents
{
	public:
		BEGIN_COM_MAP( CMyEventHandler )
			COM_INTERFACE_ENTRY(IWMPEvents)
		END_COM_MAP()

	public:
		/* Here goes declarations of the functions in the IWMPEvents interface */
}; 

The code where you create the Media Player server should look something like this, as partially described in the article:
CComPtr<IWMPPlayer> spWMPPlayer;
CComPtr<IConnectionPoint> spConnectionPoint;
DWORD dwAdviseCookie;
HRESULT hr;

/* I don't know the CLSID or ProgID of the Media Player server as I'm currently sitting on an 
** Ubuntu machine at home, but let's just assume you've successfully created the Media Player  
** server and you have a valid interface pointer for it: spWMPPlayer.
** Anyway you seem to have taken care of that already. ;-)
*/

/* Create the CMyEventHandler object */
CMyEventHandler* pMyEventHandler =  new CComObject<CMyEventHandler>;

/* Get the connection point */
CComQIPtr<IConnectionPointContainer, &__uuidof(IConnectionPointContainer)> spConnectionContainer( spWMPPlayer );
if( spConnectionContainer )
{
	hr = spConnectionContainer->FindConnectionPoint( __uuidof(IWMPEvents), &spConnectionPoint ) 
	if( pMyEventHandler && SUCCEEDED( hr ) )
	{
		hr = spConnectionPoint->Advise( (IUnknown*)pMyEventHandler, &dwAdviseCookie );
	}
}


Finally, a little tip... Shucks | :-\
You could declare CMyEventHandler as a nested class inside the class from which you're creating the Media Player server. That would make it easier to call functions in the outer class from the event handlers. You could provide the 'this'-pointer to the constructor of the CMyEventHandler class and store it internally. Creation of the CMyEventHandler would of course look like this:
CMyEventHandler* pMyEventHandler =  new CComObject<CMyEventHandler>( this );

I suppose you have to declare the nested CMyEventHandler class as a friend to the outer class if you don't feel like exposing the callbacks publicly.
From a design point of view I like this way of writing a COM event sink.

I hope you'll find the above helpful.

"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown


GeneralRe: ATL compiler error Pin
David Crow12-Mar-10 9:50
David Crow12-Mar-10 9:50 
GeneralRe: ATL compiler error Pin
Roger Stoltz16-Mar-10 0:34
Roger Stoltz16-Mar-10 0:34 
GeneralRe: ATL compiler error Pin
David Crow16-Mar-10 2:58
David Crow16-Mar-10 2:58 
GeneralRe: ATL compiler error Pin
Roger Stoltz16-Mar-10 4:44
Roger Stoltz16-Mar-10 4:44 
GeneralRe: ATL compiler error Pin
David Crow16-Mar-10 9:00
David Crow16-Mar-10 9:00 
GeneralRe: ATL compiler error Pin
Roger Stoltz19-Mar-10 2:30
Roger Stoltz19-Mar-10 2:30 
QuestionSystem Tray Context Menu Pin
MrMcIntyre11-Mar-10 9:09
MrMcIntyre11-Mar-10 9:09 
AnswerRe: System Tray Context Menu Pin
loyal ginger11-Mar-10 9:31
loyal ginger11-Mar-10 9:31 
GeneralRe: System Tray Context Menu Pin
MrMcIntyre11-Mar-10 9:40
MrMcIntyre11-Mar-10 9:40 
GeneralRe: System Tray Context Menu Pin
loyal ginger11-Mar-10 9:59
loyal ginger11-Mar-10 9:59 
GeneralRe: System Tray Context Menu Pin
loyal ginger11-Mar-10 10:07
loyal ginger11-Mar-10 10:07 
GeneralRe: System Tray Context Menu Pin
LouisLewis15-Mar-10 11:05
LouisLewis15-Mar-10 11:05 
AnswerRe: System Tray Context Menu Pin
David Crow11-Mar-10 10:45
David Crow11-Mar-10 10:45 
AnswerRe: System Tray Context Menu Pin
Richard MacCutchan11-Mar-10 10:51
mveRichard MacCutchan11-Mar-10 10:51 
QuestionEncoding a string Pin
Herboren11-Mar-10 8:42
Herboren11-Mar-10 8:42 
AnswerRe: Encoding a string Pin
Chris Losinger11-Mar-10 8:48
professionalChris Losinger11-Mar-10 8:48 
AnswerRe: Encoding a string Pin
Jonathan Davies11-Mar-10 8:51
Jonathan Davies11-Mar-10 8:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.