한 걸음씩..

Beep 사용 본문

프로그래밍

Beep 사용

smdy0426 2013. 7. 15. 10:58
반응형

PC 내부 Beep 음을 울리게 하는 코드 Debug용으로 사용

NTSTATUS DriverEntry( PDRIVER_OBJECT pDriverObject, PUNICODE_STRING RegistryPath )

{

//....

pDriverObject->MajorFunction[IRP_MJ_CREATE]= PCIDrv_CreateClose;

pDriverObject->MajorFunction[IRP_MJ_CLOSE]= PCIDrv_CreateClose;

return STATUS_SUCCESS;

}


NTSTATUS PCIDrv_CreateClose( IN PDEVICE_OBJECT pFunctionDeviceObject, IN PIRP pIrp )

{

  //..........

  PIO_STACK_LOCATION pStack = NULL;

  PPCI_DEVICE_EXTENSIONpDeviceExtension = NULL;

ULONG BeepDuration = 0;

  ULONG BeepFrequency = 0;

  LARGE_INTEGER dwInterval;

  LARGE_INTEGER dwOutValue;

  KEVENT BeepDurationEvent  = { 0, };

  

  //..........


pStack = IoGetCurrentIrpStackLocation( pIrp );


pDeviceExtension = (PPCI_DEVICE_EXTENSION) pFunctionDeviceObject->DeviceExtension;


switch( pStack -> MajorFunction )

{

case IRP_MJ_CREATE:

{

//....

KeInitializeEvent( &BeepDurationEvent, NotificationEvent, FALSE );

if ( BeepDuration <= 0 )

BeepDuration = 10;


if ( BeepFrequency <= 0 )

BeepFrequency = 1000;


dwInterval  = RtlConvertLongToLargeInteger( -1000000 * ( BeepDuration / 10 ) ); 

dwOutValue.QuadPart = 1193167 / BeepFrequency;

WRITE_PORT_UCHAR( (char *)0x61, 3 );

WRITE_PORT_UCHAR( (char *)0x43, 0xB6 );

WRITE_PORT_UCHAR( (char *)0x42, (char)(dwOutValue.QuadPart % 0x100) );

WRITE_PORT_UCHAR( (char *)0x42, (char)(dwOutValue.QuadPart / 0x100) );

KeWaitForSingleObject( &BeepDurationEvent, Executive, KernelMode, FALSE, &dwInterval.QuadPart );

WRITE_PORT_UCHAR( (char *)0x61, 0 );

//............

break;

}

case IRP_MJ_CLOSE:

{

//....

break;

}

}

pIrp->IoStatus.Status = ntStatus;

pIrp->IoStatus.Information = 0;

IoCompleteRequest( pIrp, IO_NO_INCREMENT );

return ntStatus;

}


LARGE_INTEGER RtlConvertLongToLargeInteger( LONG SignedInteger )

{

LARGE_INTEGER li;

li.QuadPart = SignedInteger;

return li;

}

반응형

'프로그래밍' 카테고리의 다른 글

MFC KeyDown 이벤트가 안될 때  (0) 2013.07.15
0xC0000005: Access violation‎ 오류 해결 방법  (0) 2013.07.15
IOPM(I/O Permission Bitmap) 구현  (0) 2013.07.15
Toaster enum Error  (0) 2013.07.15
Device 인식 기본적인 함수  (0) 2013.07.15