⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class1.cs

📁 C#开发教程 由浅入深 配有实例 是初学者的好帮手
💻 CS
字号:
using System;
using System.Runtime.InteropServices;	// for DllImport

namespace nativeDLL
{
	public class Test
	{
//		[DllImport ("user32.dll")]			// all the defaults are OK
		[DllImport("user32", EntryPoint="MessageBoxA", 
			SetLastError=true, 
			CharSet=CharSet.Ansi, ExactSpelling=true, 
			CallingConvention=CallingConvention.StdCall)]
		public static extern int MessageBoxA (
			int h, string m, string c, int type);

		[StructLayout(LayoutKind.Sequential)]
		public class SystemTime {
			public ushort wYear;
			public ushort wMonth;
			public ushort wDayOfWeek;
			public ushort wDay;
			public ushort wHour;
			public ushort wMinute;
			public ushort wSecond;
			public ushort wMilliseconds;
		}

		[DllImport ("kernel32.dll")]
		public static extern void GetLocalTime(SystemTime st);

		[STAThread]
		public static void Main(string[] args)
		{
			MessageBoxA(0, "Hello World", "nativeDLL", 0);

			SystemTime st = new SystemTime();
			GetLocalTime(st);
			string s = String.Format("date: {0}-{1}-{2}", 
				st.wMonth, st.wDay, st.wYear);
			string t = String.Format("time: {0}:{1}:{2}", 
				st.wHour, st.wMinute, st.wSecond);
			string u = s + ", " + t;

			MessageBoxA(0, u, "Now", 0);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -