用Windows的API GetPrivateProfileXXXX/WritePrivateProfileXXXX

解决方案 »

  1.   

    没有去创建控制台程式了,楼主自己调整成控制台或者WinForm就OK了
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.IO;
    using System.Runtime.InteropServices;namespace CallWebService
    {
        public partial class _Default : System.Web.UI.Page
        {
            [DllImport("Kernel32.DLL", EntryPoint = "WritePrivateProfileStringW", SetLastError = true,
             CharSet = CharSet.Unicode, ExactSpelling = true,
             CallingConvention = CallingConvention.StdCall)]
            public static extern IntPtr WritePrivateProfileStringW(
                string lpApplicationName
                , string lpKeyName
                , string lpString
                , string lpFileName);        protected void Page_Load(object sender, EventArgs e)
            {
                CreateINIFile();
            }
           private void CreateINIFile()
           {
               string FilePath = MapPath(".") + @"\1.ini";
               File.WriteAllText(FilePath, string.Empty, System.Text.Encoding.Unicode); //<--确定创建的是UNICODE文件
               int ret = 0;
               ret = (int)WritePrivateProfileStringW("haha", "測試测试", "測試测试", FilePath);
           }
        }
    }
      

  2.   

    Lost_Painting 哥们说的不错,可以生成UNICODE模式,我发现一个文个内容为I P = 1 9 2 . 1 6 8 . 5 . 1  U S E R N A M E = s a  P A S S W O R D = 1 2 3  每个字符后面有一空格,汉字后没有空格,也就是每个字符和汉字占同样的空间,是怎么回事?
     
     
     
     
      

  3.   

    API有ANSI和Unicoed两个版本的,后缀为W的为Unicode版
      

  4.   

    多谢jiangsheng!我在看别人生成的文件时发现其内容I P = 1 9 2 . 1 6 8 . 5 . 1  U S E R N A M E = s a  P A S S W O R D = 1 2 3  这只是其中一部分内容.每个字符后面有一空格,汉字后没有空格,也就是每个字符和汉字占同样的空间,是怎么回事?