TweetFollow Us on Twitter

Jul 97 - Macintosh Q and A

Volume Number: 13 (1997)
Issue Number: 7
Column Tag: develop

Jul 97 - Macintosh Q & A

by Apple Developer Support Center

Q: FindSymbol returns a paramErr if I pass it a symbol name with a length greater than 64 characters, yet the documentation and interfaces specify that I pass the address of a Str255. What gives?

A: This is a known bug, and has been fixed as of System 7.5.5. You should either make sure the System version is 7.5.5 or later, or keep your symbol name lengths to 64 or fewer characters.


Q: Any time I try to load a shared library that has a nonzero implementation version number with GetSharedLibrary, CFM returns a fragTooNew error. Why?

A: This is a bug in CFM that was fixed in System 7.5.5. If you need a nonzero implementation version number, you'll have to be sure to run only on System 7.5.5 or later. Otherwise, make your library's implementation version number 0.


Q: I've been reading the documentation on the Resource Manager and I can't seem to find an unequivocal statement about whether resource IDs should be unique within a single resource type in a given resource file. Some documentation seems to suggest it's OK to have duplicate resource IDs as long as my program doesn't expect to be able to find resources by ID later. What's the real story?

A: You're right; during a recent extensive survey of our documentation (Inside Macintosh old and new editions, Technotes, and so on), we found that some of the discussions of resource IDs were less than perfectly clear on this topic.

The real story is that resource IDs should be unique within a single resource type within a given resource file. When you're adding resources to a resource file, you might want to use UniqueID or Unique1ID to help you find unique resource IDs.

However, some resource files do contain multiple resources with the same type and ID. This can be due to bugs in the program that created the file or to the aforementioned ambiguity in the documentation. When reading resource files your program didn't create, make sure you can gracefully handle such files.

Regardless of what you may read in other documentation, the Resource Manager in some versions of the Mac OS may behave unpredictably when reading files that have multiple resources with the same type and ID.

One easy way to detect whether a given file contains multiple resources with the same type and ID is to open the file with Resorcerer or ResEdit. These programs will warn you if they detect this condition.


Q: What's the logic behind the Create/Update preview behavior in the SFPGetFilePreview dialog? If I create previews for QuickTime movies I sometimes get preview movies and sometimes get preview pictures. With QuickTime movies that already have previews I sometimes get an Update button and sometimes get a dimmed Create button. What determines the behavior?

A: PICT files (or files that QuickTime can import as PICT via the new graphic import components) don't have durations, so they can only have a preview PICT in the Standard File Preview dialog. Movies can have both a poster PICT and a movie preview.

When a movie or PICT file is selected in the dialog, the preview component will first see if a preview already exists in the file, stored in a 'pnot' resource. The 'pnot' resource also identifies whether the preview is a PICT, a movie, or whatever. The preview component then compares a timestamp in the 'pnot' resource to the modification date of the selected file to see if the preview is current. If the 'pnot' date is older than the last modified date of the file, the dialog will show the Update button (and will create the new preview with the 'pmak' components if the user selects this option).

If no 'pnot' resource is found in the selected file, and a 'pmak' component exists that can create a preview for the selected file type (QuickTime 2.5 supplies PICT, MOOV, and QTIF 'pmak' components), the Create button will be active in the dialog.

