Skype API program run error - c#

I'm trying to show online/offline contacts from Skype, but I get an error:
An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
WindowsFormsApplication2.exe
Additional information: Retrieving the COM class factory for component
with CLSID {830690FC-BF2F-47A6-AC2D-330BCB402664} failed due to the
following error: 80040154.
Debugger says that an error is in: Skype skype = new Skype();
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SKYPE4COMLib;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
Skype skype = new Skype();
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(loadContacts));
thread.IsBackground = true;
thread.Priority = System.Threading.ThreadPriority.AboveNormal;
thread.Name = "Load Skype Contacts";
thread.Start();
}
private void button1_Click(object sender, EventArgs e)
{
}
List<string> contacts = new List<string>();
public void loadContacts()
{
contacts.Clear();
if (radioButton1.Checked)
{
foreach(User user in skype.Friends)
{
contacts.Add(user.Handle);
}
}
else if (radioButton2.Checked)
{
foreach (User user in skype.Friends)
{
if (user.OnlineStatus == TOnlineStatus.olsOnline | user.OnlineStatus == TOnlineStatus.olsNotAvailable | user.OnlineStatus == TOnlineStatus.olsDoNotDisturb | user.OnlineStatus == TOnlineStatus.olsAway)
{
contacts.Add(user.Handle);
}
}
}
MethodInvoker lvUpdate = delegate
{
listView1.Items.Clear();
foreach (var user in contacts)
{
listView1.Items.Add(user);
}
listView1.Sorting = SortOrder.Ascending;
if (radioButton1.Checked)
{
radioButton1.Text = String.Format("Online ({0})", listView1.Items.Count);
}
else if (radioButton2.Checked)
{
radioButton2.Text = String.Format("All contacts ({0})", listView1.Items.Count);
}
};
Invoke(lvUpdate);
}
}
}

I found the solution.
Build -> Configuration Manager -> Acitve solution platform -> New -> x86 (instead of x64)
This helped.

Related

myPrincipal.IsInRole(WindowsBuiltInRole.Administrator) returns false despite being Administrator

Can someone help me with this code, at the line concerning the condition if I'm and Administrator it returns false despite logged in as Administrator.
The C# Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security.Principal;
namespace WinFormsAppDummies
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Added code from the book C# 5.0 Dummies
WindowsIdentity myIdentity = WindowsIdentity.GetCurrent();
WindowsPrincipal myPrincipal = new WindowsPrincipal(myIdentity);
if (myPrincipal.IsInRole("Accounting"))
{
AccountingButton.Visible = true;
}
else if(myPrincipal.IsInRole("Sales"))
{
SalesButton.Visible = true;
}
else if (myPrincipal.IsInRole("Management"))
{
ManagerButton.Visible = true;
}
else if (myPrincipal.IsInRole(WindowsBuiltInRole.Administrator)) // <--- RETURNS FALSE!
{
ManagerButton.Visible = true;
}
}
private void SalesButton_Click(object sender, EventArgs e)
{
}
private void AccountingButton_Click(object sender, EventArgs e)
{
}
private void ManagerButton_Click(object sender, EventArgs e)
{
}
}
}
Can someone help me adjusting the previous code so that the Rule is seen as Administrator?

Gecko MultiThreading Error

I am trying to make an application with 5 virtual(hidden) Gecko(Xulrunner) Browser. But when I try to create one browser in Threading its return error at GeckoPreferences I am totally confused with it!
Here code Sample:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Skybound.Gecko;
using System.Threading;
namespace Gekco_Test
{
public partial class Main : DevExpress.XtraEditors.XtraForm
{
public Main()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
}
private void Main_Load(object sender, EventArgs e)
{
}
private void simpleButton1_Click(object sender, EventArgs e)
{
Thread th = new Thread(webControllerFunc);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
void webControllerFunc()
{
geckoWebControl gControll = new geckoWebControl();
gControll.webBrowserAccess("91.213.108.178", 80);
}
}
class geckoWebControl
{
bool readyState;
GeckoWebBrowser wb = new GeckoWebBrowser();
public string webBrowserAccess(string host,int port)
{
Skybound.Gecko.Xpcom.Initialize(Application.StartupPath + "\\xulrunner\\");
readyState = false;
Form form = new Form();
GeckoPreferences.User["network.proxy.http"] = host;
GeckoPreferences.User["network.proxy.http_port"] = port;
GeckoPreferences.User["network.proxy.type"] = 1;
wb.Navigate("about:blank");
wb.DocumentCompleted += wb_DocumentCompleted;
while (!readyState)
Application.DoEvents();
return wb.Document.TextContent;
}
void wb_DocumentCompleted(object sender, EventArgs e)
{
readyState = true;
}
}
}
Error:
{"Unable to cast COM object of type 'System.__ComObject' to interface type 'Skybound.Gecko.nsIServiceManager'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{8BB35ED9-E332-462D-9155-4A002AB5C958}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."}
Thanks!
Gecko Doesn't support multithreading. So you can use it following code to use it in the threads.
this.BeginInvoke(new Action(() => {
//What you want gecko browser to do! Like:
geckoBrowser.navigate("http://somewhere.com");
}));

