Partager via


Creating a Local Server Object

The following examples illustrate how to create a WMSServer object on a local computer. If you are using C++, you must include the Wmsserver.h file. 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.

Visual Basic .NET Example

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

Dim Server As WMSServer
Try
    Server = New WMSServer()
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 
{
    // Create a WMSServer object.
    WMSServer Server = new WMSServerClass();
}
catch (COMException comExc)
{
    // TODO: Handle COM exceptions.
}
catch (Exception e) 
{
    // TODO: Handle exceptions.
}

C++ Example

#include <windows.h>
#include "wmsserver.h"

// Declare variables and interfaces.
HRESULT       hr;
IWMSServer*   pServer;

// Initialize the COM library and retrieve a pointer
// to the IWMSServer interface.
hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_WMSServer,
                      NULL,
                      CLSCTX_ALL,
                      IID_IWMSServer,
                      (void **)&pServer);
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