Question

I am trying to implement the Windows Update Agent API asynchronous download/installation methods, however, I am having trouble implementing the callback classes (IInstallationProgressChangedCallback, etc.)

Here is an example implementation class that doesn't work using System; using WUApiLib;

namespace ConsoleApplication1
{
    class DownloadProgressCallback : IDownloadProgressChangedCallback
    {
        public override void Invoke(IDownloadJob downloadJob, IDownloadProgressChangedCallbackArgs callbackArgs)
        {
            Console.WriteLine("Do something");
        }
    }
}

Whenever I try to compile a project containing this class, I get

ConsoleApplication1.DownloadProgressCallback.Invoke(WUApiLib.IDownloadJob, WUApiLib.IDownloadProgressChangedCallbackArgs)': no suitable method found to override

For reference, here's how the interface is defined (metadata):

#region Assembly Interop.WUApiLib.dll, v2.0.50727
// F:\src\ConsoleApplication1\ConsoleApplication1\obj\x86\Debug\Interop.WUApiLib.dll
#endregion

namespace WUApiLib
{
    [InterfaceType(1)]
    [Guid("8C3F1CDD-6173-4591-AEBD-A56A53CA77C1")]
    [TypeLibType(384)]
    public interface IDownloadProgressChangedCallback
    {
        void Invoke(IDownloadJob downloadJob, IDownloadProgressChangedCallbackArgs callbackArgs);
    }
}

I'm not very familiar with COM/Interop, so I'm lost as to what I am doing wrong here.

Was it helpful?

Solution

You don't need to use override when implementing an interface. Just write:

    public void Invoke(IDownloadJob downloadJob, IDownloadProgressChangedCallbackArgs callbackArgs)
    {
       Console.WriteLine("Do something");
    }

The override keyword is used when inheriting from a base class, and "overriding" the inherited virtual (or abstract) method of the base class. For details, see override.

With an interface, you just need a matching method. You can implement the interface explicitly, as well:

void IDownloadProgressChangedCallback.Invoke(IDownloadJob downloadJob, IDownloadProgressChangedCallbackArgs args)
{ //...

This allows you to implement the interface in a manner that doesn't "pollute" the classes public API, or provide a different implementations for two interfaces which have members with the same names and types.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top