Program Crashes on Debugging

I am new to C# this is kind of my first program. I am trying to integrate a SOAPI from OVH.IE (more info here: www.ovh.ie/products/soapi.xml), but whenever I launch the program and click the login button the program crashes (memory usage of VS2012 increases and then crashes).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Web.Services;
namespace Server_Manager
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
}
void login(string uid, string pwd, string dc)
{
if (dc == "OVH")
{
managerService soapi = new managerService();
string session = soapi.login(uid, pwd, "ie", false);
if (String.IsNullOrWhiteSpace(session))
{
MessageBox.Show("Not Logged");
}
else
{
MessageBox.Show("Logged In");
}
}
}
private void button1_Click(object sender, EventArgs e)
{
if (String.IsNullOrWhiteSpace(textBox1.Text) || String.IsNullOrWhiteSpace(textBox1.Text))
{
MessageBox.Show("Please Fill all the Details");
}
else
{
string uid, pwd, dc;
uid = textBox1.Text;
pwd = textBox2.Text;
dc = comboBox1.Text;
login(uid,pwd,dc);
}
MessageBox.Show(comboBox1.Text);
}
}
}
These instructions are for diagnosing this in WinDBG, a command line based debugger from microsoft, but I have been told they can work in Visual Studio.
Start up the application
Start up WinDBG and attach to the application
Type in ".loadby sos clr" (assuming >=4.0 framework)
Type "dumpheap -stat"
Look over the results, for suspicious objects type "dumpheap -mt {0}" where {0} is replaced by the objects MT address
If you don't know why objects are alive, type "gcroot {0}" passing an object address from above

Chilkat Sockets error WSAECONNRESET in C# 4.0

