ソースを参照

添加DllInvoke(未测试)

yuzhengyang 8 年 前
コミット
9412c9cdf7

+ 14 - 3
Fork.Net/Y.Utils/DataUtils/DateTimeUtils/WeekDayTool.cs

@@ -1,13 +1,24 @@
-//############################################################
+//************************************************************************
 //      https://github.com/yuzhengyang
-//      author:yuzhengyang
-//############################################################
+//      author:     yuzhengyang
+//      date:       2017.3.29 - 2017.7.24
+//      desc:       日期转换周
+//      Copyright (c) yuzhengyang. All rights reserved.
+//************************************************************************
 using System;
 
 namespace Y.Utils.DataUtils.DateTimeUtils
 {
+    /// <summary>
+    /// 日期转换周
+    /// </summary>
     public class WeekDayTool
     {
+        /// <summary>
+        /// 显示日期为周几
+        /// </summary>
+        /// <param name="date"></param>
+        /// <returns></returns>
         public static string ToWeekDay(DateTime date)
         {
             string result = "";

+ 33 - 0
Fork.Net/Y.Utils/DllUtils/DllInvokeTool.cs

@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace Y.Utils.DllUtils
+{
+    public class DllInvokeTool
+    {
+        [DllImport("kernel32.dll")]
+        private extern static IntPtr LoadLibrary(String path);
+        [DllImport("kernel32.dll")]
+        private extern static IntPtr GetProcAddress(IntPtr lib, String funcName);
+        [DllImport("kernel32.dll")]
+        private extern static bool FreeLibrary(IntPtr lib);
+        private IntPtr hLib;
+        public DllInvokeTool(String DLLPath)
+        {
+            hLib = LoadLibrary(DLLPath);
+        }
+        ~DllInvokeTool()
+        {
+            FreeLibrary(hLib);
+        }
+        //将要执行的函数转换为委托 
+        public Delegate Invoke(String APIName, Type t)
+        {
+            IntPtr api = GetProcAddress(hLib, APIName);
+            return (Delegate)Marshal.GetDelegateForFunctionPointer(api, t);
+        }
+    }
+}

+ 1 - 0
Fork.Net/Y.Utils/Y.Utils.csproj

@@ -56,6 +56,7 @@
     <Compile Include="DataUtils\StringUtils\NumberStringTool.cs" />
     <Compile Include="DelegateUtils\ProgressDelegate.cs" />
     <Compile Include="DelegateUtils\ProgressEventArgs.cs" />
+    <Compile Include="DllUtils\DllInvokeTool.cs" />
     <Compile Include="DrawUtils\ColorUtils\ColorPalette.cs" />
     <Compile Include="DrawUtils\ColorUtils\ColorStyle.cs" />
     <Compile Include="DrawUtils\ColorUtils\ColorTool.cs" />