Problem with c# ?

Handles clauses are not supported in C#

Page 1 of 1

3 Replies - 1045 Views - Last Post: 03 May 2009 - 05:00 PM Rate Topic: -----

#1 antoni428  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 18-April 09

Problem with c# ?

Post icon  Posted 02 May 2009 - 09:05 AM

Hi everybody. :D
I am working on a project that uses tapi(telephony application programming interface) functions on 'visual c# 2008 express edition' in order to make calls and answer calls directly from a PC.(Later i will add some advanced functionalities.)
I've found a nice code that enables to make a call(dial a number) from an application. But since the code was in VB i used an online converter to convert it to c#.
The problem is the code has some errors. The code converter itself put the errors in comment form within the converted code.The errors are:
/* ERROR: Not supported in C#: DeclareDeclaration */
/* ERROR: Handles clauses are not supported in C# */
You will find this comments within the code i've written below. I've put the comments in upper-case letters so that you can easily see them.
So, can anyone suggest about what can i add to this code so that the errors will be removed and sothat the code will run on 'visual c# 2008'.
Here's the code...
using System.Windows.Forms;

public class PhoneTAPI
{
	public static void Main()
	{
		Application.Run(new Form1());
	}
}

public class Form1 : System.Windows.Forms.Form
{
	public Form1()
	{
		base.New();

		InitializeComponent();

	}

	protected override void Dispose(bool disposing)
	{
		if (disposing) {
			if (!(components == null)) {
				components.Dispose();
			}
		}
		base.Dispose(disposing);
	}

	private System.ComponentModel.IContainer components;

	internal System.Windows.Forms.TextBox TextBox1;
	internal System.Windows.Forms.Label Label1;
	internal System.Windows.Forms.Button Button1;
	internal System.Windows.Forms.Label Label2;
	internal System.Windows.Forms.Button Button2;
	[System.Diagnostics.DebuggerStepThrough()]
	private void InitializeComponent()
	{
		this.TextBox1 = new System.Windows.Forms.TextBox();
		this.Label1 = new System.Windows.Forms.Label();
		this.Button1 = new System.Windows.Forms.Button();
		this.Label2 = new System.Windows.Forms.Label();
		this.Button2 = new System.Windows.Forms.Button();
		this.SuspendLayout();
		//
		//TextBox1
		//
		this.TextBox1.Location = new System.Drawing.Point(120, 32);
		this.TextBox1.Name = "TextBox1";
		this.TextBox1.Size = new System.Drawing.Size(152, 20);
		this.TextBox1.TabIndex = 0;
		this.TextBox1.Text = "";
		//
		//Label1
		//
		this.Label1.Location = new System.Drawing.Point(16, 32);
		this.Label1.Name = "Label1";
		this.Label1.Size = new System.Drawing.Size(104, 32);
		this.Label1.TabIndex = 1;
		this.Label1.Text = "Phone #";
		//
		//Button1
		//
		this.Button1.Location = new System.Drawing.Point(64, 72);
		this.Button1.Name = "Button1";
		this.Button1.Size = new System.Drawing.Size(64, 24);
		this.Button1.TabIndex = 2;
		this.Button1.Text = "Dial";
		//
		//Label2
		//
		this.Label2.Location = new System.Drawing.Point(32, 120);
		this.Label2.Name = "Label2";
		this.Label2.Size = new System.Drawing.Size(240, 104);
		this.Label2.TabIndex = 3;
		this.Label2.Text = "Message";
		//
		//Button2
		//
		this.Button2.Location = new System.Drawing.Point(160, 72);
		this.Button2.Name = "Button2";
		this.Button2.Size = new System.Drawing.Size(64, 24);
		this.Button2.TabIndex = 4;
		this.Button2.Text = "Exit";
		//
		//Form1
		//
		this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
		this.ClientSize = new System.Drawing.Size(292, 246);
		this.Controls.Add(this.Button2);
		this.Controls.Add(this.Label2);
		this.Controls.Add(this.Button1);
		this.Controls.Add(this.Label1);
		this.Controls.Add(this.TextBox1);
		this.ResumeLayout(false);

	}

 /*ERROR: NOT SUPPORTED IN C#: DECLAREDECLARATION*/
		const short TAPIERR_CONNECTED = 0;
	const short TAPIERR_NOREQUESTRECIPIENT = -2;
	const short TAPIERR_REQUESTQUEUEFULL = -3;
	const short TAPIERR_INVALDESTADDRESS = -4;
	private void  /*ERROR: HANDLES CLAUSES ARE NOT SUPPORTED IN C#*/Button1_Click(System.Object sender, System.EventArgs e)
	{
		string Str;
		short t;
		string buff;
		Str = Trim(TextBox1.Text);
		try {
			t = tapiRequestMakeCall(Str, "Dial", Str, "");
		}
		catch (Exception ex) {
			Label2.Text = "Error";
		}
		if (t != 0) {
			buff = "Error";
			switch (t) {
				case TAPIERR_NOREQUESTRECIPIENT:
					buff = buff + "No windows Telephony dialing application  is running and none could be started.";
				case TAPIERR_REQUESTQUEUEFULL:
					buff = buff + "The queue of pending Windows Telephony dialing requests is full.";
				case TAPIERR_INVALDESTADDRESS:
					buff = buff + "The phone number is not valid.";
				default:
					buff = buff + "Unkown error.";
			}
		}
		else {
			buff = "Dialing";
		}
		Label2.Text = buff;
	}

	private void  /* ERROR: HANDLES CLAUSES ARE NOT SUPPORTED IN C#*/Button2_Click(System.Object sender, System.EventArgs e)
	{
		System.Environment.Exit(0);
	}
}



This post has been edited by antoni428: 02 May 2009 - 09:11 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Problem with c# ?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4190
  • View blog
  • Posts: 11,864
  • Joined: 18-April 07

Re: Problem with c# ?

Posted 02 May 2009 - 09:30 AM

Please provide us the VB.NET equivalent so that we can see what was meant to be done versus what the converter has done now.

Btw... converters are crap and unless you know the language differences yourself to fix where the converter screwed up, I suggest you either do the conversion by hand or get someone to help you.

Waiting for your reply. :)


P.S. You are going to see a "wired event" in the InitializeComponent() function of the Form.Designer.CS file that will attach your control to the proper function. This is something that Windows VS will generate usually but you can do it yourself. Here is an example of a button wired to its click event...

this.button1.Click += new System.EventHandler(this.button1_Click);

This post has been edited by Martyr2: 02 May 2009 - 09:35 AM

Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Problem with c# ?

Posted 03 May 2009 - 04:07 PM

have you tried removing the "error" messages and running the code? To me, the code doesn't look wrong. It looks like the converter did the conversion, but got confused and thought it couldn't do the conversion.
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1634
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Problem with c# ?

Posted 03 May 2009 - 05:00 PM

The Handles clause is invalid in C# (only used in VB.NET). In your designer.cs file is where the event is handled for the button's click event. Look for the Button1 properties in the code you provided, it looks like this

this.Button1.Location = new System.Drawing.Point(64, 72);
this.Button1.Name = "Button1";
this.Button1.Size = new System.Drawing.Size(64, 24);
this.Button1.TabIndex = 2;
this.Button1.Text = "Dial";



Add this line to the bottom of that code

this.Button1.Click += new System.EventHandler(this.Button1_Click);



That line will wire up the button's click event
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1