views:

63

answers:

1

A thirdparty vendor has provided a COM interface as an external API to their product, and for sending instructions to it, it's fine with the mechanism of generating class wrappers with visual studio by importing from the dll, then creating instances of the created classes, calling their CreateDispatch(), using the access functions and releasing when done.

For return notifications, I'd normally create an EventsListener class derived from IDispatch using the Invoke function to handle events returning from the interface.

This vendor has created an Events class which I have to wrap and expose, then explicitly tell the installation where to look. all the example are given is C# where it's really easy, but I'm struggling on how to do it in C++

in the C# example provided with the API, the interop dll provided is simply added as a reference and derived into a class like so:

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Text;

using <THIER INTEROP LIB>

namespace some.example.namespace
{
    [ComVisible(true)]
    public class EventViewer : IEvents //where IEvents is their events class
    {
        public void OnEvent(EventID EventID, object pData) //overridden function
        {
            //event handled here
        }
    }
}

In broad terms I assume that I must create a COM interface, since they require a ProgID from me to instantiate, but how do I derive that's been wrapped by the import and then expose the created class to COM

I'm just not sure where to even start, as all the tutorials I've seen so far talk in terms of creating brand new classes not wrapping a third party one

+1  A: 

So they have provided you with an interface to implement and they get hold of your implementation by CoCreating the progid that you give to them? That's one way to do it, I guess...

How do you communicate your progid to their code? What expectations do they have of the COM class that you need to create?

You could either create an ATL COM object (dll) and simply implement the interface they give you (I assume they have either given you an idl file or a tlb?). However that will allow them to create your dll inside their process and it may not be ideal for you (how does that com dll then communicate with your process?, etc.) Alternatively you might look at creating an exe server rather than a dll. This would mean that you would run your process, register its objects, control the third-party app via its interface, pass it your prog id and then it could call back into your process... Again, ATL COM tutorials should help here.

Len Holgate
the ProgId is provided by way of filling in a registry entry that they read.It comes off as a little screwy, and I'd never heard of this being done before, but. C'est la vie...From their Docs: "the application [thiers] can instantiate a third-party component or assembly [mine] which will from then onreceive notification of events. To register a class to receive events from the API, the class identifier needs to be added as a registry key under the following value: HKLM\yadda\yadda. For a COM component, this value should the class’s ProgID" and that's the only non .net info provided
geocoin
In which case I'd go with an ATL dll COM object that implements their interface and which is pretty much otherwise standard ATL COM. Once you get their app to create you then you can work out what you want to do with the events they give you; you might set up some IPC between that COM dll and some other process, etc. You MIGHT be able to do it all with an exe server but I'd try the dll route first.
Len Holgate
found this example: http://www.codeproject.com/KB/COM/comintro2.aspxso far seems to be exactly what i need. I'll accept as soon as i have this working, but seems like this plus IPC is the way I'll have to proceed
geocoin
BTW, there is no .idl or .tlb provided. so far I have had to generate them using OLE viewer (idl) or with the VS class wizard (tlh and other interface class wrappers)
geocoin