Click here to Skip to main content
15,887,267 members
Articles / Desktop Programming / ATL

Host Silverlight Control in C++ using ATL

Rate me:
Please Sign up or sign in to vote.
4.82/5 (20 votes)
18 May 2010CPOL2 min read 173.8K   1.4K   38  
Hosting Silverlight control in C++ using ATL
// AtlProject.idl : IDL source for AtlProject
//

// This file will be processed by the MIDL tool to
// produce the type library (AtlProject.tlb) and marshalling code.

import "oaidl.idl";
import "ocidl.idl";

[
    object,
    uuid(2E340632-5D5A-427b-AC31-303F6E32B9E8),
    nonextensible,
    helpstring("IXcpControlDownloadCallback Interface"),
    pointer_default(unique)
]
interface IXcpControlDownloadCallback : IUnknown
{
    HRESULT OnUrlDownloaded(HRESULT hr, IStream* pStream);
};

[
    object,
    uuid(1B36028E-B491-4bb2-8584-8A9E0A677D6E),
    nonextensible,
    helpstring("IXcpControlHost Interface"),
    pointer_default(unique)
]

interface IXcpControlHost : IUnknown
{
    typedef enum
    {
        XcpHostOption_FreezeOnInitialFrame       = 0x001,
        XcpHostOption_DisableFullScreen          = 0x002,
        XcpHostOption_DisableManagedExecution    = 0x008,
		XcpHostOption_EnableCrossDomainDownloads = 0x010,
        XcpHostOption_UseCustomAppDomain         = 0x020,
        XcpHostOption_DisableNetworking          = 0x040,        
        XcpHostOption_DisableScriptCallouts      = 0x080,
        XcpHostOption_EnableHtmlDomAccess        = 0x100,
        XcpHostOption_EnableScriptableObjectAccess = 0x200,
    } XcpHostOptions;

    HRESULT GetHostOptions([out, retval] DWORD* pdwOptions);

    HRESULT NotifyLoaded();

    HRESULT NotifyError([in] BSTR bstrError, [in] BSTR bstrSource, [in] long nLine, [in] long nColumn);

    HRESULT InvokeHandler([in] BSTR bstrName, [in] VARIANT varArg1, [in] VARIANT varArg2, [out, retval] VARIANT* pvarResult);

    HRESULT GetBaseUrl([out, retval] BSTR* pbstrUrl);

    HRESULT GetNamedSource([in] BSTR bstrSourceName, [out, retval] BSTR* pbstrSource);

    //
    // Called by Silverlight to allow a host to provide content for a specified URI. This is useful in cases
    // where a resource would normally be loaded out of a XAP at runtime. At design time, no XAP exists, and
    // the host can provide content for that resource.
    //
    // This method can work synchronously or asynchronously. If the pCallback parameter is NULL, the host must
    // do the work synchronously and return the result in ppStream. If the pCallback parameter is non-NULL, the host
    // may do the work synchronously or asynchronously, invoking callback methods as defined by the 
    // IXcpControlDownloadCallback interface. If the host chooses to work asyncronously, the ppStream parameter is
    // ignored.
    //
    // The host should return S_FALSE if it cannot provide a resource for the requested URI, and S_OK on a
    // successful request.
    //
    HRESULT DownloadUrl([in] BSTR bstrUrl, [in] IXcpControlDownloadCallback* pCallback, [out, retval] IStream** ppStream);

};

[
    object,
    uuid(fb3ed7c4-5797-4b44-8695-0c512ea27d8f),
    nonextensible,
    helpstring("IXcpControlHost2 Interface"),
    pointer_default(unique)
]
interface IXcpControlHost2 : IXcpControlHost
{
    HRESULT GetCustomAppDomain([out, retval] IUnknown** ppAppDomain);

    HRESULT GetControlVersion([out] UINT *puMajorVersion, [out] UINT *puMinorVersion);
};

[
	uuid(60074165-9D7F-43C9-B0A9-127FB2B8C267),
	version(1.0),
	helpstring("AtlProject 1.0 Type Library")
]
library AtlProjectLib
{
	importlib("stdole2.tlb");
	[
		uuid(1ADB6913-DD12-4F9E-95C8-46D4D01A8B65),
		helpstring("XcpControlHost Class")
	]

	coclass XcpControlHost
	{
		[default] interface IXcpControlHost;
	};
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Syed Aftab Hassan Naqvi

Comments and Discussions