Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Aug 2014
    Location
    Sweden
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    C# Cross-windows compiling on VS2012 and CSC .NET4 Compiler

    Hello

    I'm working on a few C# .NET version 4 projects which hit a dead end really quickly;

    I'm able to compile the code on a jailbroken windows RT device (using this method: [how to] Develop on Windows RT: A C# Scratch… | Windows 8 | XDA Forum )
    I'm not able to compile the code in visual studio 2012 on a normal windows pc

    I get errors in vs2012 saying "The handle is invalid" on string and console related functions

    Any help would be appreciated.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,919
    Thanks
    79
    Thanked 4,423 Times in 4,388 Posts
    Not able to COMPILE? Or not able to execute code? An invalid handle sounds like a run-time error, not a compilation error. And it's not clear to me how a handle would ever be involved in string methods.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,919
    Thanks
    79
    Thanked 4,423 Times in 4,388 Posts
    In any case, SHOW YOUR CODE. Show AT LEAST the method where you get the error and preferably the entire class.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New to the CF scene
    Join Date
    Aug 2014
    Location
    Sweden
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I didn't see if it was at compile time or at runtime since I was never presented with the UI.

    Code:
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    
    class MForm : Form
    {
        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem option1ToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem option2ToolStripMenuItem;
    
        private System.Windows.Forms.ToolStrip toolStrip1;
        private System.Windows.Forms.ToolStripButton toolStripButton1;
        private System.Windows.Forms.ToolStripButton toolStripButton2;
    
        private System.Drawing.Bitmap toolstripIcon1;
    
        public MForm()
        {
    		Button btn1 = new Button();
            btn1.Text = "Buttons";
            btn1.Parent = this;
            btn1.Location = new Point(30, 60);
    
            Button btn2 = new Button();
            btn2.Text = "Arent";
            btn2.Parent = this;
            btn2.Location = new Point(30, 90);
            btn2.Anchor = AnchorStyles.Right;
            
            Button btn3 = new Button();
            btn3.Text = "Working";
            btn3.Parent = this;
            btn3.Location = new Point(30, 120);
            btn3.Anchor = AnchorStyles.Right;
    
            toolstripIcon1 = new Bitmap("Resources\\docs.ico");
    
            // MenuStrip
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.option1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.option2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // ToolStrip
            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
            this.toolStripButton2 = new System.Windows.Forms.ToolStripButton();
            this.toolStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // menuStrip1
            // 
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[]
            {
                this.fileToolStripMenuItem,
                this.editToolStripMenuItem,
                this.helpToolStripMenuItem
            });
    
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(600, 24);
            this.menuStrip1.TabIndex = 1;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // fileToolStripMenuItem
            // 
            this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[]
            {
                this.option1ToolStripMenuItem,
                this.option2ToolStripMenuItem
            });
    
            this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
            this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
            this.fileToolStripMenuItem.Text = "File";
            this.fileToolStripMenuItem.Click += new System.EventHandler(this.fileToolStripMenuItem_Click);
            // 
            // editToolStripMenuItem
            // 
            this.editToolStripMenuItem.Name = "editToolStripMenuItem";
            this.editToolStripMenuItem.Size = new System.Drawing.Size(39, 20);
            this.editToolStripMenuItem.Text = "Edit";
            this.editToolStripMenuItem.Click += new System.EventHandler(this.editToolStripMenuItem_Click);
            // 
            // helpToolStripMenuItem
            // 
            this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
            this.helpToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
            this.helpToolStripMenuItem.Text = "Help";
            this.helpToolStripMenuItem.Click += new System.EventHandler(this.helpToolStripMenuItem_Click);
    
            // The sub options for "file"
    
            // 
            // option1ToolStripMenuItem
            // 
            this.option1ToolStripMenuItem.Name = "option1ToolStripMenuItem";
            this.option1ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.option1ToolStripMenuItem.Text = "option1";
            // 
            // option2ToolStripMenuItem
            // 
            this.option2ToolStripMenuItem.Name = "option2ToolStripMenuItem";
            this.option2ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.option2ToolStripMenuItem.Text = "option2";
    
            // End
    
    
            this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripButton1,
            this.toolStripButton2});
    
            this.toolStrip1.Location = new System.Drawing.Point(0, 24);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new System.Drawing.Size(960, 37);
            this.toolStrip1.TabIndex = 0;
            this.toolStrip1.Text = "toolStrip1";
            // 
            // toolStripButton1
            // 
            this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripButton1.Image = ((System.Drawing.Image)(toolstripIcon1));
            this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButton1.Name = "toolStripButton1";
            this.toolStripButton1.Size = new System.Drawing.Size(32, 32);
            this.toolStripButton1.Text = "toolStripButton1";
            // 
            // toolStripButton2
            // 
            this.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripButton2.Image = ((System.Drawing.Image)(toolstripIcon1));
            this.toolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButton2.Name = "toolStripButton2";
            this.toolStripButton2.Size = new System.Drawing.Size(32, 32);
            this.toolStripButton2.Text = "toolStripButton2";
    
    
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(600, 262);
            this.Controls.Add(this.toolStrip1);
            this.Controls.Add(this.menuStrip1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();
    
            //CenterToScreen();
        }
    
        private void fileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // clicked
    		/*
    		
    		this.Close();
    		*/
        }
        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // clicked
        }
        private void helpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // clicked
        }
    }
    
    
    class Program : Form
    {
        [STAThread]
        static void Main(string[] args)
        {
            Console.Title = "some console application";
            Console.WriteLine("Some text in console window"); // Error: handle is invalid
             
            //from string literal and string concatenation
            string fname, lname;
            fname = "Application\tVersion:\t"; // Error: handle is invalid
            lname = "0.01 Pre-Alpha";

  • #5
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,758
    Thanks
    41
    Thanked 191 Times in 190 Posts
    Do a build (F6) instead of a debug (F5)... Build's ok but broken runtime- doesn't build ok compile and there should be an error output.

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #6
    New Coder
    Join Date
    Aug 2013
    Posts
    36
    Thanks
    1
    Thanked 6 Times in 6 Posts
    I am no expert in Win32 internals but I guess since there is no console in a forms application weird things happen when you set the Title or call WriteLine. Why do you want to write to the console in a forms application anyway?

  • #7
    New to the CF scene
    Join Date
    Aug 2014
    Location
    Sweden
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, there is a console created when i run it on windows rt and i was thinking about printing log messages to the console window

  • #8
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,758
    Thanks
    41
    Thanked 191 Times in 190 Posts
    Quote Originally Posted by Hexile View Post
    Actually, there is a console created when i run it on windows rt and i was thinking about printing log messages to the console window
    Doesn't make it right. Pointless topic though to debate as you're going to do what you're going to do. FWIW (as I've never really tried to do that) it doesn't work on Win7 (did a test dummy build). It also doesn't break, just nothing happens/displays.

    Reiterate this question though....

    Not able to COMPILE? Or not able to execute code? An invalid handle sounds like a run-time error, not a compilation error. And it's not clear to me how a handle would ever be involved in string methods.
    Do a build (F6) instead of a debug (F5)... Build's ok but broken runtime- doesn't build ok compile and there should be an error output.
    ie we can't help you until we know what the problem is...

    this is also confusing
    I get errors in vs2012 saying "The handle is invalid" on string and console related functions
    when paired with this

    I didn't see if it was at compile time or at runtime since I was never presented with the UI.
    Can you elaborate? Since you are doing different OS than many would be coding against we REALLY need as many details as possible. What line breaks? What are the errors verbatim from visual studio. If there are none, throw a break point on
    Code:
            [STAThread]
            static void Main() // here for break point
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
    and step through and find what piece of code exactly breaks. The more details, the more help.

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #9
    New to the CF scene
    Join Date
    Aug 2014
    Location
    Sweden
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorted.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •