We help IT Professionals succeed at work.

COM object as event parameter

DevEagle
DevEagle asked
on
G'day, I've got a component that raises a few events.  For one of the events, I want to use a COM object as one of the parameters.  Eg.

[id(7)] HRESULT Connect([in] IUrl *remoteClient);

Firing it like this:

<other code omitted>
CComQIPtr<IUrl> pUrl;
Fire_Connect(pUrl.p)

The problem is that the event will not fire.  I have not found *any* articles explaining how to do this.  There are heaps on passing strings, integers, etc but not actual objects.

Any ideas?
Comment
Watch Question

What you mean "event will not fire" ? Please describe it more clear ?

What you mean "event will not fire" ? Please describe it more clear ?

Commented:
0. You are passing the parameter correctly; the .p is unneccessary because CComPtr has an operator (IUrl*).

1a. Can you fire the event when not passing an interface pointer, but passing i.e. a long?
1b. Can you pass a different interface (make the parameter type IUnknown*)?

2. I found a description in my VC++ online help "ATL Tutorial - Step 5: Adding an Event"

3. Are you sure you have a client connected?  It's easy to test with VB:

A. Menu Project/References add your dll.
B. Add code to create the object and trigger the event:
Dim WithEvents x as CYourClass
Set x= CreateObject("DLL.YourClass") ' Create by ProgId
call x.CauseEvent()
Set x= nothing ' Release().

C. Select "x" on the left hand combo box -- it shows connect on the right hand combo box and fills in this prototype:
public sub x_Connect(byval remoteclient as IUrl)
MsgBox "Got Here" ' Add this line yourself
End Sub

If you don't have VB, you can use VBA which comes with office (look for Macros).

Commented:
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to PAQ at zero points since you never gave more feedback.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
Per recommendation, points NOT refunded and question closed by
Netminder
CS Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.