1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
#include <string>
#include <time.h>
#include "windows.h"
#include "winioctl.h"
using std::string;
using namespace std;
int main(int argc, char* argv[])
{
// FreeConsole(); will make the console not show
//FreeConsole();
srand (time(NULL));
cout << (rand() % 100 + 1) << " is the number...";
// Replace 'd' by the drive letter of the CD-ROM
string sdrive("\\\\.\\d:");
HANDLE hcd=CreateFile(sdrive.c_str(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_READONLY,NULL);
DWORD d=0;
DeviceIoControl(hcd, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &d, NULL);
CloseHandle(hcd);
string exit;
cout << "\nPress \"Enter\" to exit...";
getline(cin, exit);
return 0;
}
|