클라이언트 쪽 공급자 어셈블리 등록
참고 항목
이 설명서는 System.Windows.Automation 네임스페이스에 정의된 관리되는 UI 자동화 클래스를 사용하려는 .NET Framework 개발자를 위한 것입니다. UI 자동화에 대한 최신 정보는 Windows 자동화 API: UI 자동화를 참조하세요.
이 항목에서는 클라이언트 쪽 UI 자동화 공급자가 포함된 DLL을 등록하는 방법을 보여줍니다.
예시
다음 예제에서는 콘솔 창에 대한 공급자가 포함된 어셈블리를 등록하는 방법을 보여줍니다.
using System;
using System.Windows.Automation;
using System.Reflection;
using System.Runtime.InteropServices;
using System.IO;
namespace CSClient
{
class CSClientProgram
{
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
static void Main(string[] args)
{
// TODO Change the path to the appropriate one for your CSProviderDLL.
string fileloc = @"C:\SampleDependencies\CSProviderDLL.dll";
Assembly a = null;
try
{
a = Assembly.LoadFile(fileloc);
}
catch (FileNotFoundException e1)
{
Console.WriteLine(e1.Message);
}
if (a != null)
{
try
{
ClientSettings.RegisterClientSideProviderAssembly(a.GetName());
}
catch (ProxyAssemblyNotLoadedException e)
{
Console.WriteLine(e.Message);
}
IntPtr hwnd = GetConsoleWindow();
// Get an AutomationElement that represents the window.
AutomationElement elementWindow = AutomationElement.FromHandle(hwnd);
Console.WriteLine("Found UI Automation client-side provider for:");
// The name property is furnished by the client-side provider.
Console.WriteLine(elementWindow.Current.Name);
Console.WriteLine();
}
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
}
}
Imports System.Windows.Automation
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.IO
Namespace CSClient
Friend Class CSClientProgram
<DllImport("kernel32.dll")>
Shared Function GetConsoleWindow() As IntPtr
End Function
Shared Sub Main(ByVal args() As String)
' TODO Change the path to the appropriate one for your CSProviderDLL.
Dim fileloc As String = "C:\SampleDependencies\CSProviderDLL.dll"
Dim a As System.Reflection.Assembly = Nothing
Try
a = System.Reflection.Assembly.LoadFile(fileloc)
Catch e1 As FileNotFoundException
Console.WriteLine(e1.Message)
End Try
If a IsNot Nothing Then
Try
ClientSettings.RegisterClientSideProviderAssembly(a.GetName())
Catch e As ProxyAssemblyNotLoadedException
Console.WriteLine(e.Message)
End Try
Dim hwnd As IntPtr = GetConsoleWindow()
' Get an AutomationElement that represents the window.
Dim elementWindow As AutomationElement = AutomationElement.FromHandle(hwnd)
Console.WriteLine("Found UI Automation client-side provider for:")
' The name property is furnished by the client-side provider.
Console.WriteLine(elementWindow.Current.Name)
Console.WriteLine()
End If
Console.WriteLine("Press any key to exit.")
Console.ReadLine()
End Sub
End Class
End Namespace