From ba6e3bf25332a7a41c679c1bde48577ea0312b6b Mon Sep 17 00:00:00 2001 From: LORDofDOOM Date: Mon, 13 Nov 2017 23:20:14 +0100 Subject: [PATCH] [Core] netstandard support, drop PInvokeDelegateFactory and replace with direct dll calls in ADL.cs, NVAPI.cs, FTD2XX.cs, create project and solution file for netstandard, add compiler option in KernelDriver.cs and Ring0.cs - These options are not required for library mode. netstandard is not default for library - If compiled as usual anything works as in previous versions --- Hardware/ATI/ADL.cs | 171 +++++------------------ Hardware/KernelDriver.cs | 4 +- Hardware/Nvidia/NVAPI.cs | 19 +-- Hardware/PInvokeDelegateFactory.cs | 82 ----------- Hardware/Ring0.cs | 6 +- Hardware/TBalancer/FTD2XX.cs | 108 ++++---------- OpenHardwareMonitorLib.csproj | 1 - OpenHardwareMonitorLibNetStandard.csproj | 117 ++++++++++++++++ OpenHardwareMonitorLibNetStandard.sln | 57 ++++++++ 9 files changed, 255 insertions(+), 310 deletions(-) delete mode 100644 Hardware/PInvokeDelegateFactory.cs create mode 100644 OpenHardwareMonitorLibNetStandard.csproj create mode 100644 OpenHardwareMonitorLibNetStandard.sln diff --git a/Hardware/ATI/ADL.cs b/Hardware/ATI/ADL.cs index 51f14f2..fe25f76 100644 --- a/Hardware/ATI/ADL.cs +++ b/Hardware/ATI/ADL.cs @@ -100,125 +100,40 @@ namespace OpenHardwareMonitor.Hardware.ATI { public const int ATI_VENDOR_ID = 0x1002; - private delegate int ADL_Main_Control_CreateDelegate( - ADL_Main_Memory_AllocDelegate callback, int enumConnectedAdapters); - private delegate int ADL_Adapter_AdapterInfo_GetDelegate(IntPtr info, - int size); - - public delegate int ADL_Main_Control_DestroyDelegate(); - public delegate int ADL_Adapter_NumberOfAdapters_GetDelegate( - ref int numAdapters); - public delegate int ADL_Adapter_ID_GetDelegate(int adapterIndex, - out int adapterID); - public delegate int ADL_Display_AdapterID_GetDelegate(int adapterIndex, - out int adapterID); - public delegate int ADL_Adapter_Active_GetDelegate(int adapterIndex, - out int status); - public delegate int ADL_Overdrive5_CurrentActivity_GetDelegate( - int iAdapterIndex, ref ADLPMActivity activity); - public delegate int ADL_Overdrive5_Temperature_GetDelegate(int adapterIndex, - int thermalControllerIndex, ref ADLTemperature temperature); - public delegate int ADL_Overdrive5_FanSpeed_GetDelegate(int adapterIndex, - int thermalControllerIndex, ref ADLFanSpeedValue fanSpeedValue); - public delegate int ADL_Overdrive5_FanSpeedInfo_GetDelegate( - int adapterIndex, int thermalControllerIndex, - ref ADLFanSpeedInfo fanSpeedInfo); - public delegate int ADL_Overdrive5_FanSpeedToDefault_SetDelegate( - int adapterIndex, int thermalControllerIndex); - public delegate int ADL_Overdrive5_FanSpeed_SetDelegate(int adapterIndex, - int thermalControllerIndex, ref ADLFanSpeedValue fanSpeedValue); - - private static ADL_Main_Control_CreateDelegate - _ADL_Main_Control_Create; - private static ADL_Adapter_AdapterInfo_GetDelegate - _ADL_Adapter_AdapterInfo_Get; - - public static ADL_Main_Control_DestroyDelegate - ADL_Main_Control_Destroy; - public static ADL_Adapter_NumberOfAdapters_GetDelegate - ADL_Adapter_NumberOfAdapters_Get; - public static ADL_Adapter_ID_GetDelegate - _ADL_Adapter_ID_Get; - public static ADL_Display_AdapterID_GetDelegate - _ADL_Display_AdapterID_Get; - public static ADL_Adapter_Active_GetDelegate - ADL_Adapter_Active_Get; - public static ADL_Overdrive5_CurrentActivity_GetDelegate - ADL_Overdrive5_CurrentActivity_Get; - public static ADL_Overdrive5_Temperature_GetDelegate - ADL_Overdrive5_Temperature_Get; - public static ADL_Overdrive5_FanSpeed_GetDelegate - ADL_Overdrive5_FanSpeed_Get; - public static ADL_Overdrive5_FanSpeedInfo_GetDelegate - ADL_Overdrive5_FanSpeedInfo_Get; - public static ADL_Overdrive5_FanSpeedToDefault_SetDelegate - ADL_Overdrive5_FanSpeedToDefault_Set; - public static ADL_Overdrive5_FanSpeed_SetDelegate - ADL_Overdrive5_FanSpeed_Set; - - private static string dllName; - - private static void GetDelegate(string entryPoint, out T newDelegate) - where T : class - { - DllImportAttribute attribute = new DllImportAttribute(dllName); - attribute.CallingConvention = CallingConvention.Cdecl; - attribute.PreserveSig = true; - attribute.EntryPoint = entryPoint; - PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate); - } - - private static void CreateDelegates(string name) { - int p = (int)Environment.OSVersion.Platform; - if ((p == 4) || (p == 128)) - dllName = name + ".so"; - else - dllName = name + ".dll"; - - GetDelegate("ADL_Main_Control_Create", - out _ADL_Main_Control_Create); - GetDelegate("ADL_Adapter_AdapterInfo_Get", - out _ADL_Adapter_AdapterInfo_Get); - GetDelegate("ADL_Main_Control_Destroy", - out ADL_Main_Control_Destroy); - GetDelegate("ADL_Adapter_NumberOfAdapters_Get", - out ADL_Adapter_NumberOfAdapters_Get); - GetDelegate("ADL_Adapter_ID_Get", - out _ADL_Adapter_ID_Get); - GetDelegate("ADL_Display_AdapterID_Get", - out _ADL_Display_AdapterID_Get); - GetDelegate("ADL_Adapter_Active_Get", - out ADL_Adapter_Active_Get); - GetDelegate("ADL_Overdrive5_CurrentActivity_Get", - out ADL_Overdrive5_CurrentActivity_Get); - GetDelegate("ADL_Overdrive5_Temperature_Get", - out ADL_Overdrive5_Temperature_Get); - GetDelegate("ADL_Overdrive5_FanSpeed_Get", - out ADL_Overdrive5_FanSpeed_Get); - GetDelegate("ADL_Overdrive5_FanSpeedInfo_Get", - out ADL_Overdrive5_FanSpeedInfo_Get); - GetDelegate("ADL_Overdrive5_FanSpeedToDefault_Set", - out ADL_Overdrive5_FanSpeedToDefault_Set); - GetDelegate("ADL_Overdrive5_FanSpeed_Set", - out ADL_Overdrive5_FanSpeed_Set); - } - - static ADL() { - CreateDelegates("atiadlxx"); - } - - private ADL() { } + internal const string Atiadlxx_FileName = "atiadlxx.dll"; + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Main_Control_Create(ADL_Main_Memory_AllocDelegate callback, int enumConnectedAdapters); + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Main_Control_Destroy(); + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Adapter_AdapterInfo_Get(IntPtr info, int size); + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Adapter_NumberOfAdapters_Get(); + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Adapter_NumberOfAdapters_Get(ref int numAdapters); + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Adapter_ID_Get(int adapterIndex, out int adapterID); + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Display_AdapterID_Get(int adapterIndex, out int adapterID); + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Adapter_Active_Get(int adapterIndex, out int status); + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Overdrive5_CurrentActivity_Get(int iAdapterIndex, ref ADLPMActivity activity); + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Overdrive5_Temperature_Get(int adapterIndex, int thermalControllerIndex, ref ADLTemperature temperature); + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Overdrive5_FanSpeed_Get(int adapterIndex, int thermalControllerIndex, ref ADLFanSpeedValue fanSpeedValue); + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Overdrive5_FanSpeedInfo_Get(int adapterIndex, int thermalControllerIndex, ref ADLFanSpeedInfo fanSpeedInfo); + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Overdrive5_FanSpeedToDefault_Set(int adapterIndex, int thermalControllerIndex); + [DllImport(Atiadlxx_FileName, CallingConvention = CallingConvention.Cdecl)] + public static extern int ADL_Overdrive5_FanSpeed_Set(int adapterIndex, int thermalControllerIndex, ref ADLFanSpeedValue fanSpeedValue); public static int ADL_Main_Control_Create(int enumConnectedAdapters) { try { - try { - return _ADL_Main_Control_Create(Main_Memory_Alloc, - enumConnectedAdapters); - } catch { - CreateDelegates("atiadlxy"); - return _ADL_Main_Control_Create(Main_Memory_Alloc, - enumConnectedAdapters); - } + return ADL_Main_Control_Create(Main_Memory_Alloc, + enumConnectedAdapters); } catch { return ADL_ERR; } @@ -228,7 +143,7 @@ namespace OpenHardwareMonitor.Hardware.ATI { int elementSize = Marshal.SizeOf(typeof(ADLAdapterInfo)); int size = info.Length * elementSize; IntPtr ptr = Marshal.AllocHGlobal(size); - int result = _ADL_Adapter_AdapterInfo_Get(ptr, size); + int result = ADL_Adapter_AdapterInfo_Get(ptr, size); for (int i = 0; i < info.Length; i++) info[i] = (ADLAdapterInfo) Marshal.PtrToStructure((IntPtr)((long)ptr + i * elementSize), @@ -254,29 +169,15 @@ namespace OpenHardwareMonitor.Hardware.ATI { return result; } - public static int ADL_Adapter_ID_Get(int adapterIndex, - out int adapterID) { - try { - return _ADL_Adapter_ID_Get(adapterIndex, out adapterID); - } catch (EntryPointNotFoundException) { - try { - return _ADL_Display_AdapterID_Get(adapterIndex, out adapterID); - } catch (EntryPointNotFoundException) { - adapterID = 1; - return ADL_OK; - } - } - } + public delegate IntPtr ADL_Main_Memory_AllocDelegate(int size); - private delegate IntPtr ADL_Main_Memory_AllocDelegate(int size); - - // create a Main_Memory_Alloc delegate and keep it alive - private static ADL_Main_Memory_AllocDelegate Main_Memory_Alloc = + // create a Main_Memory_Alloc delegate and keep it alive + public static ADL_Main_Memory_AllocDelegate Main_Memory_Alloc = delegate(int size) { return Marshal.AllocHGlobal(size); }; - private static void Main_Memory_Free(IntPtr buffer) { + public static void Main_Memory_Free(IntPtr buffer) { if (IntPtr.Zero != buffer) Marshal.FreeHGlobal(buffer); } diff --git a/Hardware/KernelDriver.cs b/Hardware/KernelDriver.cs index 6225b0e..1f39bec 100644 --- a/Hardware/KernelDriver.cs +++ b/Hardware/KernelDriver.cs @@ -64,7 +64,8 @@ namespace OpenHardwareMonitor.Hardware { NativeMethods.CloseServiceHandle(service); NativeMethods.CloseServiceHandle(manager); - + +#if !NETSTANDARD2_0 try { // restrict the driver access to system (SY) and builtin admins (BA) // TODO: replace with a call to IoCreateDeviceSecure in the driver @@ -77,6 +78,7 @@ namespace OpenHardwareMonitor.Hardware { errorMessage = null; return true; } +#endif public bool Open() { device = new SafeFileHandle(NativeMethods.CreateFile(@"\\.\" + id, diff --git a/Hardware/Nvidia/NVAPI.cs b/Hardware/Nvidia/NVAPI.cs index 7a4104b..3d9de45 100644 --- a/Hardware/Nvidia/NVAPI.cs +++ b/Hardware/Nvidia/NVAPI.cs @@ -277,7 +277,7 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { out uint revisionId, out uint extDeviceId); private static readonly bool available; - private static readonly nvapi_QueryInterfaceDelegate nvapi_QueryInterface; + [DllImport(@"nvapi.dll", EntryPoint = @"nvapi_QueryInterface", CallingConvention = CallingConvention.Cdecl, PreserveSig = true)] private static extern IntPtr NvAPI32_QueryInterface(uint interfaceId); [DllImport(@"nvapi64.dll", EntryPoint = @"nvapi_QueryInterface", CallingConvention = CallingConvention.Cdecl, PreserveSig = true)] private static extern IntPtr NvAPI64_QueryInterface(uint interfaceId); private static readonly NvAPI_InitializeDelegate NvAPI_Initialize; private static readonly NvAPI_GPU_GetFullNameDelegate _NvAPI_GPU_GetFullName; @@ -346,7 +346,15 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { private static void GetDelegate(uint id, out T newDelegate) where T : class { - IntPtr ptr = nvapi_QueryInterface(id); + IntPtr ptr; + if (IntPtr.Size == 4) + { + ptr = NvAPI32_QueryInterface(id); + } + else + { + ptr = NvAPI64_QueryInterface(id); + } if (ptr != IntPtr.Zero) { newDelegate = Marshal.GetDelegateForFunctionPointer(ptr, typeof(T)) as T; @@ -356,13 +364,6 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { } static NVAPI() { - DllImportAttribute attribute = new DllImportAttribute(GetDllName()); - attribute.CallingConvention = CallingConvention.Cdecl; - attribute.PreserveSig = true; - attribute.EntryPoint = "nvapi_QueryInterface"; - PInvokeDelegateFactory.CreateDelegate(attribute, - out nvapi_QueryInterface); - try { GetDelegate(0x0150E828, out NvAPI_Initialize); } catch (DllNotFoundException) { return; } diff --git a/Hardware/PInvokeDelegateFactory.cs b/Hardware/PInvokeDelegateFactory.cs deleted file mode 100644 index 88b05f5..0000000 --- a/Hardware/PInvokeDelegateFactory.cs +++ /dev/null @@ -1,82 +0,0 @@ -/* - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - - Copyright (C) 2009-2012 Michael Möller - -*/ - -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Reflection.Emit; -using System.Runtime.InteropServices; -using OpenHardwareMonitor.Collections; - -namespace OpenHardwareMonitor.Hardware { - - internal static class PInvokeDelegateFactory { - - private static readonly ModuleBuilder moduleBuilder = - AppDomain.CurrentDomain.DefineDynamicAssembly( - new AssemblyName("PInvokeDelegateFactoryInternalAssembly"), - AssemblyBuilderAccess.Run).DefineDynamicModule( - "PInvokeDelegateFactoryInternalModule"); - - private static readonly IDictionary, Type> wrapperTypes = - new Dictionary, Type>(); - - public static void CreateDelegate(DllImportAttribute dllImportAttribute, - out T newDelegate) where T : class - { - Type wrapperType; - Pair key = - new Pair(dllImportAttribute, typeof(T)); - wrapperTypes.TryGetValue(key, out wrapperType); - - if (wrapperType == null) { - wrapperType = CreateWrapperType(typeof(T), dllImportAttribute); - wrapperTypes.Add(key, wrapperType); - } - - newDelegate = Delegate.CreateDelegate(typeof(T), wrapperType, - dllImportAttribute.EntryPoint) as T; - } - - - private static Type CreateWrapperType(Type delegateType, - DllImportAttribute dllImportAttribute) { - - TypeBuilder typeBuilder = moduleBuilder.DefineType( - "PInvokeDelegateFactoryInternalWrapperType" + wrapperTypes.Count); - - MethodInfo methodInfo = delegateType.GetMethod("Invoke"); - - ParameterInfo[] parameterInfos = methodInfo.GetParameters(); - int parameterCount = parameterInfos.GetLength(0); - - Type[] parameterTypes = new Type[parameterCount]; - for (int i = 0; i < parameterCount; i++) - parameterTypes[i] = parameterInfos[i].ParameterType; - - MethodBuilder methodBuilder = typeBuilder.DefinePInvokeMethod( - dllImportAttribute.EntryPoint, dllImportAttribute.Value, - MethodAttributes.Public | MethodAttributes.Static | - MethodAttributes.PinvokeImpl, CallingConventions.Standard, - methodInfo.ReturnType, parameterTypes, - dllImportAttribute.CallingConvention, - dllImportAttribute.CharSet); - - foreach (ParameterInfo parameterInfo in parameterInfos) - methodBuilder.DefineParameter(parameterInfo.Position + 1, - parameterInfo.Attributes, parameterInfo.Name); - - if (dllImportAttribute.PreserveSig) - methodBuilder.SetImplementationFlags(MethodImplAttributes.PreserveSig); - - return typeBuilder.CreateType(); - } - } -} diff --git a/Hardware/Ring0.cs b/Hardware/Ring0.cs index c506c69..c8524ff 100644 --- a/Hardware/Ring0.cs +++ b/Hardware/Ring0.cs @@ -202,8 +202,12 @@ namespace OpenHardwareMonitor.Hardware { isaBusMutex = new Mutex(false, mutexName); } catch (UnauthorizedAccessException) { try { +#if NETSTANDARD2_0 + isaBusMutex = Mutex.OpenExisting(mutexName); +#else isaBusMutex = Mutex.OpenExisting(mutexName, MutexRights.Synchronize); - } catch { } +#endif + } catch { } } } diff --git a/Hardware/TBalancer/FTD2XX.cs b/Hardware/TBalancer/FTD2XX.cs index c6999ad..aa2fa8e 100644 --- a/Hardware/TBalancer/FTD2XX.cs +++ b/Hardware/TBalancer/FTD2XX.cs @@ -78,69 +78,33 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { internal class FTD2XX { - public delegate FT_STATUS FT_CreateDeviceInfoListDelegate( - out uint numDevices); - public delegate FT_STATUS FT_GetDeviceInfoListDelegate( - [Out] FT_DEVICE_INFO_NODE[] deviceInfoNodes, ref uint length); - public delegate FT_STATUS FT_OpenDelegate(int device, out FT_HANDLE handle); - public delegate FT_STATUS FT_CloseDelegate(FT_HANDLE handle); - public delegate FT_STATUS FT_SetBaudRateDelegate(FT_HANDLE handle, - uint baudRate); - public delegate FT_STATUS FT_SetDataCharacteristicsDelegate( - FT_HANDLE handle, byte wordLength, byte stopBits, byte parity); - public delegate FT_STATUS FT_SetFlowControlDelegate(FT_HANDLE handle, - FT_FLOW_CONTROL flowControl, byte xon, byte xoff); - public delegate FT_STATUS FT_SetTimeoutsDelegate(FT_HANDLE handle, - uint readTimeout, uint writeTimeout); - public delegate FT_STATUS FT_WriteDelegate(FT_HANDLE handle, byte[] buffer, - uint bytesToWrite, out uint bytesWritten); - public delegate FT_STATUS FT_PurgeDelegate(FT_HANDLE handle, FT_PURGE mask); - public delegate FT_STATUS FT_GetStatusDelegate(FT_HANDLE handle, - out uint amountInRxQueue, out uint amountInTxQueue, out uint eventStatus); - public delegate FT_STATUS FT_ReadDelegate(FT_HANDLE handle, - [Out] byte[] buffer, uint bytesToRead, out uint bytesReturned); - public delegate FT_STATUS FT_ReadByteDelegate(FT_HANDLE handle, - out byte buffer, uint bytesToRead, out uint bytesReturned); - - public static readonly FT_CreateDeviceInfoListDelegate - FT_CreateDeviceInfoList = CreateDelegate< - FT_CreateDeviceInfoListDelegate>("FT_CreateDeviceInfoList"); - public static readonly FT_GetDeviceInfoListDelegate - FT_GetDeviceInfoList = CreateDelegate< - FT_GetDeviceInfoListDelegate>("FT_GetDeviceInfoList"); - public static readonly FT_OpenDelegate - FT_Open = CreateDelegate< - FT_OpenDelegate>("FT_Open"); - public static readonly FT_CloseDelegate - FT_Close = CreateDelegate< - FT_CloseDelegate>("FT_Close"); - public static readonly FT_SetBaudRateDelegate - FT_SetBaudRate = CreateDelegate< - FT_SetBaudRateDelegate>("FT_SetBaudRate"); - public static readonly FT_SetDataCharacteristicsDelegate - FT_SetDataCharacteristics = CreateDelegate< - FT_SetDataCharacteristicsDelegate>("FT_SetDataCharacteristics"); - public static readonly FT_SetFlowControlDelegate - FT_SetFlowControl = CreateDelegate< - FT_SetFlowControlDelegate>("FT_SetFlowControl"); - public static readonly FT_SetTimeoutsDelegate - FT_SetTimeouts = CreateDelegate< - FT_SetTimeoutsDelegate>("FT_SetTimeouts"); - public static readonly FT_WriteDelegate - FT_Write = CreateDelegate< - FT_WriteDelegate>("FT_Write"); - public static readonly FT_PurgeDelegate - FT_Purge = CreateDelegate< - FT_PurgeDelegate>("FT_Purge"); - public static readonly FT_GetStatusDelegate - FT_GetStatus = CreateDelegate< - FT_GetStatusDelegate>("FT_GetStatus"); - public static readonly FT_ReadDelegate - FT_Read = CreateDelegate< - FT_ReadDelegate>("FT_Read"); - public static readonly FT_ReadByteDelegate - FT_ReadByte = CreateDelegate< - FT_ReadByteDelegate>("FT_Read"); + private const string FtdAssemblyName = "FTD2XX.dll"; + [DllImport(FtdAssemblyName)] + public static extern FT_STATUS FT_CreateDeviceInfoList(out uint numDevices); + [DllImport(FtdAssemblyName)] + public static extern FT_STATUS FT_GetDeviceInfoList([Out] FT_DEVICE_INFO_NODE[] deviceInfoNodes, ref uint length); + [DllImport(FtdAssemblyName)] + public static extern FT_STATUS FT_Open(int device, out FT_HANDLE handle); + [DllImport(FtdAssemblyName)] + public static extern FT_STATUS FT_Close(FT_HANDLE handle); + [DllImport(FtdAssemblyName)] + public static extern FT_STATUS FT_SetBaudRate(FT_HANDLE handle, uint baudRate); + [DllImport(FtdAssemblyName)] + public static extern FT_STATUS FT_SetDataCharacteristics(FT_HANDLE handle, byte wordLength, byte stopBits, byte parity); + [DllImport(FtdAssemblyName)] + public static extern FT_STATUS FT_SetFlowControl(FT_HANDLE handle, FT_FLOW_CONTROL flowControl, byte xon, byte xoff); + [DllImport(FtdAssemblyName)] + public static extern FT_STATUS FT_SetTimeouts(FT_HANDLE handle, uint readTimeout, uint writeTimeout); + [DllImport(FtdAssemblyName)] + public static extern FT_STATUS FT_Write(FT_HANDLE handle, byte[] buffer, uint bytesToWrite, out uint bytesWritten); + [DllImport(FtdAssemblyName)] + public static extern FT_STATUS FT_Purge(FT_HANDLE handle, FT_PURGE mask); + [DllImport(FtdAssemblyName)] + public static extern FT_STATUS FT_GetStatus(FT_HANDLE handle, out uint amountInRxQueue, out uint amountInTxQueue, out uint eventStatus); + [DllImport(FtdAssemblyName)] + public static extern FT_STATUS FT_Read(FT_HANDLE handle, [Out] byte[] buffer, uint bytesToRead, out uint bytesReturned); + [DllImport(FtdAssemblyName)] + public static extern FT_STATUS FT_ReadByte(FT_HANDLE handle, out byte buffer, uint bytesToRead, out uint bytesReturned); private FTD2XX() { } @@ -183,23 +147,5 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { throw new InvalidOperationException(); } - private static string GetDllName() { - int p = (int)Environment.OSVersion.Platform; - if ((p == 4) || (p == 128)) - return "libftd2xx.so"; - else - return "ftd2xx.dll"; - } - - private static T CreateDelegate(string entryPoint) - where T : class { - DllImportAttribute attribute = new DllImportAttribute(GetDllName()); - attribute.CallingConvention = CallingConvention.StdCall; - attribute.PreserveSig = true; - attribute.EntryPoint = entryPoint; - T newDelegate; - PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate); - return newDelegate; - } } } diff --git a/OpenHardwareMonitorLib.csproj b/OpenHardwareMonitorLib.csproj index fd6bf2f..fcf5908 100644 --- a/OpenHardwareMonitorLib.csproj +++ b/OpenHardwareMonitorLib.csproj @@ -140,7 +140,6 @@ - diff --git a/OpenHardwareMonitorLibNetStandard.csproj b/OpenHardwareMonitorLibNetStandard.csproj new file mode 100644 index 0000000..b4946a6 --- /dev/null +++ b/OpenHardwareMonitorLibNetStandard.csproj @@ -0,0 +1,117 @@ + + + + netstandard2.0 + false + + + + Auto + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OpenHardwareMonitorLibNetStandard.sln b/OpenHardwareMonitorLibNetStandard.sln new file mode 100644 index 0000000..ebbf40f --- /dev/null +++ b/OpenHardwareMonitorLibNetStandard.sln @@ -0,0 +1,57 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenHardwareMonitorLib", "OpenHardwareMonitorLibNetStandard.csproj", "{B0397530-545A-471D-BB74-027AE456DF1A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.Build.0 = Release|Any CPU + {F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Release|Any CPU.Build.0 = Release|Any CPU + {E73BB233-D88B-44A7-A98F-D71EE158381D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E73BB233-D88B-44A7-A98F-D71EE158381D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E73BB233-D88B-44A7-A98F-D71EE158381D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E73BB233-D88B-44A7-A98F-D71EE158381D}.Release|Any CPU.Build.0 = Release|Any CPU + {BCC43E58-E473-403E-A84D-63FEDC723040}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BCC43E58-E473-403E-A84D-63FEDC723040}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BCC43E58-E473-403E-A84D-63FEDC723040}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BCC43E58-E473-403E-A84D-63FEDC723040}.Release|Any CPU.Build.0 = Release|Any CPU + {D4554296-094E-4CAC-8EAE-44EB250666C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D4554296-094E-4CAC-8EAE-44EB250666C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D4554296-094E-4CAC-8EAE-44EB250666C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D4554296-094E-4CAC-8EAE-44EB250666C6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = OpenHardwareMonitor.csproj + Policies = $0 + $0.DotNetNamingPolicy = $1 + $1.DirectoryNamespaceAssociation = None + $1.ResourceNamePolicy = FileFormatDefault + $0.TextStylePolicy = $2 + $2.FileWidth = 120 + $2.TabWidth = 2 + $2.NoTabsAfterNonTabs = True + $2.inheritsSet = VisualStudio + $2.inheritsScope = text/plain + $2.scope = text/plain + $0.TextStylePolicy = $3 + $3.inheritsSet = null + $3.scope = text/x-csharp + $0.CSharpFormattingPolicy = $4 + $4.inheritsSet = Mono + $4.inheritsScope = text/x-csharp + $4.scope = text/x-csharp + EndGlobalSection +EndGlobal