Navigation
Artikel
Stuff
RSS Feeds
|
Sourcecodes - CD-Rom Laufwerk öffnen, schließenSprachenübersicht/C / C++/ C#/Sonstiges Keywords: ROM Laufwerk öffnen und wieder schließen, C++ Quellcode, Sourcecode, programmieren, Programmieren Anton Staruschkin Top
Code: #include <windows.h> //#pragma comment(lib,"winmm.lib") //für MSV C++ BOOL DoOpenCdRom(void) { char chrRc[256]; char *ptrChrRc = &chrRc[0]; return mciSendString("Set CDAudio Door Open\0",ptrChrRc,256,NULL); } BOOL DoCloseCdRom(void) { char chrRc[256]; char *ptrChrRc = &chrRc[0]; return mciSendString("Set CDAudio Door Closed\0",ptrChrRc,256,NULL); } int main() { DoOpenCdRom(); Sleep(5000); DoCloseCdRom(); return 0; }
Erweiterung von Simon Hecht Top
Code: #include <windows.h> #include <string> #include <winbase.h> #include <sstream> #include <iostream> //winmm libary is needed! //Add it! //#pragma comment(lib,"winmm.lib") //for MSV C++ /** GetDriverType Return Values --------------------------- DRIVE_UNKNOWN The drive type cannot be determined. DRIVE_NO_ROOT_DIR The root path is invalid; for example, there is no volume is mounted at the path. DRIVE_REMOVABLE The drive has removable media; for example, a floppy drive or flash card reader. DRIVE_FIXED The drive has fixed media; for example, a hard drive, flash drive, or thumb drive. DRIVE_REMOTE The drive is a remote (network) drive. DRIVE_CDROM The drive is a CD-ROM drive. DRIVE_RAMDISK The drive is a RAM disk. **/ #if defined(UNICODE) typedef wchar_t character; #else typedef char character; #endif //Converts a Variable to a String template<class T> std::string Convert2String(T t) { std::basic_ostringstream<character> outstream; outstream << t << std::endl; std::string str(outstream.str()); str.resize(str.length()-1); return str; } void ChangeCDRoms(bool Open = true) { std::string ActionString = "Open"; if(Open != true) ActionString = "Closed"; //Each character A-Z for(char i = (char)65; i < (char)91; i++) { //Create a String with the device character and "\\" std::string CDDriver = Convert2String(i) + std::string(":\\"); //Get the driver type UINT uDriveType = ::GetDriveType(CDDriver.c_str()); //It's a cdrom device if (uDriveType == DRIVE_CDROM) { //Return buffer char chrRc[256]; // MessageBox(0, "Is a cdrom drive", CDDriver.c_str(), MB_OK); //Sets the alias ::mciSendString(std::string("Open "+ CDDriver + " Type cdaudio Alias cd").c_str(), &chrRc[0],256,NULL); //CDRom is now open, change Open to Close for closing ::mciSendString(std::string("Set cd Door " + ActionString).c_str(), &chrRc[0],256,NULL); } } } int main() { ChangeCDRoms(true); Sleep(1000); ChangeCDRoms(false); return 0; }
Gibt es noch irgendwelche Fragen, oder wollen Sie über den Artikel diskutieren? Sprachenübersicht/C / C++/ C#/Sonstiges/CD-Rom Laufwerk öffnen, schließen |