www.pudn.com > ReflectorAddIns.zip > RemoteController.cs, change:2004-12-14,size:2268b


namespace Reflector 
{ 
	using System; 
	using System.Runtime.InteropServices; 
 
	internal sealed class RemoteController 
	{ 
		private RemoteController() 
		{ 
		} 
 
		public static bool Available 
		{ 
			get 
			{ 
				return Send("Available\n4.0.0.0"); 
			} 
		} 
	 
		public static bool SelectTypeDeclaration(string key) 
		{ 
			return Send("SelectTypeDeclaration\n" + key); 
		} 
 
		public static bool SelectFieldDeclaration(string key) 
		{ 
			return Send("SelectFieldDeclaration\n" + key);	 
		} 
 
		public static bool SelectMethodDeclaration(string key) 
		{ 
			return Send("SelectMethodDeclaration\n" + key);	 
		} 
 
		public static bool SelectPropertyDeclaration(string key) 
		{ 
			return Send("SelectPropertyDeclaration\n" + key);	 
		} 
 
		public static bool SelectEventDeclaration(string key) 
		{ 
			return Send("SelectEventDeclaration\n" + key); 
		} 
 
		public static bool LoadAssembly(string fileName) 
		{ 
			return Send("LoadAssembly\n" + fileName); 
		} 
 
		public static bool UnloadAssembly(string fileName) 
		{ 
			return Send("UnloadAssembly\n" + fileName); 
		} 
 
		private static bool Send(string message) 
		{ 
			IntPtr targetWindow = FindWindow(null, "Lutz Roeder's .NET Reflector"); 
			if (targetWindow != IntPtr.Zero) 
			{ 
				char[] chars = message.ToCharArray(); 
				CopyDataStruct data = new CopyDataStruct(); 
				data.Padding = IntPtr.Zero; 
				data.Size = chars.Length * 2; 
				data.Buffer = Marshal.AllocHGlobal(data.Size); 
				Marshal.Copy(chars, 0, data.Buffer, chars.Length); 
				bool result = SendMessage(targetWindow, 0x004A, IntPtr.Zero, ref data); // WM_COPYDATA 
				Marshal.FreeHGlobal(data.Buffer); 
				return result; 
			} 
			 
			return false; 
		} 
	 
		[DllImport("user32.dll")] 
		private static extern IntPtr FindWindow(string className, string windowName); 
	 
		[DllImport("user32.dll")] 
		private static extern bool SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref CopyDataStruct lParam); 
	 
		private struct CopyDataStruct 
		{ 
			public IntPtr Padding; 
			public int Size; 
			public IntPtr Buffer; 
	 
			public CopyDataStruct(IntPtr padding, int size, IntPtr buffer) 
			{ 
				this.Padding = padding; 
				this.Size = size; 
				this.Buffer = buffer; 
			} 
		} 
	} 
}