Hi,
I have the code for rdp session for both the server side and the client side. I am just not able to implement the audiostream for the rdpsession class. I am not sure what I am doing thats wrong.
I am getting this error when I implement it.
Unable to cast COM object of type 'System.__ComObject' to interface type 'RDPCOMAPILib.IRDPSRAPIAudioStream'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{E3E30EF9-89C6-4541-BA3B-19336AC6D31C}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
What am I doing thats wrong ? The code is in the CreateRDPSession method
Parth AtaraPosted Sep 21, 2021, 8:21 AM
using System;using System.Collections.Generic;using System.Configuration;using System.Data;using System.Data.SqlClient;using System.Linq;using System.Net.NetworkInformation;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using RDPCOMAPILib;using HostvwithFile.Model;namespace HostvwithFile{////// Interaction logic for RemoteConnection.xaml///public partial class RemoteConnection : UserControl{// MainWindow mw = new MainWindow();public RDPSession x = new RDPSession();public RemoteConnection(){InitializeComponent();}public void BindComboBox(ComboBox comboBoxName){try{string strcon = ConfigurationManager.ConnectionStrings["vmconn"].ToString();using (SqlConnection con = new SqlConnection(strcon)){con.Open();using (SqlCommand com = new SqlCommand("SelectClient", con)){com.CommandType = CommandType.StoredProcedure;SqlParameter p1 = new SqlParameter("@relatedhost", System.Environment.MachineName.ToString());//SqlParameter p2 = new SqlParameter("@apassword", TxtPassword.Password);com.Parameters.Add(p1);//com.Parameters.Add(p2);using (SqlDataAdapter sda = new SqlDataAdapter(com)){DataSet dss = new DataSet();sda.Fill(dss, "ClientDetails");Clientcmbbox.ItemsSource = dss.Tables[0].DefaultView;Clientcmbbox.DisplayMemberPath = dss.Tables[0].Columns["ClientPCName"].ToString();Clientcmbbox.SelectedValuePath = dss.Tables[0].Columns["ClientIPAdd"].ToString();//dt.Rows[0]["column name"].ToString();//StoredConnections.AddConnection(dss.Tables[0].Rows[0]["ClientPCName"].ToString(), dss.Tables[0].Rows[0]["ClientIPAdd"].ToString());}}}}catch (Exception ex){LogHelper.Log(LogTarget.File, ex.StackTrace.ToString());}}private void AllowIncomingbtn_Click(object sender, RoutedEventArgs e){// mw.statuslbl.Content = "Ready for Connection";try{CreateRDPSession();}catch (Exception ex){LogHelper.Log(LogTarget.File, ex.Message + ex.StackTrace.ToString());}//toggleremotebtn.IsChecked = true;}private void CreateRDPSession(){//when the rdpsession is connected, trigger this event handlerthis.x.OnAttendeeConnected += Incoming;this.x.OnAttendeeDisconnected += Disconnect;this.x.Open();var buffer1 = this.x.FrameBuffer;var prop = this.x.Properties;IRDPSRAPIInvitation Invitation = x.Invitations.CreateInvitation("Trial", "Users", "", 1);//long pnPeriodInHundredNsIntervals = 100;Text2.Text = Invitation.ConnectionString;string adapteripadd = GetHamachiIPAdd();//LogHelper.Log(LogTarget.File, Text2.Text + " OR " + Invitation.ConnectionString);SubmitDetailstoDatabase(Text2.Text, adapteripadd);}private void Incoming(object Guest){try{IRDPSRAPIAttendee MyGuest = (IRDPSRAPIAttendee)Guest;//???MyGuest.ControlLevel = CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE;Test.Content = "Client connected" + MyGuest.RemoteName + MyGuest.ConnectivityInfo;Session.Text = "Open";LogHelper.Log(LogTarget.File, "Client connected" + MyGuest.RemoteName + MyGuest.ConnectivityInfo + "Session Details" + Session.Text);ShowCustomBalloon();//////////////long thisone = 100;IRDPSRAPIAudioStream gq = (IRDPSRAPIAudioStream)Guest;gq.Initialize(out thisone);gq.Start();}catch(Exception ex){LogHelper.Log(LogTarget.File, ex.StackTrace + ex.InnerException + ex.Message + ex.Source);}}private void Disconnect(object Guest){x.Close();MainWindow mainWindow = Application.Current.Windows.OfType<MainWindow>().FirstOrDefault();mainWindow.Show();}//public void CloseCurrentRDPSession()// {// Disconnect(x);// }public string GetHamachiIPAdd(){string ipadd = "";// Call methodfor (int i = 0; i < NetworkInterface.GetAllNetworkInterfaces().Length; i++){if (NetworkInterface.GetAllNetworkInterfaces()[i].Name == "Hamachi"){IPInterfaceProperties properties = NetworkInterface.GetAllNetworkInterfaces()[i].GetIPProperties();for (int j = 0; j < properties.UnicastAddresses.Count; j++){if (properties.UnicastAddresses[j].IPv4Mask.ToString() == "255.0.0.0"){ipadd = properties.UnicastAddresses[j].Address.ToString();}}}}return ipadd;}public void SubmitDetailstoDatabase(string inv, string hamachiipAddress){try{Clientcmbbox.IsEnabled = false;//string clientpcname = ComboItem.string clientnmfromcmbbox = Clientcmbbox.Text.ToString();string clientipfromcmbbox = Clientcmbbox.SelectedValue.ToString();StoredConnections.DeleteAllConnections();StoredConnections.AddConnection(clientnmfromcmbbox, clientipfromcmbbox);string servercon = ConfigurationManager.ConnectionStrings["vmconn"].ConnectionString;using (SqlConnection con = new SqlConnection(servercon)){con.Open();using (SqlCommand cmd = new SqlCommand()){cmd.Connection = con;cmd.CommandType = CommandType.StoredProcedure;cmd.CommandText = "InsertHostDetails";cmd.Parameters.AddWithValue("@hostname", System.Environment.MachineName);cmd.Parameters.AddWithValue("@hostipaddress", hamachiipAddress);cmd.Parameters.AddWithValue("@hostinvitation", inv);cmd.Parameters.AddWithValue("@clientspecific", clientnmfromcmbbox);cmd.Parameters.AddWithValue("@clientipadd", clientipfromcmbbox);cmd.ExecuteNonQuery();}}}catch(Exception ex){LogHelper.Log(LogTarget.File, ex.Message);}}private void toggleremotebtn_Checked(object sender, RoutedEventArgs e){if (toggleremotebtn.IsChecked == true){BindComboBox(Clientcmbbox);Clientcmbbox.IsEnabled = true;AllowIncomingbtn.IsEnabled = true;}else{Clientcmbbox.IsEnabled = false;AllowIncomingbtn.IsEnabled = false;}}private void Session_TextChanged(object sender, TextChangedEventArgs e){try{TextBox textBox = sender as TextBox;if (textBox.Text == "Closed"){x.Close();}}catch(Exception ex){LogHelper.Log(LogTarget.File, ex.StackTrace);}}private void BalloonCtrl_Click(object sender, RoutedEventArgs e){try{ShowCustomBalloon();}catch (Exception ex){LogHelper.Log(LogTarget.File, ex.StackTrace);}}}}