P
perlinson
Guest
I want to access the system's beep device. I opened the Beep Device successfuly. but It doesn'work with dobeep(). I don't know what's wrong with the code. In the beepIoctlRequestCompletionRoutine. CompletionParams->IoStatus.Status return 0xc0000001.
NTSTATUS DoBeep(WDFDEVICE device, unsigned int Duration, unsigned int Frequency)
{
NTSTATUS status = STATUS_SUCCESS;
BEEP_SET_PARAMETERS input;
WDFMEMORY wdfMemory = NULL;
WDFREQUEST request;
WDF_OBJECT_ATTRIBUTES attributes;
PDEVICE_EXTENSION pDeviceExtension = DeviceGetContext(device);
// WDF_REQUEST_SEND_OPTIONS options;
KdPrint(("beep into"));
status = WdfRequestCreate(WDF_NO_OBJECT_ATTRIBUTES,
pDeviceExtension->BeepTarget,
&request);
if (!NT_SUCCESS(status))
{
KdPrint(("beep WdfRequestCreate failed.status=0x%x!", status));
return status;
}
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = request;
input.Duration = Duration;
input.Frequency = Frequency;
WdfMemoryCreatePreallocated(&attributes, &input, sizeof(BEEP_SET_PARAMETERS), &wdfMemory);
status = WdfIoTargetFormatRequestForIoctl(pDeviceExtension->BeepTarget,
request,
IOCTL_BEEP_SET,
wdfMemory,
NULL,
wdfMemory,
NULL);
if (!NT_SUCCESS(status)) {
KdPrint(("beep WdfIoTargetFormatRequestForIoctl failed.status=0x%x!", status));
return status;
}
WdfRequestSetCompletionRoutine(request,
beepIoctlRequestCompletionRoutine,
NULL);
// WDF_REQUEST_SEND_OPTIONS_INIT(&options,
// WDF_REQUEST_SEND_OPTION_SYNCHRONOUS);
//
// if (!WdfRequestSend(request,
// pDeviceExtension->BeepTarget,
// &options)) {
// status = WdfRequestGetStatus(request);
// if (!NT_SUCCESS(status)) {
// KdPrint(("beep WdfRequestSend failed! 0x%0.4x", status));
// return status;
// }
// }
if (WdfRequestSend(request, pDeviceExtension->BeepTarget, WDF_NO_SEND_OPTIONS) == FALSE)
{
status = WdfRequestGetStatus(request);
KdPrint(("beep WdfRequestSend failed 0x%x\n", status));
return status;
}
KdPrint(("beep before success!"));
// KeSleep(Duration);
// KeSleep(50000);
WaitMicroSecond(100);
KdPrint(("beep success!"));
return status;
}
NTSTATUS OpenBeepDevice(WDFDEVICE Device, WDFIOTARGET* Target)
{
WDF_IO_TARGET_OPEN_PARAMS openParams;
NTSTATUS status = STATUS_SUCCESS;
WDFIOTARGET ioTarget;
WDF_OBJECT_ATTRIBUTES attributes;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, BEEP_DEVICE_INFO);
DECLARE_UNICODE_STRING_SIZE(SymbolicLink, 128);
status = WdfIoTargetCreate(Device,
&attributes,
&ioTarget);
if (!NT_SUCCESS(status)) {
KdPrint(("beep WdfIoTargetCreate failed 0x%x\n", status));
return status;
}
status = RtlUnicodeStringPrintf(&SymbolicLink, L"\\Device\\%s", L"Beep");
if (!NT_SUCCESS(status)) {
return status;
}
WDF_IO_TARGET_OPEN_PARAMS_INIT_OPEN_BY_NAME(
&openParams,
&SymbolicLink,
STANDARD_RIGHTS_ALL);
openParams.ShareAccess = FILE_SHARE_WRITE | FILE_SHARE_READ;
status = WdfIoTargetOpen(ioTarget, &openParams);
if (!NT_SUCCESS(status)) {
KdPrint(("beep WdfIoTargetOpen failed with status 0x%x\n", status));
WdfObjectDelete(ioTarget);
return status;
}
KdPrint(("beep WdfIoTargetOpen Successfully!\n"));
*Target = ioTarget;
return status;
}
VOID
beepIoctlRequestCompletionRoutine(
IN WDFREQUEST Request,
IN WDFIOTARGET Target,
PWDF_REQUEST_COMPLETION_PARAMS CompletionParams,
IN WDFCONTEXT Context
)
{
UNREFERENCED_PARAMETER(Context);
UNREFERENCED_PARAMETER(Request);
UNREFERENCED_PARAMETER(Target);
// targetInfo = GetTargetDeviceInfo(Target);
KdPrint(("beep CompletionParams.IoStatus.status =%x ", CompletionParams->IoStatus.Status));
//status = 0xc0000001
}
Continue reading...
NTSTATUS DoBeep(WDFDEVICE device, unsigned int Duration, unsigned int Frequency)
{
NTSTATUS status = STATUS_SUCCESS;
BEEP_SET_PARAMETERS input;
WDFMEMORY wdfMemory = NULL;
WDFREQUEST request;
WDF_OBJECT_ATTRIBUTES attributes;
PDEVICE_EXTENSION pDeviceExtension = DeviceGetContext(device);
// WDF_REQUEST_SEND_OPTIONS options;
KdPrint(("beep into"));
status = WdfRequestCreate(WDF_NO_OBJECT_ATTRIBUTES,
pDeviceExtension->BeepTarget,
&request);
if (!NT_SUCCESS(status))
{
KdPrint(("beep WdfRequestCreate failed.status=0x%x!", status));
return status;
}
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = request;
input.Duration = Duration;
input.Frequency = Frequency;
WdfMemoryCreatePreallocated(&attributes, &input, sizeof(BEEP_SET_PARAMETERS), &wdfMemory);
status = WdfIoTargetFormatRequestForIoctl(pDeviceExtension->BeepTarget,
request,
IOCTL_BEEP_SET,
wdfMemory,
NULL,
wdfMemory,
NULL);
if (!NT_SUCCESS(status)) {
KdPrint(("beep WdfIoTargetFormatRequestForIoctl failed.status=0x%x!", status));
return status;
}
WdfRequestSetCompletionRoutine(request,
beepIoctlRequestCompletionRoutine,
NULL);
// WDF_REQUEST_SEND_OPTIONS_INIT(&options,
// WDF_REQUEST_SEND_OPTION_SYNCHRONOUS);
//
// if (!WdfRequestSend(request,
// pDeviceExtension->BeepTarget,
// &options)) {
// status = WdfRequestGetStatus(request);
// if (!NT_SUCCESS(status)) {
// KdPrint(("beep WdfRequestSend failed! 0x%0.4x", status));
// return status;
// }
// }
if (WdfRequestSend(request, pDeviceExtension->BeepTarget, WDF_NO_SEND_OPTIONS) == FALSE)
{
status = WdfRequestGetStatus(request);
KdPrint(("beep WdfRequestSend failed 0x%x\n", status));
return status;
}
KdPrint(("beep before success!"));
// KeSleep(Duration);
// KeSleep(50000);
WaitMicroSecond(100);
KdPrint(("beep success!"));
return status;
}
NTSTATUS OpenBeepDevice(WDFDEVICE Device, WDFIOTARGET* Target)
{
WDF_IO_TARGET_OPEN_PARAMS openParams;
NTSTATUS status = STATUS_SUCCESS;
WDFIOTARGET ioTarget;
WDF_OBJECT_ATTRIBUTES attributes;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, BEEP_DEVICE_INFO);
DECLARE_UNICODE_STRING_SIZE(SymbolicLink, 128);
status = WdfIoTargetCreate(Device,
&attributes,
&ioTarget);
if (!NT_SUCCESS(status)) {
KdPrint(("beep WdfIoTargetCreate failed 0x%x\n", status));
return status;
}
status = RtlUnicodeStringPrintf(&SymbolicLink, L"\\Device\\%s", L"Beep");
if (!NT_SUCCESS(status)) {
return status;
}
WDF_IO_TARGET_OPEN_PARAMS_INIT_OPEN_BY_NAME(
&openParams,
&SymbolicLink,
STANDARD_RIGHTS_ALL);
openParams.ShareAccess = FILE_SHARE_WRITE | FILE_SHARE_READ;
status = WdfIoTargetOpen(ioTarget, &openParams);
if (!NT_SUCCESS(status)) {
KdPrint(("beep WdfIoTargetOpen failed with status 0x%x\n", status));
WdfObjectDelete(ioTarget);
return status;
}
KdPrint(("beep WdfIoTargetOpen Successfully!\n"));
*Target = ioTarget;
return status;
}
VOID
beepIoctlRequestCompletionRoutine(
IN WDFREQUEST Request,
IN WDFIOTARGET Target,
PWDF_REQUEST_COMPLETION_PARAMS CompletionParams,
IN WDFCONTEXT Context
)
{
UNREFERENCED_PARAMETER(Context);
UNREFERENCED_PARAMETER(Request);
UNREFERENCED_PARAMETER(Target);
// targetInfo = GetTargetDeviceInfo(Target);
KdPrint(("beep CompletionParams.IoStatus.status =%x ", CompletionParams->IoStatus.Status));
//status = 0xc0000001
}
Continue reading...