Comments (7)
Thanks for reporting. The char
type referenced in the DevicePath
field is causing .NET Framework to consider SP_DEVICE_INTERFACE_DETAIL_DATA_W
to be a managed type. Changing it to ushort
gets it to work. I'll investigate what the best fix is for CsWin32 here.
from cswin32.
The char type referenced in the DevicePath field is causing .NET Framework to consider SP_DEVICE_INTERFACE_DETAIL_DATA_W to be a managed type
A nit on this statement. The concept of "managed" or "unmanaged" is historically a C# ism and not defined by the runtime. The runtime deals with the terms blittable and non-blittable. In .NET the bool
and char
primitives are non-blittable but are considered "unmanaged" by C#. This is friction we are slowly trying to fix in .NET 7+, it will be a long process.
@tannergooding @AaronRobinsonMSFT do you have any ideas here?
Using short
, as you discovered, is what I would recommend.
from cswin32.
I tested this and it appeared to work. I think it would be safe.
-internal global::Windows.Win32.VariableLengthInlineArray<char> DevicePath;
+internal global::Windows.Win32.VariableLengthInlineArray<char, ushort> DevicePath;
and
- internal struct VariableLengthInlineArray<T>
+ internal struct VariableLengthInlineArray<T, T2>
where T : unmanaged
+where T2 : unmanaged
{
- internal T e0;
+ internal T2 e0;
internal unsafe ref T this[int index]
{
[UnscopedRef]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => ref Unsafe.Add(ref this.e0, index);
+ get => ref Unsafe.Add(ref Unsafe.AsRef<T>(Unsafe.AsPointer(ref this.e0)), index);
}
This works by changing the field from char
to ushort
, while still presenting almost the same char
based API. In fact we could probably change the field e0
itself to private
and add a ref T
property getter to even present char
there.
@tannergooding @AaronRobinsonMSFT do you have any ideas here?
from cswin32.
In .NET the bool and char primitives are non-blittable
@AaronRobinsonMSFT Do you mean in .NET Framework? .NET 8 didn't throw an exception in the OP's repro -- only .NET Framework did. That seems to suggest that .NET 8 considers char
to be blittable.
from cswin32.
.NET 8 didn't throw an exception in the OP's repro -- only .NET Framework did. That seems to suggest that .NET 8 considers char to be blittable.
Hmmm. That is surprising. Are you using DisableRuntimeMarshalling
?
from cswin32.
No.
from cswin32.
Hmmm. That is surprising. Are you using
DisableRuntimeMarshalling
?
I can confirm that it will not throw when the [assembly: DisableRuntimeMarshalling]
present in .NET 8
from cswin32.
Related Issues (20)
- APPBARDATA should compile on AnyCPU HOT 2
- CsWin32 should avoid Unsafe.SkipInit when it doesn't exist in the compilation HOT 1
- WlanOpenHandle doesn't support SafeHandle HOT 1
- The API "Gdi32" is ambiguous HOT 4
- Add `GET_WHEEL_DELTA_WPARAM` macro
- `TASKDIALOGCONFIG.pfCallback` should use associated enum for `msg` parameter
- Broken `VariableLengthInlineArray<T>` after upgrade from 0.3.49-beta to 0.3.106 HOT 8
- NetFramework - Unsafe.SkipInit(out T value) unavailable HOT 3
- Inconsistent const in parameters of RmRegisterResources HOT 9
- LocalExternFunctions should use `DefaultDllImportSearchPaths`
- Code Quality: Use `WinMdRoot` instead of `winmdroot` to supress CS8981 (type name is ASCII lowercase only) HOT 5
- `PCWSTR` is not marked with `[GeneratedCode]`
- Many Win32 structs (HDC, HMONITOR, etc.) lack the IntPtr conversion operator.
- "Pointers cannot reference marshaled structures. Use ByRef instead" caused by VariableLengthInlineArray
- Latest WDK metadata fails to create DEVPKEY field
- Daily nuget feed not updating HOT 1
- MFTEnumEx signature incorrect
- `VirtualFreeEx` missing HOT 1
- Missing NtCreateThread and NtCreateThreadEx functions HOT 1
- Add an analyzer to catch inadvertent ephemeral delegates HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cswin32.