cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
CChong
Level 11 Flexeran
Level 11 Flexeran

Download events... C++ example?

My issue is that I've been trying to programmatically enumerate & download updates using IAgentEx, IUpdates & IUpdate objects. I tried to subscribe to the IUpdateEvents interface via connection points, but for some reason or another I'm never getting event notifications. The download does in fact occur... so I must be doing something wrong somewhere w/ the connection point code. I'm doing the same thing I generally do to receive connection point notifications and actually tried to modify a test program that I knew worked w/ another COM object that fired events, in order to receive the download events & still nothing.

I was basically wondering if anyone has some C++ code that I could look at which receive the events generated by IUpdate.

Any help would be much appreciated!
0 Kudos
(9) Replies
CChong
Level 11 Flexeran
Level 11 Flexeran

Got it working...
0 Kudos
CChong
Level 11 Flexeran
Level 11 Flexeran

Is there any chance of getting an example of your code cos I've been fighting with the same problem and there are no examples out there

Cheers

Dean
0 Kudos
CChong
Level 11 Flexeran
Level 11 Flexeran

Here's a quick sample of the working code :

//////////////////////////////////////////////////////////////////////////
// UpdateEventSink.h

#pragma once

#import "C:\Program Files\Common Files\InstallShield\UpdateService\Agent.exe" named_guids no_namespace raw_interfaces_only

// Sink class to receive update events
class CUpdateEventSink :
public IDispEventImpl<1, CUpdateEventSink, &DIID__IUpdateEvents, &LIBID_DWUpdateServiceLib, 1, 0>
{
// IUpdateEvent callback implementation
public:
void __stdcall OnDownloadBegin();
void __stdcall OnDownloadComplete(long nResult);
void __stdcall OnProgressChanged(long nBytes, long nPercent, BSTR strTransferRate, BSTR strTimeRemaining);
void __stdcall OnUpdateBegin();
void __stdcall OnUpdateComplete(long nReturnCode);

// Event sink map
BEGIN_SINK_MAP(CUpdateEventSink)
SINK_ENTRY_EX(1, DIID__IUpdateEvents, 0x1, OnDownloadBegin)
SINK_ENTRY_EX(1, DIID__IUpdateEvents, 0x2, OnProgressChanged)
SINK_ENTRY_EX(1, DIID__IUpdateEvents, 0x3, OnDownloadComplete)
SINK_ENTRY_EX(1, DIID__IUpdateEvents, 0x4, OnUpdateBegin)
SINK_ENTRY_EX(1, DIID__IUpdateEvents, 0x5, OnUpdateComplete)
END_SINK_MAP()
}



////////////////////////////////////////////////////////////////////
// example code to receive events :

// IMPORTANT : Use MTA threading if you're using a non-
/ message pump class
hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);

CComPtr spUpdate;

// enum updates here

// Connect event sink
CUpdateEventSink* pSink = new CUpdateEventSink
HRESULT hr = pSink->DispEventAdvise(spUpdate)

// Receive events ...

// Release event sink
HRESULTS hr = pSink->DispEventUnadvise(spUpdate);
0 Kudos
CChong
Level 11 Flexeran
Level 11 Flexeran

thats a great help, thanks
0 Kudos
CChong
Level 11 Flexeran
Level 11 Flexeran

I know it's been a while, but I'm trying to implement the same thing here.
My question is, where DIID__IUpdateEvents, LIBID_DWUpdateServiceLib come from
where are they declared. If it has something to do with the importing of the
agent.exe then is there any other way to
declare them since im using the dispatch method to connect to agent.exe

Thanks,
GrubUser
0 Kudos
louis1530
Level 2

I'm not sure that there is someone answer my reply or not. I would like to know that... how can I define the 3rd parameter in the SINK_ENTRY_EX(1, DIID__IUpdateEvents, 0x1, OnDownloadBegin) please if someone out there notice this reply.
0 Kudos
Not applicable

The 3rd parameter is in reference to the dispatch ID of the event on the interface. E.g. the number 0x1 refers to the first event in the list for IUpdateEvents ( in this that's OnDownloadBegin ). The number 0x2 would refer to the 2nd method in the list, OnProgressChanged, and so-forth. The ordering of those numbers is most easily accessed by opening agent.exe using the Object Browser of Visual Studio ( or whatever tool you have's equivalent ).

More information on that ATL macro can be found here:
http://msdn.microsoft.com/en-us/library/aaxh168w(v=vs.80).aspx

0 Kudos
smeadows
Level 3

Hello,

I've followed the example in the Reference guide for downloading and installing and the example mentioned above and I'm still not able get the events to fire. I'm using FNC 11.6 and VS2005?

Any help will be greatly appreciated!!
0 Kudos
krogerfan
Level 2

I don't know that there is somebody answer my answer or not. How might I characterize the third parameter in the SINK_ENTRY_EX(1, DIID__IUpdateEvents, 0x1, OnDownloadBegin) kindly in the event that somebody who might be listening notice this answer.

https://kroger-feedback-survey.com/
0 Kudos