Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ames!apple!rdclark From: rdclark@Apple.COM (Richard Clark) Newsgroups: comp.sys.mac.programmer Subject: Re: SFGetFile Message-ID: <39665@apple.Apple.COM> Date: 20 Mar 90 07:56:40 GMT References: <3830@sage.cc.purdue.edu> Organization: Apple Computer Inc, Cupertino, CA Lines: 48 In article <3830@sage.cc.purdue.edu> ar4@sage.cc.purdue.edu (Piper Keairnes) writes: >Got a problem folks... what's wrong with this simple code??? > >int handleDialog(theItem, dp) >int theItem; >DialogPtr dp; >{ > return(theItem); >} > >GetDir() >{ > Point where = {80,80}; > SFReply reply; > ProcPtr ppr = handleDialog; > > SFPGetFile(where, NIL, NIL, 1, "", ppr, &reply, GET_DIALOG, NIL); >} > OK, we'll take it from the top. First, C passes paramaters and function results in a different way than Pascal (C reverses the order of the parms, and uses register D0 for function results (Pascal uses the stack.)) The simple fix for this is to use the "pascal" keyword thusly: pascal int handleDialog(int theItem, DialogPtr dp) The reason you have to do this is that the Toolbox uses the Pascal calling conventions, and expects callback/filter routines to do the same. Another (potential) problem is the use of "int". Pascal INTEGERs are 16 bits. C integers are 16 or 32 bits on the Macintosh depending on which C compiler you use (THINK C: 16 bits; MPW C: 32 bits.) For this reason, you should use "short" which is _always_ 16 bits. Now, on to the SFP statement. For the TypeList, you really do have to declare a variable of SFTypeList and fill in 1 (or more) of the fields, then pass the address of that structure. If you want "all files", then pass 0 for the type count and NIL for the pointer to the type list. Hope this helps. -- -----------------------------+----------------------------------------------- Richard Clark | "If you don't know where you're going, Instructor/Designer | don't go there" -- Sybalski's Law Apple Developer University +----------------------------------------------- AppleLink, GEnie, Delphi, MCI, Internet: rdclark CI$: 71401, 2071