How do I programmatically integrate the Updater with applications written in various languages?

Answer:

The Advanced Updater can be easily integrated with your application since you only have to launch it using an adequate command line option.

Here's a sample code written in C++ and ATL that integrates the updater with the MainFrame of an application.

TipSee more languages samples links at the bottom of this page.

#define UPDATER_NAME                   _T("updater.exe")
#define UPDATER_COMMAND_LINE_CHECKNOW  _T("updater.exe /checknow")
#define UPDATER_COMMAND_LINE_OPTIONS   _T("updater.exe /configure %u")
#define UPDATER_COMMAND_LINE_SILENT    _T("updater.exe /silent")

class MainFrame : public CFrameWindowImpl<MainFrame>,
                  public CUpdateUI<MainFrame>,
                  public CMessageFilter, public CIdleHandler
{
public:
  DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)
  ........
  BEGIN_MSG_MAP(MainFrame)
    MESSAGE_HANDLER(WM_CREATE, OnCreate)
    MESSAGE_HANDLER(WM_TIMER, OnTimer)
    ........
    COMMAND_ID_HANDLER(ID_CHECK_FOR_UPDATES, OnCheckForUpdates)
    COMMAND_ID_HANDLER(ID_UPDATER_OPTIONS, OnUpdaterOptions)
    ........
  END_MSG_MAP()
    ........

  LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/,
		      LPARAM /*lParam*/, BOOL& /*bHandled*/)
  {
    .......
    SetTimer(0, 5000);
    return 0;
  }

  void DoRunUpdater(CString aCommandLine)
   {
    TCHAR path[MAX_PATH];
    ::GetModuleFileName(NULL, path, MAX_PATH);

    CString updaterPath(path);
    int ind = updaterPath.ReverseFind(_T('\\'));
    if (ind > 0)
      updaterPath = updaterPath.Left(ind);
       if (updaterPath[updaterPath.GetLength() - 1] != _T('\\'))
         updaterPath += _T('\\');
    updaterPath += UPDATER_NAME;

    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    ::CreateProcess(updaterPath, const_cast<LPSTR>((LPCTSTR)aCommandLine),
      			 NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
  }

  LRESULT OnTimer(UINT /*uMsg*/, WPARAM /*wParam*/,
                  LPARAM /*lParam*/, BOOL& /*bHandled*/)
  {
    KillTimer(0);
    DoRunUpdater(UPDATER_COMMAND_LINE_SILENT);
    return 0;
  }

  LRESULT OnCheckForUpdates(WORD /*wNotifyCode*/, WORD /*wID*/,
			         HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  {
    DoRunUpdater(UPDATER_COMMAND_LINE_CHECKNOW);
    return 0;
  }

  LRESULT OnUpdaterOptions(WORD /*wNotifyCode*/, WORD /*wID*/,
			        HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  {
    CString commandLine;
    commandLine.Format(UPDATER_COMMAND_LINE_OPTIONS, m_hWnd);
    DoRunUpdater(UPDATER_COMMAND_LINE_OPTIONS);
    return 0;
  }
};

"/checknow" option

When using this command-line option, the Updater launches, checks if new updates are available and give you the possibility to download and install them. To launch Updater with this option from your application, you can create a menu option.

In the sample code from above, this scenario corresponds to the "OnCheckForUpdates" function.

"/configure [HWND]" option

When using this command line the "Updates Options" configuration dialog is displayed. This dialog allows you to enable or disable the updater, set the check frequency and select the folder where the updates will be downloaded. You could integrate this option in the same mode as explained above, with a menu option.

This command line is used in the above sample code with an additional parameter that specifies the parent window handle for the "Updates Options" dialog. This parameter is of unsigned integer type.

In the example, this option corresponds to the "OnUpdaterOptions" function. The “m_hWnd” represents the pointer to the parent window which in this case is the MainFrame.

"/silent" option

When using this option, Advanced Updater is launched and checks for updates at the interval specified in the "Updates Option" dialog. You can use the updater with this command line every time your application is launched.

This corresponds to the "OnTimer" function from the sample code.

Five seconds after you launch the application, the updater is launched too. This interval is set in the "OnCreate" function.

The updater checks whether or not it's time to verify for new updates depending on the check frequency you entered in the "Updates Option" dialog.

The "DoRunUpdater" function launches the updater with a certain command line option.

NoteIf you have a Java application, please follow the following link for a sample code that will help you integrate the updater: Integrate Updater In Java Application .

Topics