Note that sound files preview in a slightly different way. The 'pnot' components create an automatic 10-second preview (if there's that much sound) for supported sound file types without needing a 'pnot' resource in the file.

You can read more about preview components in Inside Macintosh:QuickTime Components.


Q: I've saved files to disk in both foreground and background printing modes with LaserWriter 8.4.1, and the file size is always the same. I'd expect the size of the background image to be smaller as a result of compression and two-pass optimizations. Why don't I get different-size PostScript files?

A: LaserWriter 8.4 (and all other 8.x versions) always saves to disk in two passes, hence the foreground and background files you see are the same size. If we didn't do this, we would generate non-DSC compliant PostScript jobs when saving to disk in the foreground. If you really want to check the PostScript code being sent to the printer, you should turn on the papToDisk bit in the driver's 'PRFS' resource. This creates papToDisk files that capture the data going to and coming from the printer.


Q: I'm trying to find a way for my application to determine whether it's using a PostScript printer. For performance reasons, I'd like to send custom PostScript code instead of a PICT to the printer if I can. Is there an API to find out whether the currently selected printer is a PostScript printer?

A: There's no good way of doing this. For Apple's LaserWriter drivers, you can, if you must, look at the wDev field in the print record of the currently selected printer. Here's a quote that's hidden in Technote QD 10, "Picture Comments - The Real Deal":

The high byte of the prStl.wDev field of the print record identifies a printer driver species; a value of $03 tells you that the printer driver belongs to the PostScript LaserWriter driver ancestry...

However, although the Apple LaserWriter driver has a wDev of 3, other printer drivers for PostScript devices may not, so this is not a complete solution for detecting PostScript printers. Further, it's not recommended that you use the wDev field to distinguish between printer drivers at all; see the Print Hints column in this issue of develop for more on this.


Q: I'm using the code from page 4-16 of Inside Macintosh: Processes to animate the cursor at VBL time, but it crashed (with the stack crawl indicating SetCursor as the culprit). What's up?

A: When hardware cursor support was added to the Mac OS (System 7.5.2 for PCI Power Macs), SetCursor started requiring A5 to refer to a valid QuickDraw globals world. Despite the fact that the code you refer to accesses no global variables, your application still needs to make sure A5 is set up for SetCursor's benefit.

An explanation of setting up A5 in a VBL task can be found on page 4-13 of Inside Macintosh: Processes.


Q: We're writing an application that requires us to connect to a remote machine via TCP/IP and talk to a background application running on that machine. However, we cannot connect to that machine when it's in sleep mode. Is there a way to keep the network services alive when a machine is in sleep mode? I've seen how you can keep the serial port alive, but not the network services.

A: When a Macintosh (usually a PowerBook) goes into the "sleep" state, it's incapable of responding to network requests; the connections actually shut down. There are some Macintosh computers, however, that will attempt to go into an energy-efficient mode know as "doze."

The sleep state is easy to prevent and is pretty well documented in the Power Manager chapter of Inside Macintosh: Devices under "The Sleep Queue" and "Sleep Procedures," and there's more information in Technote 1046, "Inside Macintosh: Devices - Power Manager Addenda," and Technote 1086, "Power Management & The Energy Saver API."

If you want to prevent the system from sleeping or dozing, you should do the following:

  1. Allocate a SleepQRec (preferably in the system heap).
  2. Set it up to call into your sleep handler.
  3. Return a nonzero value from your sleep handler when it's called. (When the Macintosh attempts to sleep or doze, your sleep handler is called with a sleepRequest or dozeRequest selector.)

In the doze state, Open Transport networking is still enabled and TCP connections that are set up should still function. But it might take several packets received within a short period (try 10 per second) to wake the machine from its doze state. You might also consider pinging the machine first to get it out of the doze state. Either way, if the machine is dozing it will take some time for the networking to reactivate, especially if virtual memory is enabled and the disk drive must spin up.


Q: I'm writing a fax client-server system and I've encountered a problem after I put the server to sleep: on waking, the server software doesn't seem to reregister on the network (using RegisterMyName). On the client side, when receiving a sleep demand I wait until network activity has ceased, then return control to the system; the client wakes and reconnects to the server with no problems. What action should I take to correct the reregistering problem?

A: In general, you might want to disable sleep on your server by informing the Power Manager with AutoSleepControl(false). Otherwise, the clients might never know that your server is sleeping, and they'll be unable to connect. But if you do want to support sleep, a server should install a sleep procedure through the Power Manager using SleepQInstall.

The exact details of how your server should handle sleep requests and sleep demands are provided in Table 6-1 on page 6-10 of Inside Macintosh: Devices. Ultimately, you close and deregister your server from the network. Later, when you get the sleepWakeUp call, you should reopen and reregister.


Q: I installed a sleep procedure, but the Power Manager will issue a sleep demand if the user selects Sleep from the Special menu. The AutoSleepControl(false) call will stop sleep requests but will it also stop sleep demands?

A: Your application cannot refuse a sleep demand, as documented in Inside Macintosh: Devices on page 6-11:

When your sleep procedure receives a sleep demand, however, your procedure has no way to determine whether it originated as a conditional sleep demand or an unconditional sleep demand. Your device driver or application must prepare for the sleep state and return control promptly to the Power Manager when it receives a sleep demand.

For AutoSleepControl, see Inside Macintosh: Devices, page 6-44:

When enableSleep is set to false, the computer will not go into the sleep mode unless it is forced to either by some user action - for example, by the user's selecting Sleep from the Special menu of the Finder - or in a low battery situation.


Q: How do I specify and control Open Transport serial port I/O handshaking? The options are a bit confusing.

A: By using the SRL_OPT_HANDSHAKE option provided by the Open Transport native interfaces, you can customize serial port handshaking in a variety of ways. For instance, you can request that input handshaking be controlled by the CTS line or by the XON/OFF sequence. The default value of this option is no handshaking.

The handshaking behavior is specified by a 4-byte unsigned integer value that's passed in with the SRL_OPT_HANDSHAKE option. The high word (16 bits) of the integer is a bitmap with one or more of the following bits set:

kOTSerialXOnOffInputHandshake       = 1
kOTSerialXOnOffOutputHandshake      = 2
kOTSerialCTSInputHandshake          = 4
kOTSerialDTROutputHandshake         = 8

The second lowest byte is the XON character value, and the lowest byte is the XOFF character value. If these values are 0, and XON/XOFF handshaking was requested, the default values of Control-S for XOFF and Control-Q for XON will be used.

An inline function (or a macro, for C users) is defined in OpenTptSerial.h for creating this 4-byte value:

OTSerialHandshakeData(UInt16 type, UInt8 onChar, UInt8 offChar)

Suppose, for instance, that you wanted to enable XON/XOFF input handshaking, but you wanted to specify that the XON character be Control-T instead of Control-Q. You would create an option structure as follows:

TOption 		opt;
opt.len = kOTFourByteOptionSize;
opt.level = XTI_GENERIC;
opt.name = SERIAL_OPT_HANDSHAKE;
opt.value =
OTSerialHandshakeData(kOTSerialXOnOffInputHandshake, 
	('T' & ~0x40),		// normally kOTSerialDefaultOnChar
	kOTSerialDefaultOffChar);

You can also control the XOFF state of the serial input port, by using the I_SetSerialXOFFState Ioctl command. A value of 0 will unconditionally clear the XOFF state, while a value of 1 will unconditionally set it:

// Set XOFF state.
OTIoctl(theSerialEndpoint, I_SetSerialXOffState, 1);

The I_SetSerialXOn Ioctl command causes the serial port to send an XON character. A value of 0 will cause it to be sent only if we're in the XOFF state, while a value of 1 will unconditionally send the character:

// Unconditionally send an XON character.
OTIoctl(theSerialEndpoint, I_SetSerialXOn, 1);

Conversely, the I_SetSerialXOFF Ioctl command causes the serial port to send an XOFF character. A value of 0 will cause it to be sent only if we're in the XON state, while a value of 1 will unconditionally send the character:

// Unconditionally send an XOFF character.
OTIoctl(theSerialEndpoint, I_SetSerialXOff, 1);

Q: A friend told me you can make really great water rockets from plastic pop bottles. Is this true?

A: Boy , howdy, is it ever! To give you an idea of how great they are, read the article "Soda Bottle Water Rockets" in Physics Teacher magazine, March 1995. Some interesting results from the article: If you launch a plain 2-liter bottle, filled with 0.7 liters of water (about 1/3 full turns out to be optimal) and pumped to 85 pounds per square inch, all the water is expelled in 0.07 seconds. At that point ("burnout") the bottle is only about 2 meters off the ground but is traveling at an incredible 76 meters per second (171 miles per hour)! That's an average acceleration of over 100 g's!

Of course, a naked bottle is aerodynamically hopeless, and tumbles fluffily after burnout. But if you add fins and some nose weight to make a stable rocket out of it, truly impressive altitudes are possible. A velocity-sensitive parachute deployment device has recently been concocted, bottle connection technology is advancing rapidly, and reliable multistage rockets are an active topic of investigation. Launching techniques range from the ultra-simple "cram a cork in it and pump 'til it blows" method to sophisticated, expensive launchers with all the bells and whistles.

For more information, see these Web sites: http://members.aol.com/aquarocket/, http://www.H2ORocket.com/, and http://www.flash.net/~berggren/rocket/.


Q: If my Web server is running along happily under Open Transport (1.1 or 1.1.1), and the listener is bound to address 0.0.0.0, what happens when someone uses the control panel and changes the IP number? Right now it appears to just make the listener go deaf. I don't appear to receive connections on the new IP number, and if I use the control panel a second time to switch back to the original IP number, I don't get connections for that IP number either. Is there some event that gets sent to the listener that I'm not looking for that tells me when this happens?

A: When a port changes its IP number, it's actually closing and reopening. When Open Transport closes a port, any endpoint that's plumbed to it is also closed, hence you'll get no further events on that endpoint.

The first thing you need to do is check for the provider events such as kOTProviderWillClose and kOTProviderIsClosed.

You should also use the OTRegisterAsClient call and register a notifier for client events, such as kOTPortDisabled, kOTPortEnabled, kOTPortOffline, kOTPortOnline, kOTClosePortRequest, kOTYieldPortRequest, and kOTNewPortRegistered.

When the interface changes, you need to close up your endpoints and rebind them.


These answers are supplied by the technical gurus in Apple's Developer Support Center. For more answers, see the Macintosh Technical Q&As on the World Wide Web at http://dev.info.apple.com/techqa/Main.html.

 
AAPL
$99.76
Apple Inc.
+2.09
MSFT
$44.08
Microsoft Corpora
+0.45
GOOG
$520.84
Google Inc.
+9.67

MacTech Search:
Community Search:

Software Updates via MacUpdate

Macgo Blu-ray Player 2.10.9.1750 - Blu-r...
Macgo Mac Blu-ray Player can bring you the most unforgettable Blu-ray experience on your Mac. Overview Macgo Mac Blu-ray Player can satisfy just about every need you could possibly have in a Blu-ray... Read more
Apple iOS 8.1 - The latest version of Ap...
The latest version of iOS can be downloaded through iTunes. Apple iOS 8 comes with big updates to apps you use every day, like Messages and Photos. A whole new way to share content with your family.... Read more
TechTool Pro 7.0.5 - Hard drive and syst...
TechTool Pro is now 7, and this is the most advanced version of the acclaimed Macintosh troubleshooting utility created in its 20-year history. Micromat has redeveloped TechTool Pro 7 to be fully 64... Read more
PDFKey Pro 4.0.2 - Edit and print passwo...
PDFKey Pro can unlock PDF documents protected for printing and copying when you've forgotten your password. It can now also protect your PDF files with a password to prevent unauthorized access and/... Read more
Yasu 2.9.1 - System maintenance app; per...
Yasu was originally created with System Administrators who service large groups of workstations in mind, Yasu (Yet Another System Utility) was made to do a specific group of maintenance tasks... Read more
Hazel 3.3 - Create rules for organizing...
Hazel is your personal housekeeper, organizing and cleaning folders based on rules you define. Hazel can also manage your trash and uninstall your applications. Organize your files using a... Read more
Autopano Giga 3.7 - Stitch multiple imag...
Autopano Giga allows you to stitch 2, 20, or 2,000 images. Version 3.0 integrates impressive new features that will definitely make you adopt Autopano Pro or Autopano Giga: Choose between 9... Read more
MenuMeters 1.8 - CPU, memory, disk, and...
MenuMeters is a set of CPU, memory, disk, and network monitoring tools for Mac OS X. Although there are numerous other programs which do the same thing, none had quite the feature set I was looking... Read more
Coda 2.5 - One-window Web development su...
Coda is a powerful Web editor that puts everything in one place. An editor. Terminal. CSS. Files. With Coda 2, we went beyond expectations. With loads of new, much-requested features, a few... Read more
Arq 4.6.1 - Online backup to Google Driv...
Arq is super-easy online backup for the Mac. Back up to your own Google Drive storage (15GB free storage), your own Amazon Glacier ($.01/GB per month storage) or S3, or any SFTP server. Arq backs up... Read more

Latest Forum Discussions

See All

This Week at 148Apps: October 13-17, 201...
Expert App Reviewers   So little time and so very many apps. What’s a poor iPhone/iPad lover to do? Fortunately, 148Apps is here to give you the rundown on the latest and greatest releases. And we even have a tremendous back catalog of reviews; just... | Read more »
Angry Birds Transformers Review
Angry Birds Transformers Review By Jennifer Allen on October 20th, 2014 Our Rating: :: TRANSFORMED BIRDSUniversal App - Designed for iPhone and iPad Transformed in a way you wouldn’t expect, Angry Birds Transformers is a quite... | Read more »
GAMEVIL Announces the Upcoming Launch of...
GAMEVIL Announces the Upcoming Launch of Mark of the Dragon Posted by Jessica Fisher on October 20th, 2014 [ permalink ] Mark of the Dragon, by GAMEVIL, put | Read more »
Interview With the Angry Birds Transform...
Angry Birds Transformers recently transformed and rolled out worldwide. This run-and-gun title is a hit with young Transformers fans, but the ample references to classic Transformers fandom has also earned it a place in the hearts of long-time... | Read more »
Find Free Food on Campus with Ypay
Find Free Food on Campus with Ypay Posted by Jessica Fisher on October 20th, 2014 [ permalink ] iPhone App - Designed for the iPhone, compatible with the iPad | Read more »
Strung Along Review
Strung Along Review By Jordan Minor on October 20th, 2014 Our Rating: :: GOT NO STRINGSUniversal App - Designed for iPhone and iPad A cool gimmick and a great art style keep Strung Along from completely falling apart.   | Read more »
P2P file transferring app Send Anywhere...
File sharing services like Dropbox have security issues. Email attachments can be problematic when it comes to sharing large files. USB dongles don’t fit into your phone. Send Anywhere, a peer-to-peer file transferring application, solves all of... | Read more »
Zero Age Review
Zero Age Review By Jordan Minor on October 20th, 2014 Our Rating: :: MORE THAN ZEROiPad Only App - Designed for the iPad With its mind-bending puzzles and spellbinding visuals, Zero Age has it all.   | Read more »
Hay Ewe Review
Hay Ewe Review By Campbell Bird on October 20th, 2014 Our Rating: :: SAVE YOUR SHEEPLEUniversal App - Designed for iPhone and iPad Pave the way for your flock in this line drawing puzzle game from the creators of Worms.   | Read more »
My Very Hungry Caterpillar (Education)
My Very Hungry Caterpillar 1.0.0 Device: iOS Universal Category: Education Price: $3.99, Version: 1.0.0 (iTunes) Description: Care for your very own Very Hungry Caterpillar! My Very Hungry Caterpillar will captivate you as he crawls... | Read more »

Price Scanner via MacPrices.net

2013 15-inch 2.0GHz Retina MacBook Pro availa...
B&H Photo has leftover previous-generation 15″ 2.0GHz Retina MacBook Pros now available for $1599 including free shipping plus NY sales tax only. Their price is $400 off original MSRP. B&H... Read more
Updated iPad Prices
We’ve updated our iPad Air Price Tracker and our iPad mini Price Tracker with the latest information on prices and availability from Apple and other resellers, including the new iPad Air 2 and the... Read more
Apple Pay Available to Millions of Visa Cardh...
Visa Inc. brings secure, convenient payments to iPad Air 2 and iPad mini 3as well as iPhone 6 and 6 Plus. Starting October 20th, eligible Visa cardholders in the U.S. will be able to use Apple Pay,... Read more
Textkraft Pocket – the missing TextEdit for i...
infovole GmbH has announced the release and immediate availability of Textkraft Pocket 1.0, a professional text editor and note taking app for Apple’s iPhone. In March 2014 rumors were all about... Read more
C Spire to offer iPad Air 2 and iPad mini 3,...
C Spire on Friday announced that it will offer iPad Air 2 and iPad mini 3, both with Wi-Fi + Cellular, on its 4G+ LTE network in the coming weeks. C Spire will offer the new iPads with a range of... Read more
Belkin Announces Full Line of Keyboards and C...
Belkin International has unveiled a new lineup of keyboard cases and accessories for Apple’s newest iPads, featuring three QODE keyboards and a collection of thin, lightweight folios for both the... Read more
Verizon offers new iPad Air 2 preorders for $...
Verizon Wireless is accepting preorders for the new iPad Air 2, cellular models, for $100 off MSRP with a 2-year service agreement: - 16GB iPad Air 2 WiFi + Cellular: $529.99 - 64GB iPad Air 2 WiFi... Read more
Price drops on refurbished Mac minis, now ava...
The Apple Store has dropped prices on Apple Certified Refurbished previous-generation Mac minis, with models now available starting at $419. Apple’s one-year warranty is included with each mini, and... Read more
Apple refurbished 2014 MacBook Airs available...
The Apple Store has Apple Certified Refurbished 2014 MacBook Airs available for up to $180 off the cost of new models. An Apple one-year warranty is included with each MacBook, and shipping is free.... Read more
Refurbished 2013 MacBook Pros available for u...
The Apple Store has Apple Certified Refurbished 13″ and 15″ MacBook Pros available starting at $929. Apple’s one-year warranty is standard, and shipping is free: - 13″ 2.5GHz MacBook Pros (4GB RAM/... Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
Position Opening at *Apple* - Apple (United...
…customers purchase our products, you're the one who helps them get more out of their new Apple technology. Your day in the Apple Store is filled with a range of Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** At the Apple Store, you connect business professionals and entrepreneurs with the tools they need in order to put Apple solutions to work in their Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** The Apple Store is a retail environment like no other - uniquely focused on delivering amazing customer experiences. As an Expert, you introduce people Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** As businesses discover the power of Apple computers and mobile devices, it's your job - as a Solutions Engineer - to show them how to introduce these Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.