using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
    class Program
    {
        [DllImport("kernel32.dll")]
        public static extern uint DeleteFile(string fileName);
        [DllImport("kernel32.dll")]
        public static extern uint GetLastError();
        [DllImport("kernel32.dll")]
        public static extern uint FormatMessage(uint dwFlag, ref IntPtr source, uint messageId, uint languageId, ref string lpBuffer, uint size, ref IntPtr va_list);
        static void Main(string[] args)
        {
            string str = null;
            IntPtr tempptr = IntPtr.Zero;
            if (DeleteFile("C:\test.txt") != 0)
                Console.Write("删除成功!");
            else{
                FormatMessage(0x1300, ref tempptr, GetLastError(), 0, ref str, 0, ref tempptr);
                Console.Write("删除失败!\n失败原因:" + str);
            }
        }
    }
}

 

相关文章:

  • 2022-01-20
  • 2021-10-17
  • 2021-10-31
  • 2022-12-23
  • 2021-05-18
猜你喜欢
  • 2021-05-15
  • 2022-01-11
  • 2022-02-21
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
相关资源
相似解决方案