Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How can I eject a disc?
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MrAndrews




PostPosted: Mon May 26, 2008 10:25 pm   Post subject: How can I eject a disc?

I have Turing v. 4.1.1, and I was wondering how to open the disc drive. I was going to use this in to put at the end of a trivia type program something like:

put "You Won!"
put "As your prize, you will now receive a new Cup Holder!"
(This is where you would open the disc drive)



I know that to shut down the computer you use:

var ret : int
system ("shutdown -s -c message-here", ret)

so i was thinking that to do something like open the disc drive you would need something similiar, but so far ive gotten nowhere
anyway, if anyone can help, thatd be great

ps. im new to this website, so im sorry if i put this in the wrong place or submitted it incorrectly somehow
Sponsor
Sponsor
Sponsor
sponsor
Nick




PostPosted: Mon May 26, 2008 11:23 pm   Post subject: Re: How can I eject a disc?

MrAndrews @ Mon May 26, 2008 10:25 pm wrote:

var ret : int
system ("shutdown -s -c message-here", ret)


never used System before but it seems to use DOS prompt... look for a DOS command
Tony




PostPosted: Mon May 26, 2008 11:54 pm   Post subject: Re: How can I eject a disc?

nick @ Mon May 26, 2008 11:23 pm wrote:
look for a DOS command

unless he's running Windows 98 (or *gasp* earlier), DOS is hardly relevant.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
MrAndrews




PostPosted: Tue May 27, 2008 10:50 am   Post subject: RE:How can I eject a disc?

Personally, I havnt really used System before either . . . i got that line of code from a program a friend sent me. As for the OS, my friend wrote and tested the program on XP, and i am running Vista and it still shut my computer down
btiffin




PostPosted: Tue May 27, 2008 2:00 pm   Post subject: Re: How can I eject a disc?

If Turing allows dll linking;

Convert this C# to something similar in Turing syntax (something I know little about)
Csharp:

//This is necessary to enable Win32 API calls to eject or close the CD tray

   [DllImport("winmm.dll", EntryPoint = "mciSendStringA")]
   public static extern void mciSendStringA(string lpstrCommand, string lpstrReturnString, Int32 uReturnLength, Int32 hwndCallback);
   string rt = "";

   private void EjectCD()
   {
     mciSendStringA("set CDAudio door open", rt, 127, 0);
   }

   private void CloseCD()
   {
     mciSendStringA("set CDAudio door closed", rt, 127, 0);
   }


http://msdn.microsoft.com/en-us/library/ms712587%28VS.85%29.aspx for more info

Cheers
Nick




PostPosted: Tue May 27, 2008 2:03 pm   Post subject: RE:How can I eject a disc?

well DOS, command prompt, I don't know the difference, the only console I use is for ubuntu
btiffin




PostPosted: Tue May 27, 2008 2:11 pm   Post subject: RE:How can I eject a disc?

P.S. Be careful if you experiment with mciSendString. It can do a lot, and no doubt bone things up if not shown the proper care and respect.

Cheers
MrAndrews




PostPosted: Sat May 31, 2008 7:06 pm   Post subject: RE:How can I eject a disc?

Thanks for the help so far . . .
Unfortunately, i have no idea how to use C# and even less of an idea how to translate something like that into Turing. as far as i know, the system (" "ret) function that i used does the exact same thing as Sys.Exec (" ") which i have seen in other parts of compsci. They both use the Windows Command Line, however i am not sure if there is a command available through that that actually opens the cd door.

anyway, if anyone has any ideas on this, some more help would be great
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Sat May 31, 2008 9:53 pm   Post subject: Re: RE:How can I eject a disc?

btiffin @ 2008-05-27, 2:11 pm wrote:
P.S. Be careful if you experiment with mciSendString. It can do a lot, and no doubt bone things up if not shown the proper care and respect.

No reason to worry... Turing doesn't allow DLL linking, though I am sure with a little creativity just as much harm can be done...

MrAndrews, I don't know how, but I don't doubt that there is a way over the command line. Just keep looking, google it. Smile
Stove




PostPosted: Mon Jun 02, 2008 9:09 pm   Post subject: Re: How can I eject a disc?

