שיתוף | קוד #C לזיהוי גרסת Videoff המותקנת במחשב
-
הקוד הבא מחזיר את גרסת הדרייבר של videoff המותקנת במחשב.
public static class VideoffDetector { private const string VideoffPortName = "\\msdtghPort"; public static bool TryGetVersion(out int? version) { return TryGetVersionByCommunicationPort(out version); } private static bool TryGetVersionByCommunicationPort(out int? version) { version = null; var hResult = FltLib.FilterConnectCommunicationPort(VideoffPortName, 0, 0, 0, 0, out var hPort); if (hResult != 0) { return false; } try { var input = BitConverter.GetBytes(1); var output = new byte[4]; hResult = FltLib.FilterSendMessage(hPort, input, output); if (hResult != 0) { return false; } version = BitConverter.ToInt32(output); return true; } finally { Kernel32.CloseHandle(hPort); } } } internal static partial class FltLib { private const string LibraryName = "FltLib"; [LibraryImport(LibraryName, StringMarshalling = StringMarshalling.Utf16)] public static partial int FilterConnectCommunicationPort(string lpPortName, int dwOptions, nint lpContext, short wSizeOfContext, nint lpSecurityAttributes, out nint hPort); [LibraryImport(LibraryName, EntryPoint = "FilterSendMessage")] public static partial int FilterSendMessage(nint hPort, ReadOnlySpan<byte> lpInBuffer, int dwInBufferSize, ReadOnlySpan<byte> lpOutBuffer, int dwOutBufferSize, out uint lpBytesReturned); public static int FilterSendMessage(nint hPort, ReadOnlySpan<byte> lpInBuffer, ReadOnlySpan<byte> lpOutBuffer) { return FilterSendMessage(hPort, lpInBuffer, lpInBuffer.Length, lpOutBuffer, lpOutBuffer.Length, out _); } } internal static partial class Kernel32 { private const string LibraryName = "Kernel32"; [LibraryImport(LibraryName)] [return: MarshalAs(UnmanagedType.Bool)] public static partial bool CloseHandle(nint hObject); }