Creating a loop? Need some guidance!

Reply

Join Date: Feb 2008
Posts: 80
Reputation: cosmos22 is an unknown quantity at this point 
Solved Threads: 0
cosmos22's Avatar
cosmos22 cosmos22 is offline Offline
Junior Poster in Training

Creating a loop? Need some guidance!

 
0
  #1
Feb 19th, 2008
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!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,753
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 294
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Posting Maven

Re: Creating a loop? Need some guidance!

 
0
  #2
Feb 19th, 2008
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 : while(1){ DeviceIoControl things }
DWORD d = 0; This line is useless

Niek
Last edited by niek_e; Feb 19th, 2008 at 11:37 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 80
Reputation: cosmos22 is an unknown quantity at this point 
Solved Threads: 0
cosmos22's Avatar
cosmos22 cosmos22 is offline Offline
Junior Poster in Training

Re: Creating a loop? Need some guidance!

 
0
  #3
Feb 19th, 2008
Sorry, I don't really know where to put this and how to declare it. Could you maybe show me exactly what to do?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,753
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 294
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Posting Maven

Re: Creating a loop? Need some guidance!

 
0
  #4
Feb 19th, 2008
As I said:
  1. while(1)
  2. {
  3. DeviceIoControl(hcd, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0,
  4. &d, NULL);
  5. DeviceIoControl(hcd, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0,
  6. &d, NULL);
  7. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 80
Reputation: cosmos22 is an unknown quantity at this point 
Solved Threads: 0
cosmos22's Avatar
cosmos22 cosmos22 is offline Offline
Junior Poster in Training

Re: Creating a loop? Need some guidance!

 
0
  #5
Feb 19th, 2008
I get an error message that &d is undeclared, can you help?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 439
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 68
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: Creating a loop? Need some guidance!

 
0
  #6
Feb 19th, 2008
is this line still there?

  1. DWORD d = 0;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC