How to open CD-ROM in C?

Asked

Viewed 202 times

3

I want to create an algorithm in C to open and close the CD-ROM drive, I took a look at some tutorials but they ended up not working. I would like to know which libraries you should use.

  • Depends on OS. And is easier in the system shell

  • @Jeffersonquesado Windows 7. I know that in Linux the code is very short. But in Windows, by the tutorials I could not. So I thought I’d create one myself, but I wanted to know which libraries to use.

  • 4

    @Marinero: Well, I found the question very relevant, with the correct TAGS, and could add a lot to the Sopt community: https://pastebin.com/qZW7aEkP

  • 2

    Maybe I’m taking a risk, but I voted to reopen giving Lacobus the opportunity to answer (I’m not going to say it works, because it’s not something I dominate). ps: @lacobus I don’t dominate C as much as you do, but I believe that true and false need a define, or Enum or even <stdbool.h>, of course you may have assumed that this is something intuitive for the author, but sometimes he may beginner.

  • @Guilhermenascimento: You’re right. The type bool, and the constants true and false are unique to the C++ and are not part of the standard C.

  • @Lacobus already voted to reopen, 3 votes are missing, now just wait. PS: O stdbool.h was introduced in the C99 if I’m not mistaken.

  • Try the following ----- #include <windows. h> #include <iostream> using namespace Std; typedef MCIERROR WINAPI (CDROM)(const char,char*,unsigned,HWND); CDROM pcd; void Abrir cd(){ pcd("Set Cdaudio Door Open",NULL,0,NULL); } void Fecha cd(){ pcd("Set Cdaudio Door Closed",NULL,0,NULL); }

  • int menu(){ int Choice; Cout << "you want to open or close the cd drive? n"; Cout << "[1]Open n"; Cout << "[2]Close n"; Cin >> Choice; switch(Choice){ case 1: Open CD(); break; case 2: Closecd(); break; default: Cout << "non-existent option n"; Sleep(250); Exit(0); } Exit(0); Return 0; }

  • int main(){ HINSTANCE dll = Loadlibrary("winmm.dll"); if(!dll) Return 1; pcd = (CDROM)Getprocaddress(dll,"mciSendStringA"); if(!pcd) Return 1; menu(); Return 0; }

  • Copy the sequence and glue, then and execute, I could not answer otherwise, I am new here :S

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.