DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Creating a loop? Need some guidance! (http://www.daniweb.com/forums/thread109825.html)

cosmos22 Feb 19th, 2008 10:59 am
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!

niek_e Feb 19th, 2008 11:36 am
Re: Creating a loop? Need some guidance!
 
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

cosmos22 Feb 19th, 2008 11:50 am
Re: Creating a loop? Need some guidance!
 
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

niek_e Feb 19th, 2008 11:52 am
Re: Creating a loop? Need some guidance!
 
As I said:
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);
}

cosmos22 Feb 19th, 2008 12:27 pm
Re: Creating a loop? Need some guidance!
 
I get an error message that &d is undeclared, can you help?

Thanks

Agni Feb 19th, 2008 1:48 pm
Re: Creating a loop? Need some guidance!
 
is this line still there?

DWORD d = 0;


All times are GMT -4. The time now is 4:56 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC