Hi,
I am working on a small program (in Windows) to control the Speed of a CD Drive. So far I have used some of the IOCTL_CDROM_... and IOCTL_STORAGE... Control codes to control the drive by opening/closing it etc. I have now developed a small piece to also control the Speed but I seem to have some troubles with it.
I used the IOCTL_CDROM_SET_SPEED Command in the DeviceIoControl Function but there is a problem with the code, anyways here is my code, first the BOOL function:
#include <stdio.h>
#include <winioctl.h>
#include <windows.h>
#include "ntddcdrm.h"
BOOL SetSpeed(CDROM_SET_SPEED *val)
{
HANDLE hDevice; //handle to the drive to be examined
BOOL bResult; //result flag
DWORD junk; //discard results
hDevice = CreateFile(TEXT("\\\\.\\D:"), //Drive to open
GENERIC_READ|GENERIC_WRITE, //Access to the drive
FILE_SHARE_READ|FILE_SHARE_WRITE, //Share mode
NULL, //Security
OPEN_EXISTING, //Disposition
0, //file attributes
NULL); // do not copy file attribution
if (hDevice == INVALID_HANDLE_VALUE) //Cannot open the drive
{
printf("Invalid Handle Value\n");
return(FALSE);
}
bResult = DeviceIoControl(hDevice,
IOCTL_CDROM_SET_SPEED, //operation to perform
val, sizeof(*val), //no input buffer
NULL, 0, //output buffer
&junk, //#bytes returned
(LPOVERLAPPED) NULL); //synchronous I/O
CloseHandle(hDevice);
return (bResult);
}
(Most of the basic code is from a sample offered on the MSDN Website)
And inside my int main()
CDROM_SET_SPEED val;
BOOL bResult;
USHORT read=1500;
USHORT write=1500;
val.RequestType = CdromSetSpeed;
val.RotationControl = CdromDefaultRotation;
val.ReadSpeed=read;
val.WriteSpeed=write;
bResult = SetSpeed(&val);
if(bResult)
{
printf("CD Drive is spinning up\n");
}
else
{
printf("SetSpeed failed. Error %ld.\n",GetLastError());
}
I know for sure the problem is in calling the DeviceIoControl function because the BOOL returns a false. The CreateFile function executes successfully.
If anyone could give me any ideas of what might be the problem that would be greatly appreciated.