Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!hsdndev!dartvax!Eric.J.Baumgartner From: Eric.J.Baumgartner@dartmouth.edu (Eric J. Baumgartner) Newsgroups: comp.sys.mac.programmer Subject: Re: Objects in Code Resources - HELP! Message-ID: <1991May22.173738.6863@dartvax.dartmouth.edu> Date: 22 May 91 17:37:38 GMT References: <1991May22.011618.27337@terminator.cc.umich.edu> Sender: news@dartvax.dartmouth.edu (The News Manager) Organization: Dartmouth College, Hanover, NH Lines: 69 In article <1991May22.011618.27337@terminator.cc.umich.edu> potts@itl.itd.umich.edu (Paul Potts) writes: > It all works great, when these objects are built into an > application, with a simple front end that uses the C console > window to ask for commands and pass them to CDispatcher. > I've been doing this, though, in the hopes that I could > eventually use this object heirarchy in an XCMD/XFCN setting. I'm using oops in a THINK C XCMD and there are definitely a couple of tricks; I think I've solved them. First off, the XCMD has to be multi-segment to use oops. This isn't really a big deal until your HC users decide to copy it into their stack... then they'll probably forget the CCOD resource. (THINK C creates 1 XCMD resource and as many CCOD resources as are necessary, and I assume the ID's of both the XCMD and the CCOD are important and shouldn't be changed.) So be sure to warn 'em. That's multi-segment. The other thing you've gotta do is the old "preserve A4" trick, like you used to do to use strings in THINK C 3.x, because when you go multi-segment, THINK starts storing strings as globals again. (p. 87 in the manual) (The method table is probably tucked away like the strings as well, so you need to save A4 to access those values too. Symantec people, please correct me as needed.) So my main routine looks like this: #include #include pascal void main(XCmdPtr paramPtr) { RememberA0(); SetUpA4(); /* Do your stuff here. This is a xwindow for HC 2.x, so paramCount may be negative. */ if (paramPtr->paramCount == -1) { DoMacEvent(paramPtr); } else if (paramPtr->paramCount > -1) { DoFirstTime(paramPtr); } /* We're multi-segment, so be careful. */ /*UnloadA4Seg(0L);*/ /* If HC tries to keep us around, this is a bad thing. */ /* Maybe jump dump the CCOD resource??? */ RestoreA4(); } So you set up A4 prior to doing anything else, and restore it at the end, and you're fine. Your object files and method calls don't need to worry about A4 at all. The THINK manual mentions (p. 91) that you've got to unload additional segments yourself, but I left the call commented out because I'm trusting HyperCard to manage the resources. This may be a bad thing; I'm not sure, but nothing's broken yet, so I'm not going to change... but if anyone knows for sure whether I should uncomment the UnloadA4Seg call, I'd appreciate a note. Hope this helps. Eric Baumgartner * ebaum@dartmouth.edu Interactive Media Lab * - When in danger or in doubt, Dartmouth Medical School * run in circles, scream and shout.