You could try making a visual basic script (make a text file and change the extension to .vbs, not real visual basic btw) with something like:

VisualBASIC:

Set wmp = CreateObject("WMPlayer.OCX.7" )
Set cds = wmp.cdromCollection

if cds.Count >= 1 then
        For i = 0 to cds.Count - 1
        cds.Item(i).Eject
        Next ' cdrom
End If


And then just execute the file with system(). The only problem is that wscript.exe or whatever program runs the script, never actually closes... You could probably run "taskkill /f /im wscript.exe" with system() afterwards to clean it up. Its kind of an "icky" approach, but I tried it in Turing and it seems to work.

Turing:

var blah : int
system ("test.vbs", blah)
delay (8000)
system ("taskkill /f /im wscript.exe", blah)


One last thing, it takes forever for the script to actually load and run, so you'll have to wait a bit before you kill wscript.exe. That being said, it'd probably be a good idea to run the script on a separate thread so you don't have to block your main program while it runs. It took about 8 seconds on my laptop to run, but that time will probably vary. Anyways, hope that helps.
btiffin




PostPosted: Tue Jun 03, 2008 4:32 am   Post subject: Re: How can I eject a disc?

If you haven't googled a good executable yet, try this ECMAScript (ECMAScript is just me using anal speak for javascript)

Make a file ej.js

ECMAScript:
Drive = "E:\\"
sysapp = new ActiveXObject("Shell.Application")
fakeright = sysapp.NameSpace(Drive).Self
fakeright.InvokeVerb("E&ject")


What ever the drive letter for the CD is (you, may need to wrap this is an error trapper and try D:, E:, F:, G: etc) I'll leave any error handling for you to figure out ... not hard ... ok a hint, ECMAScript has try/catch. If you pick a drive letter that doesn't exist, script runner will pop up an error dialog.

Then try your system() Turing function on ej.js

Cheers

Edit; Sorry, just noticed the VB solution. This wasn't meant as a one upper, apologies for that Stove.
jeffgreco13




PostPosted: Tue Jun 03, 2008 11:44 am   Post subject: Re: How can I eject a disc?

I've done this before. It's been a while since I worked with it but have a look:

Quote:
Set oWMP = CreateObject("WMPlayer.OCX.7" )
Set colCDROMs = oWMP.cdromCollection

if colCDROMs.Count >= 1 then
For i = 0 to colCDROMs.Count - 1
colCDROMs.Item(i).Eject
Next ' cdrom
End If


This is VBScript and it does work! You open up notepad and paste that in. Save as cdOpen.vbs

MAKE SURE ITS EXTENSION IS > .vbs

Then use this:

Quote:
var ret : int
system ("put the path to the file here", ret)


that should work... for what ur looking for.

There's also ways to have turing open a filestream and create that file for you if you're to make a standalone exe.

PM me for details on that.
petree08




PostPosted: Tue Jun 03, 2008 12:04 pm   Post subject: RE:How can I eject a disc?

does anyone have a compiled (.exe) disktray opener?
the following should work if the exe is named DiskOpen.exe

code:

if not Sys.Exec ("DiskOpen.exe") then
    put "doesn't work"
end if



i suck at c and was wondering if anyone would post a compiled disk tray opener

edit : sorry i didn't read the above post properly , pretty much the same thing
Stove




PostPosted: Tue Jun 03, 2008 6:55 pm   Post subject: Re: How can I eject a disc?

@ MrAndrews

Definitely use btiffin's script for opening the cd drive, as it completely avoids the whole taskkill and clean up bit that executing a visual basic script needs.

@ btiffin

No need to apologize, the more solutions the better. Razz
MrAndrews




PostPosted: Fri Jun 20, 2008 10:37 pm   Post subject: RE:How can I eject a disc?

Thanks for all the help everyone. I havnt been on in a while to read this (exams etc.) but now I have a bit more time

I know nothing about javascript, so decided to try the solution given by jeffgreco13 first, which worked fine. I didn't add any taskkill feature to the program and when i went into the taskmanager, i couldnt find the VBScript. Maybe i'm not looking in the right place? Anyway this works for what I am trying to do.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: