1

I have an ATL project which exposes a COM object. I would like my COM object to call a function specified by the consumer from time to time, or via some other means of notifying the consumer from time to time.

I have tried adding a method in CerberusNative.idl in order to take void function pointers which I would like to call from the COM instance side of things so that the consumer would just need to tell the COM object upon initialization what its callbacks are:

interface ICerberusSession : IDispatch {
    [id(5)] HRESULT SetCallbacks([in] void(*userExit)(int, char *), [in] void(*userAttemptingReconnection)(), [in] void(*userReconnected)());
};

However, there are some problems with my void function pointers:

Severity Code Description Project File Line Suppression State Error MIDL2269 procedures in an object interface must return an HRESULT : [( Parameter 'userExit' ) ] Error MIDL2131 parameter must not be a function : [ Parameter 'userExit' of Procedure 'SetCallbacks' ( Interface 'ICerberusSession' ) ]

In what ways can I get a client application to subscribe to callback functions in my COM object?

1

2 Answers 2

1

The correct way to do it is to define a separate interface with methods on it, and to pass that interface into my setter method:

[
    object,
    uuid(AECE8D0C-F902-4311-A374-ED3A0EBB6B49),
    dual,
    nonextensible,
    pointer_default(unique)
]
interface ICallbacks : IUnknown
{
    [id(1)] HRESULT UserExit([in] int errorCode, [in] BSTR errorMessage);
    [id(2)] HRESULT UserAttemptingReconnection();
    [id(3)] HRESULT UserReconnected();
};

[
    object,
    uuid(B98A7D3F-651A-49BE-9744-2B1D8C896E9E),
    dual,
    nonextensible,
    pointer_default(unique)
]
interface ICerberusSession : IDispatch {
    ...
    [id(5)] HRESULT SetCallbacks([in] ICallbacks* callbacks);
};
Sign up to request clarification or add additional context in comments.

Comments

0

COM has a Concept called Connection Points for that

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.