Hello,
i have some trouble passing a struct to my driver :
My app :
…
Command myCommand;
myCommand.data = 3;
myCommand.pe.data1 = 23;
myCommand.pe.data2 = 123;
…
DeviceIoControl (dev, myapp_add, &myCommand, sizeof(Command), &ver,
sizeof (ver), &bytes_out, NULL);
My driver :
case myapp_add:
DbgPrint((“my app Add hook”));
if (InputBuffer && InputBufferLength == sizeof(Command)){
DbgPrint((“Winmac : argument match”));
RtlCopyMemory(&myCommand,&InputBuffer,sizeof(Command));
DbgPrint((“data %d”, myCommand.data));
DbgPrint((“data1 : %d”,myCommand.pe.data1));
DbgPrint((“data2 : %d”,myCommand.pe.data2));
where : InputBuffer = Irp->AssociatedIrp.SystemBuffer;
and InputBufferLength =
irp_stack->Parameters.DeviceIoControl.InputBufferLength;
Command looks like :
struct PE {
int data1;
int data2;
};
typedef struct Command{
int data;
struct PE pe;
} Command;
This works but i have trouble with my values data1 is always equal to
12, data2 to -2130372064 and if i try to cast them *(ULONG*) or *(int
*), windows (XP SP2) crashs.
If someone has an idea…
Thanks in advance
Best regards
Louis
The string
RtlCopyMemory(&myCommand,&InputBuffer,sizeof(Command));
must be
RtlCopyMemory(&myCommand,InputBuffer,sizeof(Command));
because InputBuffer contains the buffer address, the (&InputBuffer) is
the address of the stack variable.
“Louis Nyffenegger” wrote in message
news:xxxxx@ntdev…
Hello,
i have some trouble passing a struct to my driver :
My app :
…
Command myCommand;
myCommand.data = 3;
myCommand.pe.data1 = 23;
myCommand.pe.data2 = 123;
…
DeviceIoControl (dev, myapp_add, &myCommand, sizeof(Command), &ver,
sizeof (ver), &bytes_out, NULL);
My driver :
case myapp_add:
DbgPrint((“my app Add hook”));
if (InputBuffer && InputBufferLength == sizeof(Command)){
DbgPrint((“Winmac : argument match”));
RtlCopyMemory(&myCommand,&InputBuffer,sizeof(Command));
DbgPrint((“data %d”, myCommand.data));
DbgPrint((“data1 : %d”,myCommand.pe.data1));
DbgPrint((“data2 : %d”,myCommand.pe.data2));
where : InputBuffer = Irp->AssociatedIrp.SystemBuffer;
and InputBufferLength =
irp_stack->Parameters.DeviceIoControl.InputBufferLength;
Command looks like :
struct PE {
int data1;
int data2;
};
typedef struct Command{
int data;
struct PE pe;
} Command;
This works but i have trouble with my values data1 is always equal to
12, data2 to -2130372064 and if i try to cast them (ULONG) or (int
), windows (XP SP2) crashs.
If someone has an idea…
Thanks in advance
Best regards
Louis
nice, it works
thanks
Louis
On 4/25/06, Slava Imameyev wrote:
> The string
> RtlCopyMemory(&myCommand,&InputBuffer,sizeof(Command));
> must be
> RtlCopyMemory(&myCommand,InputBuffer,sizeof(Command));
> because InputBuffer contains the buffer address, the (&InputBuffer) is
> the address of the stack variable.
>
>
> “Louis Nyffenegger” wrote in message
> news:xxxxx@ntdev…
> Hello,
>
> i have some trouble passing a struct to my driver :
>
> My app :
> …
> Command myCommand;
> myCommand.data = 3;
> myCommand.pe.data1 = 23;
> myCommand.pe.data2 = 123;
> …
> DeviceIoControl (dev, myapp_add, &myCommand, sizeof(Command), &ver,
> sizeof (ver), &bytes_out, NULL);
>
>
>
> My driver :
> case myapp_add:
> DbgPrint((“my app Add hook”));
> if (InputBuffer && InputBufferLength == sizeof(Command)){
> DbgPrint((“Winmac : argument match”));
> RtlCopyMemory(&myCommand,&InputBuffer,sizeof(Command));
> DbgPrint((“data %d”, myCommand.data));
> DbgPrint((“data1 : %d”,myCommand.pe.data1));
> DbgPrint((“data2 : %d”,myCommand.pe.data2));
>
> where : InputBuffer = Irp->AssociatedIrp.SystemBuffer;
> and InputBufferLength =
> irp_stack->Parameters.DeviceIoControl.InputBufferLength;
>
> Command looks like :
> struct PE {
> int data1;
> int data2;
> };
>
> typedef struct Command{
> int data;
> struct PE pe;
> } Command;
>
> This works but i have trouble with my values data1 is always equal to
> 12, data2 to -2130372064 and if i try to cast them (ULONG) or *(int
> *), windows (XP SP2) crashs.
>
> If someone has an idea…
>
> Thanks in advance
>
> Best regards
>
> Louis
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>