โ P/Invoked DeviceIoControl() works in C++ but does nothing in C#.
Code is attached.
I have scoured this for hours upon hours and cross checked the pointers with the working C++ version and everything matches. The call doesn't error, checking LastWin32Error, LastSystemError and LastPInvokeError all return "The operation completed successfully." and the return length of the data retrieved is the same in C# as it is in C++, even checked in ProcMon that both apps were making the same system calls and they are. The call happens successfully as it should, but zero data is retrieved in the C# version.
I'm at my wits end here.
74 Replies
are you sure the
STORAGE_PROTOCOL_DATA_DESCRIPTOR_EXT
definition is correct?
it's defined as
and to my knowledge, ULONG
is uint
?which should be uint ๐
fuck me if it's really that simple
it's not referenced ๐คจ
i'll try it tho
the size matters still, i would assume
ah
the entire struct isn't
yeah i don't think it's used. it's used in other example code so i added the definition but it never gets touched
and yeah, still no data
good eye though!
is there some tutorial you pulled this from?
Working with NVMe drives - Win32 apps
Learn how to work with high-speed NVMe devices from your Windows application.
hm, i've been trying to get it to work myself, but i get
ERROR_NOT_SUPPORTED
on DeviceIoControl
and i have like 2 nvme drivesis the drive letter right
sure
it's hard coded to C
tried both C and D
that's not c or d but you get it
oh, was it still on E?
eh
my home m.2 is E, the pc i'm on right now is C
i have 3 drives in my PC, C and D are m.2s
what are you calling to get the error?
๐ง
i ripped out error checking for a minimal repro, but i'm pretty sure that exact check was in there
hang on
this is how i had it, and it doesn't hit the two "not valid" writes and the 3 calls at the end are all "The operation completed successfully"
do you have crystal disk info?
i guess i can get it real quick
i'm curious if your drives don't show that feature
thank god it's on winget
C and D
whoops, that's E and C
why is it sorted like that
who knows lol
windows probably reports them backwards
c and d are the same
so it's supported
what's the device handle?
how do you mean?
if it's valid or not?
ye
sure is
not sure why yours errors and mine doesn't
let me just toss these GetLastError calls everywhere rq
why bother, Win32Exception does that lol
it's just a few copy pastes
still no errors
but no data
not sure if there's somethinng wrong
what if you yeet the exception calls
the c++ version i have hits those errors but still gets the right data
SMART/Health Information Log Data - Temperature 4294967023
about rightdamn
that just means both are zero
it should be in the realm 40
is your F drive an nvme?
doesn't work with C or D either
F is an external ssd
also has SMART
an external wouldn't be nvme though
i don't even know what nvme means hoenstly lol
this is a command specific to nvme drives. smart data on other drives is elsewhere
this is an nvme drive
yeah i got a 980pro i think?
๐
cdi would say if it's nvme in the interface
says nvme on my external lol
๐
wild
idk then
weird!
i can't even get it to work on mine, no chance i can get it to work on yours ๐
if i sent the compiled exe would you mind running it? it needs to be run as admin and it might get flagged as a trojan (it did when i downloaded it at home yesterday)
i'm not running someone else's exe lol
upload the source code and i'll build it
completely understandable
same thing
er, sorry, same thing as you
gotcha
i'm chalking this whole thing up to a windows bug but mtreit disagrees despite not wanting to help ๐
is the goal of the code just to get the drive's temperature?
it's to get all of this
the temp's just what's in the example and if it gets the temp right, it gets everything right, in theory
hypothetically it can be extrapolated to get detailed error logs as well, but i tried using a precompiled c++ app that supposedly retrieved them using these calls and not even that worked so idk
If it was a Windows bug your C++ code would not work.
you don't think there could be an interop bug going on?
What feature of Windows do you think is involved there?
If there was some kind of interop bug that would be a .NET issue. Not a Windows issue.
distinction without a difference imo
.NET is a feature of Windows, it is built-in
.NET Framework is.
.NET is not.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.