using HighWayIot.Log4net;
using HighWayIot.Winform.MainForm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HighWayIot.Winform
{
    internal static class Program
    {
        private static LogHelper logger = LogHelper.Instance;

        [System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError = true)]
        [return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
        public static extern bool AllocConsole();

        [System.Runtime.InteropServices.DllImport("Kernel32")]
        public static extern void FreeConsole();

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {

            //Console.OutputEncoding = System.Text.Encoding.UTF8;
            //Console.InputEncoding = System.Text.Encoding.UTF8;

            try
            {
                AllocConsole();//调用系统API，调用控制台窗口
                               // 设置控制台编码为系统默认编码（解决乱码问题）
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                //创建窗体
                MainForm.MainForm loginform = new MainForm.MainForm();
                logger.Info("程序初始化成功");
                Application.Run(loginform);
                FreeConsole();//释放控制台
            }
            catch(Exception ex)
            {
                logger.Error("程序异常", ex);
            }            
        }
    }
}
