Sure, but I have managed to send “a” struct across the divide, so it should be possible. The marshalling provided by C# may be slow, but to mitigate this I want to send more information in one go hence increasing from 1 struct to an array of 50 structs to keep the amount of chatter to a minimum.
Yet a DbgPrint of the AssociatedIrp->SystemBuffer size yields only 4 bytes!
This is what is confusing the heck out of me. This worked like a charm when I was only retrieving one struct.
So the theory is this.
I need a buffer off 200 bytes (which will return an array of 50 ptrs - each ptr points to a struct in the array. Then I can walk the buffer pulling out my structs.
As I say I’m not asking for help with how to unpack the buffer, rather why or how is the driver only getting 4 bytes?
I had this same problem. I had complicated kernel mode structures that I tried to define in C# and just ran into to many issues trying to get marshaling to work correctly. In the end I wrote a DLL in C++ and had my C# app use the DLL so that I could simplify the data exchange. It wasn’t pretty, but it worked. I remember going to a C# forum for help with defining my structure in C# and the advice I got was don’t do it… My app by the way was a c# application talking to a virtual miniport driver and acting like a disk in user mode… don’t try this at home…
What is driving me nuts is, if I have a simple struct, say 40 bytes, it works like a charm.
Forget the complex structs bit, I am going to handle that I’m sure. The question he is, why after I have allocated 200 bytes does the driver only get 4?
As you say your solution aint pretty, and I wouldn’t no where to start (writing the external hooks for c# I mean) and I just feel like there is something obvious here I am missing.
Random thought for the day (I haven’t read this read) - you’re passing
something like sizeof(pointer) v. sizeof(structure).
mm
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.co.uk
Sent: Friday, September 03, 2010 9:31 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] DeviceIO and Array of structs
I know. I understand what you are telling me.
What is driving me nuts is, if I have a simple struct, say 40 bytes, it
works like a charm.
Forget the complex structs bit, I am going to handle that I’m sure. The
question he is, why after I have allocated 200 bytes does the driver only
get 4?
As you say your solution aint pretty, and I wouldn’t no where to start
(writing the external hooks for c# I mean) and I just feel like there is
something obvious here I am missing.
What exactly is the problem? You’re using METHOD_BUFFERED without any INPUT buffer, and the OUTPUT buffer size is being set to exactly what you asked (200).
Your driver should expect to receive a buffer in non-paged pool (the pointer will be at Irp->AssociatedIrp.SystemBuffer) that has random contents and which is at least 200 bytes long. That seems to be exactly what you’re getting.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.co.uk
Sent: Friday, September 03, 2010 9:15 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] DeviceIO and Array of structs
Thanks Peter
>1) Please post the definition of the control code that you’re using
>(the
CTL_CODE macro, please)
internal static uint METHOD_BUFFERED = 0;
internal static uint FILE_ANY_ACCESS = 0;
internal static uint SIOCTL_TYPE = 40000; internal static uint
IOCTL_REGISTER_EVENT = ((SIOCTL_TYPE) \<\< 16) | ((FILE_ANY_ACCESS) \<\< 14) |
((0x906) \<\< 2) | (METHOD_BUFFERED); ```
>\>2) Please post the C# signature [DllImport] that you're using for
DeviceIoControl
>\>3) Please post the contents of
Parameters.DeviceIoControl.InputBufferLength and
Paramters.DeviceIoControl.OutputBufferLength
Parameters.DeviceIoControl.InputBufferLength is 0
Paramters.DeviceIoControl.OutputBufferLength is 200
As I say, the api call and CTL_CODE works like a charm with one structure.
Very confusing.
---
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.co.uk
Sent: Friday, September 03, 2010 9:27 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] DeviceIO and Array of structs
But 4 is what it is supposed to return. You get the length from the parameters field of the irp stack…
Mark Cariddi
OSR Open Systems Resources, Inc
Associate Fellha… (to keep up with MM… ;
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.co.uk
Sent: Friday, September 03, 2010 10:27 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] DeviceIO and Array of structs
Firstly, yes I do feel stupid.
Secondly, yes I do feel incredibly stupid.
Thirdly this is what happens when some code eats you up and you start at the screen until 3am then get up again 3 hours later, start at the screen all day long (with a screaming teething toddler in the background for good measure)
I will track back in the code versions and see how the heck it ever worked for one structure. Should be interesting.
While this CAN be a helpful site, the contents vary widely in terms of the qualify of what’s posted. MUCH if it is not best practice, and some of it is just plain wrong.
I’m not saying never go to pinvoke.net – I’m merely saying use your judgement and verify whatever you find there.