Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Q] Ejecting and unmounting CDs.

0 views
Skip to first unread message

Craig Emery

unread,
Jan 27, 1997, 3:00:00 AM1/27/97
to

Dear All,

I'm being driven mad trying to eject CD's especially from non-apple
CD-Rom drives.

The code below (all variants) works fine on my PPC 8100/80AV with a
built-in Apple CD300ePlus, but not on a Quadra 650 with external CD-Rom
drives (I've tried NEC, Apple and a Toshiba all with and without CharisMac
1.03j CD-Rom drivers)

My first attempt was simply using Eject and UnmountVol both suppiled
the volume ID.

My second attempt (included below) is getting the drive ID from the VCB
for my volume in the VCB list and supplying Eject with that; and finally
supplying PBEject with the volume name and volume ID. I even tried
PBOffLine.

All these attempts were to no avail. When I call Eject (or PBEject etc)
I get error -50.

The drag (pun intended) is that I can drag icons onto the trash and the
CD-Rom drives will eject their CD's.

I can un-mount the volume and it's icon dissapears from the DeskTop,
but I cannot get the CD to pop out of the drive. :-((((((((

All help would be **greatly** appreciated.

TIA

Craig.

// include files
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <string.h>
#include <Files.h>

// proto-types

Boolean InitMac ();
Size _P2CStr (const StringPtr psSrc, char *lpszDest);

// globals

Boolean bMacInited = InitMac (),
bQuitApp = false;

// macros
#define USE_EJECT 1
#define USE_PBEJECT 2
#define USE_PBOFFLINE 3
#define TRY_THIS USE_EJECT
// functions

Boolean InitMac ()
{
InitGraf ((Ptr) &qd.thePort);
InitWindows ();
InitDialogs (nil);
InitMenus ();
InitCursor (); // make the cursor the standard arrow and
set cursor show / hide count to 0
MaxApplZone ();
for (int i = 0; i < 100; i++)
{
MoreMasters ();
}
};

Size _P2CStr (const StringPtr psSrc, char *lpszDest)
{
Size szSize;
BlockMove ((void *) &psSrc[1], (void *) lpszDest, szSize = (Size)
*((char *) psSrc));
lpszDest[szSize] = '\0';
return (szSize);
};

void main(void)
{
QHdrPtr pQHead = GetVCBQHdr ();
if (NULL != pQHead)
{
VCB *pVCB = (VCB *) (pQHead->qHead);
while (NULL != pVCB)
{
VCB *pNext = (VCB *) (pVCB->qLink);
if (0x4244 == pVCB->vcbSigWord)
{
char name[28];
_P2CStr (pVCB->vcbVN, name);
cout << "Should I unmount: " << name << "?";
int iNumber;
cin >> iNumber;
if (0 != iNumber)
{
cout << "\tVolume ID: " << pVCB->vcbVRefNum << endl;
cout << "\tDrive ID: " << pVCB->vcbDrvNum << endl;
cout << "\t\tEjecting..." << endl;
short nsDrvNum = pVCB->vcbDrvNum;
short nsVRefNum = pVCB->vcbVRefNum;
OSErr theErr = noErr;
#if TRY_THIS == USE_EJECT
if (noErr != (theErr = Eject (0, nsDrvNum)))
{
cout << "\t\t\tEject (0, " << nsDrvNum << ")
returned " << theErr << endl;
}
else
{
cout << "\t\tDone." << endl;
};
#elif TRY_THIS == USE_PBEJECT
ParamBlockRec myParamBlk;
Str255 psName;
memset ((void *) &myParamBlk, 0, sizeof (ParamBlockRec));
memcpy ((void *) &psName[0], (void *) pVCB->vcbVN,
(pVCB->vcbVN)[0] + 1);
myParamBlk.volumeParam.ioNamePtr = &psName[0];
myParamBlk.volumeParam.ioVRefNum = nsVRefNum;
PBEject (&myParamBlk);
theErr = myParamBlk.volumeParam.ioResult;
if (noErr != theErr)
{
cout << "\t\t\tPBEject () returned " << theErr << endl;
}
else
{
cout << "\t\tDone." << endl;
};
#elif TRY_THIS == USE_PBOFFLINE
ParamBlockRec myParamBlk;
Str255 psName;
memset ((void *) &myParamBlk, 0, sizeof (ParamBlockRec));
memcpy ((void *) &psName[0], (const void *)
pVCB->vcbVN, (pVCB->vcbVN)[0] + 1);
myParamBlk.volumeParam.ioNamePtr = &psName[0];
myParamBlk.volumeParam.ioVRefNum = nsVRefNum;
PBOffLine (&myParamBlk);
theErr = myParamBlk.volumeParam.ioResult;
if (noErr != theErr)
{
cout << "\t\t\tPBOffline () returned " << theErr <<
endl;
}
else
{
cout << "\t\tDone." << endl;
};
#endif // TRY_THIS == ??
cout << "\t\tand unmounting..." << endl;
if (noErr != (theErr = UnmountVol (0, nsVRefNum)))
{
cout << "\t\t\tUnmountVol (0, " << nsVRefNum << ")
returned " << theErr << endl;
}
else
{
cout << "\t\tDone." << endl;
};
};
pVCB = pNext;
};
};

cout << "End Of Queue" << endl;
};
};

-----------------------------------------------------------------------
| Norman Craig Emery B.Sc., cr...@epic.co.uk |
| Team Leader / Senior CDi Programmer & CRAIG...@applelink.apple.com |
| Macintosh Programming Coordinator, Voice: +44 (0) (1273) 320637 |
| The Epic Multimedia Group, Fax: +44 (0) (1273) 821567 |
| http://www.epic.co.uk/ |
| VPS House, 52 Old Steine, Brighton, East Sussex, BN1 1NH, U.K. |
-----------------------------------------------------------------------

Brian Bechtel

unread,
Jan 27, 1997, 3:00:00 AM1/27/97
to

In article <craig-ya02318000...@proxy.epic.co.uk>,
cr...@epic.co.uk (Craig Emery) wrote:

> Dear All,
>
> I'm being driven mad trying to eject CD's especially from non-apple
> CD-Rom drives.

Use the unmount and eject routine from MoreFiles, available at
<http://members.aol.com/jumplong>

0 new messages