[comp.sys.mac.programmer] THINK C and SFGetFile w/FSOpen

chuck@umiami.miami.edu (07/12/90)

Hello folx.

I'm working with THINK C 4.0.2.  I'm trying to do a simple SFGetFile and 
FSOpen procedure to open up a file so I can do some processing.  For some
reason, it seems that the SFGetFile is getting a bad address, and I get a
system bomb when FSOpen is called.  Any ideas?  Check out my code below.
By the way, the SFGetFile dialog box comes up, and myWindow shows up, too.
Everything points to a problem with either where reply points to, or a problem
with the way I'm handling FSOpen.


..
{
Point where;
SFReply *reply;
int sourceFile;

where.v=100;
where.h=100;
SFGetFile(where," ",0L,0,'',0L,&reply);
myWindow=GetNewWindow(314,0L,-1L);
ShowWindow(myWindow);
SetPort(myWindow);
MoveTo(30,30);
if (FSOpen((*reply).fName,(*reply).vRefNum,&sourceFile)!=noErr)
   DrawString("\pCan't FSOpen File.");
else
   DrawString("\pFSOpening file.");
FSClose(sourceFile);
}
(I hope there's no typos in this!!! :-) )
-- 
===========================================================================
   Chuck Urwiler    University of Miami Music Engineering   Voice & Keys  
 chuck@umiami              | 
 e1mvqi9z@umiamivm         | Go ahead, I DARE you to mail me something...
 chuck@umiami.miami.edu    |
 chuck@miavax.ir.miami.edu |
===========================================================================
Disclaimer: I only work and learn at this University. I don't speak for it!

puklich@plains.UUCP (Blayne Puklich) (07/13/90)

chuck@umiami.miami.edu wrote in article THINK C and SFGetFile w/FSOpen:
>I'm working with THINK C 4.0.2.  I'm trying to do a simple SFGetFile and
>FSOpen procedure to open up a file so I can do some processing.  For some
>reason, it seems that the SFGetFile is getting a bad address, and I get a
>system bomb when FSOpen is called.  Any ideas?  Check out my code below.
[stuff deleted]
>SFReply *reply;
         ^
There's your problem.

>SFGetFile(where," ",0L,0,'',0L,&reply);
                                ^
The SFReply you have declared is a pointer to an SFReply struct, not an
actual SFReply struct on the stack.  So, &reply means the address of the
SFReply pointer on the stack, which you haven't allocated.  What you may want
to do is change the declaration to SFReply reply, and then the SFGetFile()
call will work just fine.

Hope this helps.

||+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++||
|| Blayne Puklich    puklich@Plains.NoDak.EDU "I think I'm going bald..."  ||
|| NDSU, Fargo, ND   (701) 237-4408            -- Rush, Caress of Steel,   ||
||                                                1975                     ||
||-------------------------------------------------------------------------||

keith@Apple.COM (Keith Rollin) (07/13/90)

In article <6533.269b32ac@umiami.miami.edu> chuck@umiami.miami.edu writes:
>Hello folx.
>
>I'm working with THINK C 4.0.2.  I'm trying to do a simple SFGetFile and 
>FSOpen procedure to open up a file so I can do some processing.  For some
>reason, it seems that the SFGetFile is getting a bad address, and I get a
>system bomb when FSOpen is called.  Any ideas?  Check out my code below.
>By the way, the SFGetFile dialog box comes up, and myWindow shows up, too.
>Everything points to a problem with either where reply points to, or a problem
>with the way I'm handling FSOpen.
>
>where.v=100;
>where.h=100;
>SFGetFile(where," ",0L,0,'',0L,&reply);

I think there are at least 3 problems with this call:

1) for a prompt string, you are passing a pointer to a C string with one
character in it; a space. You should really be passing a Pascal string: "\p".

2) you are passing 0 for numTypes. This is an invalid value. If you don't
want to specify any types, pass a -1. This is documented in Inside Mac.

3) you are passing '' where you should be passing a pointer to a typeList. In
C, I think it should be OK to specify *(SFTypeList *)0L if you don't have
a typelist that will be used.

-- 
------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc.  ---  Developer Technical Support
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions