ICoreApplicationInitialization::Run method

Starts execution of the application object after an instance of it is created in an application.

Syntax

HRESULT Run(
  [in] HSTRING                  serverName,
  [in] IViewProviderFactory     *viewProviderFactory,
  [in] IActivationFactory       *getActivationFactory,
  [in] IBackgroundWorkerFactory *backgroundWorkerFactory
);

Parameters

  • serverName [in]
    Type: HSTRING

    The name of the ExeServer that this application implements. This is used by the application object to both look up metadata about this application but also to register all activatable classes implemented in this EXE.

  • viewProviderFactory [in]
    Type: IViewProviderFactory*

    A view provider factory to produce the default view provider for this application’s views. If this parameter is NULL, the application object assumes that entry point attribute specified in the manifest refers to an ActivatableClassId for the view provider.

  • getActivationFactory [in]
    Type: IActivationFactory*

    A thin wrapper around the ActivateInstance method for the server that the application object uses to register activation factories for ActivatableClassIds not aliased by the application object.

  • backgroundWorkerFactory [in]
    Type: IBackgroundWorkerFactory*

    The background worker factory that the application object uses to create background workers.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Examples

int wmain(int argc, wchar_t** argv)
{
    if(arc < 2)
    {
        return E_INVALIDARG;
    }

    HRESULT hr = Initialize(WINRT_INIT_MULTITHREADED);
    if (SUCCEEDED(hr))
    {
        // Scoping for ComPtr destruction
        {
            ComPtr<IApplication> spApplication;
            hr = ActivateInstance(StringReference(RuntimeClass_Application).Get(),
                                  &spApplication);

            if (SUCCEEDED(hr))
            {
                ComPtr<IViewProviderFactory> spViewFactory = Make<CMyViewProvider>();

                StringReference serverName(argv[1]);
                hr = spApplication->Run(serverName, 
                                        spViewFactory, // IViewProviderFactory
                                        nullptr, // IGetActivationFactory
                                        nullptr // IBackgroundProviderFactory
                                        );
            }
        }
        Uninitialize();
    }
    return hr;
}

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Header

Windows.ApplicationModel.Core.h

IDL

Windows.ApplicationModel.Core.idl

See also

ICoreApplicationInitialization