• MacTech Network:
  • Tech Support
  • |
  • MacForge.net
  • |
  • Apple News
  • |
  • Register Domains
  • |
  • SSL Certificates
  • |
  • iPod Deals
  • |
  • Mac Deals
  • |
  • Mac Book Shelf

MAC TECH

  • Home
  • Magazine
    • About MacTech in Print
    • Issue Table of Contents
    • Subscribe
    • Risk Free Sample
    • Back Issues
    • MacTech DVD
  • Archives
    • MacTech Print Archives
    • MacMod
    • MacTutor
    • FrameWorks
    • develop
  • Forums
  • News
    • MacTech News
    • MacTech Blog
    • MacTech Reviews and KoolTools
    • Whitepapers, Screencasts, Videos and Books
    • News Scanner
    • Rumors Scanner
    • Documentation Scanner
    • Submit News or PR
    • MacTech News List
  • Store
  • Apple Expo
    • by Category
    • by Company
    • by Product
  • Job Board
  • Editorial
    • Submit News or PR
    • Writer's Kit
    • Editorial Staff
    • Editorial Calendar
  • Advertising
    • Benefits of MacTech
    • Mechanicals and Submission
    • Dates and Deadlines
    • Submit Apple Expo Entry
  • User
    • Register for Ongoing Raffles
    • Register new user
    • Edit User Settings
    • Logout
  • Contact
    • Customer Service
    • Webmaster Feedback
    • Submit News or PR
    • Suggest an article
  • Connect Tools
    • MacTech Live Podcast
    • RSS Feeds
    • Twitter

ADVERTISEMENT
Volume Number:11
Issue Number:7
Column Tag:Tips & Tidbits

Tips & Tidbits

By Neil Ticktin, Editor-in-Chief with special thanks to Steve Sisak

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

TIP OF THE MONTH

Tag Your PowerPC Code
With a Call To _eieio()

When disassembling PowerPC code with CodeWarrior, it isn’t always easy to find the instructions associated with a given set of C statements. Putting in call like Debugger(); can turn a leaf routine into a trunk.

If you use the CodeWarrior intrinsic __eieio(), this is no April Fools joke, it will add the eieio instruction to the stream. Wrap your statements in this and moo. Also, it is fairly benign to accidentally execute.

Chris Sears
sears@netcom.com

Load Extensions After Boot-Time.

This is a cool hack to load Extensions without restarting the Mac. It is the main part of my Freeware utility LoadADrive 1.1, that can load a CD-ROM Driver after the Mac has been started. (You can mount CDs without restarting your Mac if you haven’t switched on your CD-ROM Drive at boot time. Works with System 7.x and even PowerMacs)

I also use this code to debug Extensions. It is anoying to reboot the mac all the time. With this code as the main part of a small application and a good Debugger (I use Jasik’s The Debugger) you can easily check the loading of the Extension.

I tested this code with some other Extensions and it works fine. Of course, this simple version will definitly not work with most Extensions, but you can improve the code to handle special situations.

Maybe someone, who has more free time than I have, will even develop an Uninstaller for Extension. You have to keep track of all patches, allocated memory, changes in Low Memory and so on. (not easy, I know :-)

I just want to demonstrate that it is NOT impossible to load Extensions after boot time.

Dieter Spaar
Friedberg, Germany

Boolean LoadInit(FSSpecPtr extensionFSSpec)
{
    short refNum, ret;
    Handle hdl;

    // Open resource fork

    refNum = FSpOpenResFile(extensionFSSpec, fsCurPerm);
    if(refNum == -1 || ResError() != noErr)
      return FALSE; // Cannot open file

    // Load INIT into System Zone

    SetZone(SystemZone()); // Set zone to system zone
    hdl = Get1IndResource(‘INIT’,1);
    if(hdl == 0) {
      SetZone(ApplicZone());
 CloseResFile(refNum);
 return FALSE; // Cannot load INIT from driver
    }

    HLock(hdl); // lock the resource
    HNoPurge(hdl);

    // Call INIT, we don’t handle the return value ret here

    ret = (*(short(*)())(*hdl))(); // Looks nice, doesn’t it ;-)

     // Is it still a resource ? (don’t unlock if detached)
     // Some INIT’s detach the resource to keep the INIT’s memory block

    if(HGetState(hdl) & 0x20)
    {
        HUnlock(hdl);
        ReleaseResource(hdl);
    }

    SetZone(ApplicZone()); // Back to application zone
    CloseResFile(refNum); // Close the resource file

    // Redraw desktop (Extension may draw startup icon)

    PaintOne(nil, GetGrayRgn());

    return TRUE;
}

...And Thus Spake the App, “Another Bug!”

Have a piece of code that hard to debug with the debugger? Trying to debug a code resource? Usually a quick and dirty solution is to put in a bunch of SysBeep(10) calls to get an idea of where your code is at. However, you can use Apple’s Speech Manager in a similar fashion and get a much better “speak-out”. Here’s how:

Include SpeakIt.c to your project. (The code is included on the disk, and at the usual online places.) Include SpeakIt.h in all the files you want to have any debug statements spoken. In SpeakIt.h is the macro DebugSpeech. Define it like “#define DebugSpeech 1” when you want to use the speech debugger, and comment it out when you don’t want to use it. Within the code you want to debug, call the speech debugger by adding code like this example:

#ifdef DebugSpeech
    CheckSpeechMgr();   // should be called once in your initialization code
#endif

. code ...

#ifdef DebugSpeech
    SpeakIt( “Before while loop.”, true );
#endif

. more code ...

#ifdef DebugSpeech
    SpeakIt( “Made it through the while loop.”, true );
#endif

. and more code ...

#ifdef DebugSpeech
    SpeakIt( “Right before bringing up main window.”, true );
#endif


Cool!

Bill Modesitt
billm@maui.com, http://www.maui.com/~billm

 
MacTech Only Search:
Community Search:

 
 
 

 
 
 
 
 
  • SPREAD THE WORD:
  • Slashdot
  • Digg
  • Del.icio.us
  • Reddit
  • Newsvine
  • Generate a short URL for this page:



MacTech Magazine. www.mactech.com
Toll Free 877-MACTECH, Outside US/Canada: 805-494-9797
MacTech is a registered trademark of Xplain Corporation. Xplain, "The journal of Apple technology", Apple Expo, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, Apple Expo, MacTech Central, MacTech Domains, MacNews, MacForge, and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders.
All contents are Copyright 1984-2010 by Xplain Corporation. All rights reserved. Theme designed by Icreon.
 
Nov. 20: Take Control of Syncing Data in Sow Leopard' released
Nov. 19: Cocktail 4.5 (Leopard Edition) released
Nov. 19: macProVideo offers new Cubase tutorials
Nov. 18: S Stardom anounces Safe Capsule, a companion piece for Apple's
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live