my code is working fine but also I am receiving lot of WSAECONNRESET An existing connection was forcibly closed by the remote host. error.
I have a Chilkat.Socket Listener exe which is executing as a windows service and a test program which is simply sending strings data to this listener service. Listener is working fine but the program which is generatring strings and sending it to the listener is receiving the below mentioned error...please guide.
Error:
ChilkatLog:
SendString:
DllDate: Jan 19 2012
UnlockPrefix: XXXXSocket
Username: XXXXXX
Architecture: Little Endian; 64-bit
Language: .NET 4.0 / x64
fd: 0x510
objectId: 1433
NumChars: 111
Charset: ansi
NumBytes: 111
SocketError: WSAECONNRESET An existing connection was forcibly closed by the remote host.
For more information see this Chilkat Blog post: http://www.cknotes.com/?p=217
Error sending on socket
send_size: 111
Failed.
This is my windows service code running as a listner
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Windows.Forms;
using Chilkat;
using NLog;
using Newtonsoft.Json;
namespace Test.Services.MessageServer
{
public partial class MessageProcessor : ServiceBase
{
private Chilkat.Socket _socket;
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
public MessageProcessor()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
init();
}
protected override void OnStop()
{
}
private void init()
{
_socket = new Chilkat.Socket();
_logger.Info("Service starting...");
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
//_logger.Info("Service started");
var success = _socket.UnlockComponent("XXXXXXSocket_XXXXXXXXX");
try
{
if (success != true)
{
return;
}
success = _socket.BindAndListen(5555, 25);
if (success != true)
{
_logger.Error(String.Format("Error: {0}", _socket.LastErrorText));
return;
}
// Get the next incoming connection
// Wait a maximum of 0 seconds (0000 millisec)
Chilkat.Socket connectedSocket = null;
connectedSocket = _socket.AcceptNextConnection(0);
if (connectedSocket == null)
{
_logger.Error(String.Format("Error: {0}", _socket.LastErrorText));
return;
}
connectedSocket.MaxReadIdleMs = 1000;
string txt = connectedSocket.ReceiveUntilMatch("-EOM-");
_logger.Info(String.Format("Received Orignal Message: {0}", txt));
if (txt == string.Empty)
{
_logger.Error(String.Format("Error: {0}", _socket.LastErrorText));
return;
}
connectedSocket.Close(0);
((BackgroundWorker)sender).ReportProgress(0, txt.Replace("-EOM-", string.Empty).Trim());
}
catch (Exception ex)
{
_logger.Error(String.Format("Error caught: {0}", _socket.LastErrorText));
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
if (e.UserState == null) return;
_logger.Info((String.Format("Message Received: {0}", e.UserState.ToString())));
var obj = JsonConvert.DeserializeObject<JsonGeoLocation>(e.UserState.ToString());
_logger.Info((String.Format("Received: JobId: {0}\tDateTime: {1}\tLatitude: {2}\tLongitude: {3}", obj.F0,obj.F1,obj.F2.F0,obj.F2.F1)));
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
}
}
This is my code which is connecting to the above code and sending the messages
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Chilkat;
using NLog;
using Newtonsoft;
using Newtonsoft.Json;
namespace SocketMessageGenerator
{
public partial class Form1 : Form
{
//private Chilkat.Socket _socket;
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
public Form1()
{
InitializeComponent();
Init();
}
private void Init()
{
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
SendMessage();
}
private void SendMessage()
{
var socket = new Socket();
var success = socket.UnlockComponent("XXXXXXSocket_XXXXXXXXX");
try
{
if (success != true)
{
return;
}
success = socket.Connect("191.111.009.256", 5555, false, 0);
if (!success)
{
_logger.Info((String.Format("Error: \nunable to connect to host: {0}", socket.LastErrorText)));
}
var geoLocation = new JsonGeoLocation { F0 = 123, F1 = System.DateTime.Now, F2 = new JsonGeoPosition { F0 = 51.577790260314941, F1 = 0.0993499755859375 } };
var obj = JsonConvert.SerializeObject(geoLocation);
success = socket.SendString(message);
//success = socket.SendString(obj);
if (!success)
{
_logger.Info((String.Format("Error: \nunable to send message: {0}", socket.LastErrorText)));
}
socket.Close(1000);
}
catch (Exception)
{
throw;
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
}
}

My textbox clear is getting Cannot implicitly convert type

All I want to do is just clear the text box on a button click. I get this error
"Error 2 Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox' C:\Users\Ed\Downloads\BT1_B\BT1_B\Form1.cs 108 36 BT1_B
"
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using InTheHand;
using InTheHand.Net;
using InTheHand.Net.Sockets;
using InTheHand.Net.Bluetooth;
namespace BT1_B
{
public partial class Form1 : Form
{
Guid service = new Guid("{00001101-0000-1000-8000-00805F9B34FB}");
BluetoothListener bl;
BluetoothClient bc;
bool radioAvailable = false;
bool listening = false;
delegate void SettbMessageReceivedCallback(string text);
public Form1()
{
InitializeComponent();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
listening = false;
bl.Stop();
}
catch
{
}
}
private void btn_listen_Click(object sender, EventArgs e)
{
try
{
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;
radioAvailable = true;
}
catch
{
MessageBox.Show("Please make sure Bluetooth is available");
}
if (radioAvailable)
{
bl = new BluetoothListener(BluetoothService.SerialPort);
bl.Start();
listening = true;
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ListenLoop));
t.Start();
}
}
private void ListenLoop()
{
try
{
while (listening)
{
bc = bl.AcceptBluetoothClient();
StreamReader sr = new StreamReader(bc.GetStream());
String message = sr.ReadLine();
sr.Close();
SettbMessageReceived(message);
}
}
catch
{
}
}
private void SettbMessageReceived(string text)
{
try
{
if (this.txt_incoming_message.InvokeRequired)
{
SettbMessageReceivedCallback d = new SettbMessageReceivedCallback(SettbMessageReceived);
this.Invoke(d, new object[] { text });
}
else
{
this.txt_incoming_message.Text += text + "\r\n";
}
}
catch (ThreadAbortException ex)
{
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn_clear_Click(object sender, EventArgs e)
{
txt_incoming_message.Clear();
}
}
}
private void btn_clear_Click(object sender, EventArgs e)
{
txt_incoming_message.Text = "";
}
but please keep the question specific, and do some research before asking for help.

Categories

Resources