-
-
Save baget/1ee25c2c6607a7797f4f4e3d12c4d05e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<TargetFramework>net5.0-windows10.0.19041</TargetFramework> | |
</PropertyGroup> | |
<PropertyGroup> | |
<CsWinRTIncludes>Contoso</CsWinRTIncludes> | |
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir> | |
<CsWinRTWindowsMetadata>10.0.19041.0</CsWinRTWindowsMetadata> | |
<Nullable>annotations</Nullable> | |
<OutputType>Exe</OutputType> | |
</PropertyGroup> | |
<PropertyGroup> | |
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | |
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.19041.1" /> | |
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="1.1.0" /> | |
<PackageReference Include="System.Runtime.InteropServices.WindowsRuntime" Version="4.3.0" /> | |
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" /> | |
</ItemGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using Windows.Storage.Streams; | |
using System.Runtime.InteropServices.WindowsRuntime; | |
static class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello WinRT"); | |
var guid = new Guid("df964c4d-f0e8-400d-8404-6f140c2a392c"); | |
var deviceSel = Windows.Devices.Custom.CustomDevice.GetDeviceSelector(guid); | |
var devices = Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(deviceSel).GetResults(); | |
var rot13Device = Windows.Devices.Custom.CustomDevice.FromIdAsync(devices[0].Id, | |
Windows.Devices.Custom.DeviceAccessMode.ReadWrite, | |
Windows.Devices.Custom.DeviceSharingMode.Exclusive).GetResults(); | |
const ushort UNKONWN_DEVICE_TYPE = 0x00000022; | |
var ioctl = new Windows.Devices.Custom.IOControlCode(UNKONWN_DEVICE_TYPE, 0x800, Windows.Devices.Custom.IOControlAccessMode.Any, Windows.Devices.Custom.IOControlBufferingMethod.Buffered); | |
String input = "abcxyz"; | |
var dataWriter = new Windows.Storage.Streams.DataWriter(); | |
dataWriter.WriteBytes(System.Text.Encoding.ASCII.GetBytes(input)); | |
uint outSize = (uint)input.Length; | |
var outBuf = new Windows.Storage.Streams.Buffer(outSize); | |
var res = rot13Device.SendIOControlAsync(ioctl, dataWriter.DetachBuffer(), outBuf).GetResults(); | |
var dataReader = DataReader.FromBuffer(outBuf); | |
var str = dataReader.ReadString(outSize); | |
Console.WriteLine(str); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment