3

I'm trying to use a method of the new WUAPI IUpdateInstaller4 for Windows 10. I found it here:

https://msdn.microsoft.com/en-us/library/windows/desktop/mt694207(v=vs.85).aspx

But all that i've tried failed:

Creation a dynamic object failed with "no defintion exception". Example:

dynamic installAgent = Activator.CreateInstance(Type.GetTypeFromProgID("Microsoft.Update.Installer"));
installAgent.Commit(IntPtr.Zero);

Creation of a new type lib did not contain the Interface.

tlbimp.exe wuapi.dll /out=c:\_sandbox\WUApiInterop.dll 

Any help or hint would be great.

M. Altmann
  • 726
  • 5
  • 20
  • Check this thread (also contains workaround): https://social.msdn.microsoft.com/Forums/Lync/en-US/92ddcc93-fcf3-4b60-8ca3-e3dbbdee77cf/iupdateinstaller4-missing-in-wuapilib?forum=csharpgeneral – Evk Nov 12 '16 at 11:42
  • @Evk - as Hans said in his answer, the workaround only works when you know what to define, but the intermediary IUpdateInstaller3 interface is missing from the surface of the known world (no .h, no .idl, no .tlb, no doc, no nothing) – Simon Mourier Nov 13 '16 at 10:53

1 Answers1

3

I repro. You certainly can't get this going on Win10 version 1607, the type library embedded in wuapi.dll is missing both the IUpdateInstaller3 and IUpdateInstaller4 interfaces. Something you can see for yourself when you run Oleview c:\windows\system32\wuapi.dll from the Developer Command Prompt.

Not the only problem, note the Wuapi_p.h header file quoted in the MSDN article. It is also missing the Win10 SDK version I have installed on my machine (version 10.0.10586.0). There is a newer version available (14393). Note sure if it includes it, I've been avoiding it due to horrible install problems I had with the previous release.

Not the only problem, MSDN is missing the definition of IUpdateInstaller3. That makes it too hard to guess how to declare the missing interfaces in C# correctly. You could punt and guess that IUpdateInstaller3 just added one more method.

It however does implement the interface. Querying for it using the IID documented in the MSDN article works fine on my machine:

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

class Program {
    static void Main(string[] args) {
        var obj = new WUApiLib.UpdateInstaller();
        var punk = Marshal.GetIUnknownForObject(obj);
        var iid4 = new Guid("EF8208EA-2304-492D-9109-23813B0958E1");
        IntPtr itf4;
        var hr = Marshal.QueryInterface(punk, ref iid4, out itf4);
        Debug.Assert(hr == 0 && itf4 != IntPtr.Zero);  // fine
    }
}

But that won't help you make the call, not without the interface definitions. These are typical "agile" problems btw, such a common issue with the way Microsoft does business these days. The rough and tumble is that you are doing this too early, next release might be better. Some odds that this will be Windows Server 2016, currently in Technical Preview. If you are going to work around it by declaring the interfaces yourself then keep in mind that your IUpdateInstaller4 declaration must include all the methods of the previous interface versions, interface inheritance can't work.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536