[comp.sys.mac.programmer] Calling "OpenDriver" from LightSpeed C

moyman@ecn.purdue.edu (James M Moya) (08/18/90)

This is interesting.  I wrote a simple Device Driver from LSC that simply does
a SysBeep every 2 seconds.  I select the "Build Device Driver" menu item.
I then attach the resources created to an application that just calls 
"Open Driver".  Here is the interesting part:  If the DRVR resource is
0 then everything works fine, you get a SysBeep every 2 seconds.  If you
use an DRVR ID inside the IM range 0-31 other than zero, the driver starts
up but nothing else (the driver Open routine gets called but nothing else).  
If you use a number > 31 I get a -21 error returned from the OpenDriver call.  
Something seems very wrong.  I figured OpenDriver would select a free unit 
number and assign the refnumber accordingly, it doesn't, It always uses the 
DRVR resource ID whether it's being used or not.

I have looked at several DRVR resource in my system, all use numbers like 63,
124, etc... (>31)???  Am I missing something??  Also, shouldn't the driver
continue to run until I call a CloseDriver?? This isn't the case either, It
only runs until I quit the application that called the OpenDriver...Maybe
this behavior is from running the app within the LSC debugger...Any ideas

Mike Moya
Engineering Computer Network
Purdue University

russotto@eng.umd.edu (Matthew T. Russotto) (08/20/90)

In article <1990Aug17.215833.15273@ecn.purdue.edu> moyman@ecn.purdue.edu (James M Moya) writes:
>This is interesting.  I wrote a simple Device Driver from LSC that simply does
>a SysBeep every 2 seconds.  I select the "Build Device Driver" menu item.
>I then attach the resources created to an application that just calls 
>"Open Driver".  Here is the interesting part:  If the DRVR resource is
>0 then everything works fine, you get a SysBeep every 2 seconds.  If you
>use an DRVR ID inside the IM range 0-31 other than zero, the driver starts
>up but nothing else (the driver Open routine gets called but nothing else).  
>If you use a number > 31 I get a -21 error returned from the OpenDriver call.  
>Something seems very wrong.  I figured OpenDriver would select a free unit 
>number and assign the refnumber accordingly, it doesn't, It always uses the 
>DRVR resource ID whether it's being used or not.
Yep.  I think that if you want to assign the unit number dynamically, you
have to do it yourself.

Hey Apple: How about a FindEmptyUnitTableSlot trap?

>I have looked at several DRVR resource in my system, all use numbers like 63,
>124, etc... (>31)???  Am I missing something??  Also, shouldn't the driver
>continue to run until I call a CloseDriver?? This isn't the case either, It
>only runs until I quit the application that called the OpenDriver...Maybe
>this behavior is from running the app within the LSC debugger...Any ideas

Multifinder closes all drivers loaded into the application heap.  If it didn't,
quitting the application would crash the system.
--
Matthew T. Russotto	russotto@eng.umd.edu	russotto@wam.umd.edu
][, ][+, ///, ///+, //e, //c, IIGS, //c+ --- Any questions?