| | |
Creating a loop? Need some guidance!
![]() |
Hello, I have downloaded some coding off the internet and modified it to suit my needs. It opens and closes the CD drive ONCE. And I would like to make it do so an infinate amount of times.
#include "windows.h"
#include "winioctl.h"
#include <string>
using std::string;
int main(int argc, char* argv[])
{
string sdrive("\\\\.\\e:"); //replace 'g' by the drive letter of the cdrom
HANDLE hcd = CreateFile(sdrive.c_str(),
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_READONLY,
NULL);
if (hcd == INVALID_HANDLE_VALUE)
printf("Could not open drive g:\\\n");
DWORD d = 0;
DeviceIoControl(hcd, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0,
&d, NULL);
DeviceIoControl(hcd, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0,
&d, NULL);
CloseHandle(hcd);
return 0;
}
Thank you all!
#include "windows.h"
#include "winioctl.h"
#include <string>
using std::string;
int main(int argc, char* argv[])
{
string sdrive("\\\\.\\e:"); //replace 'g' by the drive letter of the cdrom
HANDLE hcd = CreateFile(sdrive.c_str(),
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_READONLY,
NULL);
if (hcd == INVALID_HANDLE_VALUE)
printf("Could not open drive g:\\\n");
DWORD d = 0;
DeviceIoControl(hcd, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0,
&d, NULL);
DeviceIoControl(hcd, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0,
&d, NULL);
CloseHandle(hcd);
return 0;
}
Thank you all!
This is the third time I'm going to tell you to : PLEASE USE CODE tags
You need a loop around the two DeviceIoControl() lines like :
Niek
You need a loop around the two DeviceIoControl() lines like :
while(1){ DeviceIoControl things } DWORD d = 0; This line is uselessNiek
Last edited by niek_e; Feb 19th, 2008 at 11:37 am.
As I said:
c Syntax (Toggle Plain Text)
while(1) { DeviceIoControl(hcd, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &d, NULL); DeviceIoControl(hcd, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, &d, NULL); }
![]() |
Other Threads in the C++ Forum
- Previous Thread: Getting packet detais in VC++
- Next Thread: Socket Programming
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error faq file forms fstream function functions game givemetehcodez graph gui hash homeworkhelp homeworkhelper iamthwee ifpug ifstream infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets






