Solved

How to create COM sink using MFC?

Posted on 2008-06-21
4
832 Views
Last Modified: 2013-11-26
Hello,

I am having difficulties implementing a sink for a COM object dispatch interface. This is an MFC console application, so using wizards to add CCmdTarget automation is not an option.

I am not having any issues with using other interfaces (calling from my app into the COM object). It is the sink where I am running into a snag (from _Notify).

Here is a snippet of the TLH file, for which I need to implement the sink:
struct __declspec(uuid("2e21b3ec-f00f-f00f-8973-46d109c82f47"))  _TheLib;
struct __declspec(uuid("C3520671-f00f-f00f-9b96-0060083968AE")) _Notify;

TLI file for the interface of interest:
inline HRESULT _Notify::OnNotifyMsg ( )
{
    HRESULT _result = 0;
    _com_dispatch_method(this, 0x2, DISPATCH_METHOD, VT_ERROR, (void*)&_result, NULL);
    return _result;
}

Here is the IDL:
library TheLib
{
    // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("stdole2.tlb");

    // Forward declare all types defined in this typelib
    dispinterface _Notify;
    [
      uuid(C3520671-F00F-F00F-9B96-0060083968AE),
      helpstring("_Notifyinterface")
    ]

    dispinterface _Notify{
        properties:
        methods:
            [id(0x00000002)]
            HRESULT OnNotifyMsg();
    };
};

I've generated the  IDispatch wrapper class using the Add Class from Typelib Wizard. I've then attempted to inherit and extend the method which I am interested in - but the sink never receives any events.

I would greatly appreciate help with this. I've tried many different ways of doing this, and have looked through other posts about this subject on Experts Exchange - without too much help.

Thanks everyone!

NotLogical
0
Comment
Question by:NotLogical
  • 2
4 Comments
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 150 total points
ID: 21842176
THis codeproject article should provide some clues.
   Handling COM Events in a Console Application
   http://www.codeproject.com/KB/COM/xyevent.aspx
0
 
LVL 8

Author Comment

by:NotLogical
ID: 21842265
Dan,

The article you offered is quite interesting, although the XYDispDriver class which is discussed only connects one COM object's dispatcher to another one. This is done in a console application, but it unfortunately does not create a sink within said console application.

Thanks,

NotLogical
0
 
LVL 19

Assisted Solution

by:alb66
alb66 earned 150 total points
ID: 21864592
0
 
LVL 8

Accepted Solution

by:
NotLogical earned 0 total points
ID: 21871034
Thank you for your help... I think this will work!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now