void ContextNew(freerdp *instance, rdpContext *context) { Console.WriteLine("ContextNew"); hPreConnect = new pPreConnect(this.PreConnect); hPostConnect = new pPostConnect(this.PostConnect); instance->PreConnect = Marshal.GetFunctionPointerForDelegate(hPreConnect); instance->PostConnect = Marshal.GetFunctionPointerForDelegate(hPostConnect); this.context = context; input = instance->input; settings = instance->settings; }
public FreeRdpControl() { InitializeComponent(); rdp_client_entry_points_v1 e = new rdp_client_entry_points_v1(); _entryPoint = &e; NativeMethods.RdpClientEntry(_entryPoint); _context = NativeMethods.freerdp_client_context_new(_entryPoint); _instance = _context->instance; _settings = _instance->settings; // TODO: Set values for Hostname, domain, username, password this.Hostname = "10.x.x.xx"; // atleast this one should be set }
void ContextNew(freerdp* instance, rdpContext* context) { Console.WriteLine("ContextNew"); hPreConnect = new pPreConnect(this.PreConnect); hPostConnect = new pPostConnect(this.PostConnect); instance->PreConnect = Marshal.GetFunctionPointerForDelegate(hPreConnect); instance->PostConnect = Marshal.GetFunctionPointerForDelegate(hPostConnect); this.context = context; input = instance->input; settings = instance->settings; }
/// <summary> /// Connects the specified hostname. /// </summary> /// <param name="hostname">The hostname.</param> /// <param name="domain">The domain.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <param name="port">The port.</param> /// <returns></returns> public void Connect(string hostname, string domain, string username, string password, int port = 3389, ConnectionSettings connectionSettings = null) { if (hostname == null) { throw new ArgumentNullException(nameof(hostname)); } if (username == null) { throw new ArgumentNullException(nameof(username)); } if (_connected) { throw new FreeRdpException("Cannot connect when different connection is already active."); } DisposeContext(); NativeMethods.freerdp_context_new(_freerdp); _settings = _freerdp->settings; if (_settings == null) { throw new FreeRdpException("Contex creation failed"); } _settings->ServerPort = (uint)port; _settings->AsyncTransport = 1; _settings->AutoLogonEnabled = 1; //_settings->IgnoreCertificate = 1; //_settings->LocalConnection = 1; if (connectionSettings != null) { _settings->DesktopWidth = (uint)connectionSettings.DesktopWidth; _settings->DesktopHeight = (uint)connectionSettings.DesktopHeight; _settings->ColorDepth = (uint)connectionSettings.ColorDepth; } Debug.WriteLine("hostname:{0} username:{1} width:{2} height:{3} port:{4}", hostname, username, _settings->DesktopWidth, _settings->DesktopHeight, _settings->ServerPort); //The freerdp_context_free will free all strings, however it will cause Assert in debug mode, because // the heap manager used by c++ in debug is not the same as Marshal.StringToHGlobalAnsi uses _settings->ServerHostname = Marshal.StringToHGlobalAnsi(hostname); _settings->Username = Marshal.StringToHGlobalAnsi(username); if (!string.IsNullOrEmpty(domain)) { _settings->Domain = Marshal.StringToHGlobalAnsi(domain); } if (!string.IsNullOrEmpty(password)) { _settings->Password = Marshal.StringToHGlobalAnsi(password); } else { _settings->Authentication = 0; } _connected = NativeMethods.freerdp_connect(_freerdp) != 0; if (!_connected) { throw new FreeRdpException("Connection failed"); } }