Hi,
I would like to ask you for advice. I need SetEvent from Driver WDF (PCI card), when Interrupt occur to the application. We have used this code on the WIN XP x86 successfully (driver WDM) but now we need use to same on the WIN 7 x64 (driver wdf).
UserMode creates the event HANDLE successfully:
hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
Then passes it to Kernel Mode through IOCTL:
DeviceIoControl(
hdevice,
IOCTL_REGISTER_EVENT,
&hEvent,
sizeof(hEvent),
NULL,
0,
&junk,
NULL);
Which gets picked up in Kernel Mode:
Irp = WdfRequestWdmGetIrp(Request);
case IOCTL_REGISTER_EVENT:
devContext->HEvent = *(PHANDLE) Irp->AssociatedIrp.SystemBuffer;
KdPrint ((DRIVERNAME"\t\t\t\t HEvent is: (0x%p)\r\n", devContext->HEvent));
status = ObReferenceObjectByHandle(
devContext->HEvent,
EVENT_MODIFY_STATE,
*ExEventObjectType,
KernelMode,
&devContext->KEvent, NULL);
KdPrint ((DRIVERNAME"\t\t\t\t KEvent is: (0x%p)\r\n", devContext->KEvent));
if(!NT_SUCCESS(status)){
KdPrint((DRIVERNAME"\t\t\t\tObReferenceObjectByHandle() failed 0x%x\n", status));
devContext->HEvent = NULL;
devContext->KEvent = NULL;
}
break;
This code work correctly under the WIN XP x86, as I wrote upwards, but in the WIN 7 x64 i have problem with STATUS_INVALID_HANDLE, error code 0xc0000008, which get from ObReferenceObjectByHandle.
It is strange, because i compared hEvent from UserMode with HEvent from Kernel Mode and that value was equivalent. Maybe is problem in 32 bit app in 32 bit HANDLE and 64 bit HANDLE in Driver KernelMode.
But i tried this structure in UserMode:
typedef struct {
HANDLE hEvent;
HANDLE zero;
}s_handle;
I wanted same lenght. I got it, but problem still standing.
Please help me find out why the handle is invalid?