PDA

View Full Version : Download events... C++ example?



smcgill
05-27-2003, 12:37 PM
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!

smcgill
06-04-2003, 09:32 AM
Got it working...

deansy
06-19-2003, 04:57 AM
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

smcgill
06-19-2003, 08:28 AM
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<IUpdate> 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);

deansy
06-27-2003, 09:39 AM
thats a great help, thanks

grubuser
03-01-2004, 06:11 PM
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

louis1530
05-26-2011, 09:57 PM
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.

bryanwolf
05-31-2011, 12:02 PM
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

smeadows
07-06-2011, 06:16 PM
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!!