Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » problems compiling first Windows application
Closed Thread
Old 02-11-2009, 07:42 PM   #1 (permalink)
 
Junior Techie

Join Date: Nov 2008

Posts: 79

BobLewiston is on a distinguished road

Default problems compiling first Windows application

I tried to compile a Windows Forms Application in Visual C# 2008 Express with this source code from the CSharpSchool tutorial at Programmer's Heaven:
Code:
using System;
using System.Windows.Forms;
using System.Drawing;
namespace CSharpSchool
{
    class HelloWinForm
    {
        static void Main ()
        {
            Application.Run (new MyWindow ());
        }
    }
    class MyWindow : Form
    {
        public MyWindow () : base ()
        {
            this.Text = "My First Windows Application";
            this.Size = new Size (300, 300);
            Label lblGreeting = new Label ();
            lblGreeting.Text = "Hello WinForm";
            lblGreeting.Location = new Point (100, 100);
            this.Controls.Add (lblGreeting);
        }
    }
}
but I got these errors:

Error 1 Program 'C:\Documents and Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\obj\Release\HelloWinForm.exe ' has more than one entry point defined: 'HelloWinForm.Test.Main()'. Compile with /main to specify the type that contains the entry point. C:\Documents and Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\Form1.cs 8 21 HelloWinForm

Error 2 Program 'C:\Documents and Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\obj\Release\HelloWinForm.exe ' has more than one entry point defined: 'HelloWinForm.Program.Main()'. Compile with /main to specify the type that contains the entry point. C:\Documents and Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\Program.cs 14 21 HelloWinForm

Error 3 'HelloWinForm.Form1.Dispose(bool)': no suitable method found to override C:\Documents and Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\Form1.Designer.cs 14 33 HelloWinForm

Feeding this into a search engine:

"visual c#" "Compile with /main"

yielded this link:

Compiler Error CS0017
Visual C# Reference: Errors and Warnings. Compiler Error CS0017 ... Compile with /main to specify the type that contains the entry point. ...
msdn.microsoft.com/en-us/library/t9k01y87.aspx

which said:

If you are using MS Visual Studio and do not want to delete the other Main() methods you can specify the class which you want as you Entry Point in Startup Object in the Project Properties under Application Tab (at least for VS2008 Express)

Going to:

Project | HelloWinForm Properties | Application | Startup Object

I discovered it wasn't set. Setting it to either HelloWinForm.Test or HelloWinForm.Program, the first two problems disappear, but not the third. I can't see how this code has more than one entry point, and I'm not at all clear on why the compiler requires these gyrations in Startup Object. None of these issues are mentioned by CSharpSchool, which claims the code I used will run as written. This is my first Windows app, and WOW! am I in the dark on this. What gives? Maybe I should just get a different tutorial. Any explanations of this or, failing that, any suggestions for which tutorial(s) I should use?
BobLewiston is offline  
Old 02-12-2009, 10:21 AM   #2 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default Re: problems compiling first Windows application

I'm going to make some assumptions about what you've done:
- You created a new WinForms project in Visual Studio
- You added a new class and pasted the code you posted above into it

I will answer your question assuming that the above statements are true.

When you create a new WinForms project in Visual Studio, it creates a Program.cs file and a Form1.cs file automatically. This makes sense because you chose to create a WinForm project, so it creates a skeleton window (Form1.cs) and a file containing the 'Main' method ('Program.cs') -- the entry point to the program. If you create a third file and paste your code into it, you have added a second 'Main' method to your project. So you do, in fact, have more than one entry point.

For this specific example, delete the 'Form1.cs' class since you're not using it. Next, replace the auto generated 'Main' method in the 'Program.cs' file with the one you pasted above along with your 'MyWindow' class.
jaeusm is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Tech Forums Official Crysis [Warhead] GPU Benchmark Thread gurusan Overclocking, Case Mod, Tweaking PC Performance 528 10-28-2009 09:43 PM
error code 80070490, Windows Defender update cased some problems! Wildside Windows Operating Systems and Software 4 12-09-2008 10:30 PM
Booting Windows XP From An External Drive Osiris Apple, Mac OS , and Power PC 0 09-11-2008 09:23 AM
Reformatted computer, but have problems.. ruderitalin Windows Operating Systems and Software 3 05-11-2008 09:40 PM
Sony VAIO Desktop - Windows Home Edition Problems KugarWeb Windows Operating Systems and Software 2 09-12-2007 01:01 PM