WUAPI: Asynchronous operations with Visual Basic 6 Project

Discussion in 'Windows Update' started by morukland, Sep 11, 2005.

  1. morukland

    morukland Guest

    Dear all,

    can anybody give some advice how to perform an asynchronous search from
    a Visual Basic 6 application?

    I have the following module for the BeginSerach function:
    Public Sub WUScan(strType)
    Dim WUSsearchJob As ISearchJob
    Dim WUSState As Variant
    WUScriteria = "IsInstalled=0 and Type='Software'"
    Set WUSsearchJob = oUpd.BeginSearch(WUScriteria, ?iUnknown?,
    WUSState)
    End Sub

    I'm not sure what to put in for the IUnknown callback interface.
    Tried some methods, i.e. implementing the ISearchCompletedCallback
    interface into an ActiveX-DLL (Class WScanA) and calling it from the
    main app:

    Public Sub WUScan(strType)
    Dim WUSsearchJob As ISearchJob
    Dim WUSState As Variant
    WUScriteria = "IsInstalled=0 and Type='Software'"
    Set WScanX = New WScan.WScanA
    Set WUSsearchJob = oUpd.BeginSearch(WUScriteria, WScanX, WUSState)

    End Sub

    WScan ActiveX-DLL:
    'Class WScanA
    Implements ISearchCompletedCallback

    Private Sub Class_Initialize()
    Debug.Print "WUScan init"
    End Sub

    Private Sub Class_Terminate()
    Debug.Print "WUScan term"
    MsgBox Date & " " & Time & " - Test.."
    End Sub

    Public Sub ISearchCompletedCallback_Invoke(ByVal searchJob As
    WUApiLib.ISearchJob, ByVal callbackArgs As
    WUApiLib.ISearchCompletedCallbackArgs)
    MsgBox searchJob.IsCompleted
    End Sub

    ....which fails also. The class is terminating while the search is still
    ongoing. The %windir%\system32\windowsupdate.log contains then an error
    indicating the callback failed:
    WARNING: WU client fails to call back to search call
    {CAE90800-88AC-4EC9-AA02-E7D88B7E00E3} with error 0x8024000c

    If anyone could tell me how to implement the asynchronous functions of
    the WUAPI.dll (at least the BeginSearch) that would be really great.

    Thanks in advance.
     
    morukland, Sep 11, 2005
    #1
    1. Advertisements

  2. morukland

    Q Guest

    It looks like you were in the same boat as I was. I found an article in Swiss
    that solves this problem. After I was able to run the BeginSearch
    successfully, I tried to implement the same type of code for BeginDownload,
    but quickly realized that there was no way to do the Update list that it uses
    to download. Maybe you can figure that part out and re-post the solution here.

    Here is the link to answer your question:
    http://www.swissdelphicenter.ch/de/forum/index.php?showtopic=10601&hl=beginsearch

    If you copy the code right, it will work.

    Let me know if you get the downloadbegin to work?
     
    Q, Sep 17, 2005
    #2
    1. Advertisements

  3. morukland

    morukland Guest

    Hi,

    yes, I found the solution. I don't know exactly if it's the "normal"
    way to implement but it works. So simply implementing the interfaces in
    a special ActiveX-Dll works:
    i.e.
    ActiveX-DLL "WScan"
    Class "WScanA"
    ''''''''''''''''''''''''''''''''''''''''''''''''''
    Implements ISearchCompletedCallback

    Public Event SearchComplete()

    Public Sub ISearchCompletedCallback_Invoke(ByVal searchJob As
    WUApiLib.ISearchJob, ByVal callbackArgs As
    WUApiLib.ISearchCompletedCallbackArgs)
    RaiseEvent SearchComplete
    End Sub
    ''''''''''''''''''''''''''''''''''''''''''''''''''

    Then in your main application, you set a reference to the WScan.dll and
    add the following to your form object:
    ''''''''''''''''''''''''''''''''''''''''''''''''''
    Public WithEvents WScanUpdatesA As WScan.WScanA

    Public Sub WUScan
    Set WScanUpdatesA = New WScan.WScanA
    Set WUSsearchJob = oUpdSearcher.BeginSearch(WUScriteria,
    WScanUpdatesA, WUSState)
    End Sub

    Private Sub WScanUpdatesA_SearchComplete()
    'Receives the SearchComplete Event
    Call SearchJobStat(WUSsearchJob)
    End Sub

    ''''''''''''''''''''''''''''''''''''''''''''''''''

    I have implemented all other Callbacks (Download, Install..) to the
    same dll and its working fine.

    That's it!

    Ibrahim Isik
     
    morukland, Sep 27, 2005
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.