Creating a Remote Server Object

To create a remote WMSServer object, Windows Media Services must be installed on the remote computer. Also, you must use the DCOMCnfg utility to set the access, launch, and configuration permissions, and identify the users who can administer the server. For more information, see Using DCOM to Customize Security Settings. On the local computer, either Windows Media Services must be installed or the type library must be registered. To register the type library, run at the command prompt.regsvr32 WMSServerTypeLib.dll

If you are using C++, you must add the following define and include statements to your code.

#define _WIN32_DCOM     // Enables DCOM extensions.
#include "wmsserver.h"

If you are using C# or Visual Basic .NET, you must add a reference to the Windows Media Services Primary Interop Assembly (PIA). For more information, see Using the Windows Media Services Primary Interop Assembly. The following examples illustrate how to create a remote server object.

Visual Basic .NET Example

Imports Microsoft.WindowsMediaServices.Interop
Imports System.Runtime.InteropServices

Dim tServerType As Type
Dim RemoteServer As WMSServer

Try

    ' Retrieve the type information from the Windows
    ' Media server running on the remote machine.

    tServerType = Type.GetTypeFromProgID("WMSServer.Server", "server_name")

    ' Create an instance of the remote server object locally.
    RemoteServer = Activator.CreateInstance(tServerType)

Catch errCom As COMException
    ' TODO: Handle COM exceptions.
Catch err As Exception
    ' TODO: Exception handler goes here.
Finally
    ' TODO: Clean-up code goes here.
End Try

C# Example

using Microsoft.WindowsMediaServices.Interop;
using System.Runtime.InteropServices;

try 
{
    // Declare variables.
    Type        tServerType;
    WMSServer   RemoteServer;

    // Retrieve the type information from the Windows
    // Media server running on the remote machine.
    tServerType = Type.GetTypeFromProgID("WMSServer.Server",
                                         "remote_computer_name");

    // Create an instance of the remote server object locally.
    RemoteServer = (WMSServer)Activator.CreateInstance(tServerType);
}
catch (COMException comExc)
{
    // TODO: Handle COM exceptions.
}
catch (Exception e) 
{
    // TODO: Handle exceptions.
}

C++ Example

#define _WIN32_DCOM     // Enables DCOM extensions.
#include <windows.h>
#include <atlbase.h>
#include "wmsserver.h"

// Declare variables and interfaces.
IWMSServer      *pRemoteServer;

HRESULT         hr;
COSERVERINFO    cs;
MULTI_QI        mqi;

// Initialize the COM library.
hr = CoInitialize(NULL);
    
// Create a COSERVERINFO structure containing information about
// the computer on which to create the IWMSServer interface.
ZeroMemory(&cs, sizeof(cs));
cs.pwszName = L"remote-server-name";
cs.pAuthInfo = NULL;

// Create a MULTI_QI structure to hold an IUnknown pointer
// to an IWMSServer interface.
ZeroMemory(&mqi, sizeof(mqi));
mqi.pIID = &IID_IWMSServer;
mqi.pItf = NULL;
mqi.hr = 0;

// Retrieve a pointer to the IWMSServer interface.
hr = CoCreateInstanceEx(CLSID_WMSServer,
                        NULL,
                        CLSCTX_SERVER,
                        &cs,
                        1,
                        &mqi);
if (FAILED(hr)) goto EXIT;

// The MULTI_QI structure contains an IUnknown pointer. Call
// QueryInterface to retrieve a pointer to IWMSServer.
hr = mqi.pItf->QueryInterface(IID_IWMSServer,
                             (void**) &pRemoteServer);
if (FAILED(hr)) goto EXIT;

EXIT:
    // TODO: Release temporary COM objects and uninitialize COM.

See Also

Reference

IWMSServer Interface

IWMSServer Object (C#)

IWMSServer Object (Visual Basic .NET)

Concepts

Programming the Server Object Model