[comp.sys.mac.programmer] GetRsrc strange in LSP

mnkonar@manyjars.SRC.Honeywell.COM (Murat N. Konar) (06/21/89)

I'm having trouble with a WDEF I'm writing in LSP.
                                                   
The problem is that I'm trynig to do a GetResource
whenever I enter the WDEF.  It works fine for all
WDEF messages except wHit.  Then GetResource
returns a nil handle but resError = noErr. (!)

I suspect this is the LSP environment at work since
it seems to work okay when compiled to an application
and run from the finder.

I know that you cannot have the debug flag set for
units called by the WDEF so this is not my problem.

I'm trying to work around this by storing a handle
to my resource in the dataHandle of a windowRecord
during the wInit message, but this is a suboptimal 
solution.

Any help is very much appreciated.
____________________________________________________________________
Have a day. :^|
Murat N. Konar        Honeywell Systems & Research Center, Camden, MN
mnkonar@SRC.honeywell.com (internet) {umn-cs,ems,bthpyd}!srcsip!mnkonar(UUCP)

keith@Apple.COM (Keith Rollin) (06/22/89)

In article <24302@srcsip.UUCP> mnkonar@src.honeywell.com (Murat N. Konar) writes:
>I'm having trouble with a WDEF I'm writing in LSP.
>                                                   
>The problem is that I'm trynig to do a GetResource
>whenever I enter the WDEF.  It works fine for all
>WDEF messages except wHit.  Then GetResource
>returns a nil handle but resError = noErr. (!)
>
>I suspect this is the LSP environment at work since
>it seems to work okay when compiled to an application
>and run from the finder.
>

I don't know why you aren't finding your resource, but the fact that the 
Resource Manager is returning "noErr" was a deliberate "feature". I honestly 
don't know why it does this, but the Resource Manager intentionally doesn't 
set ResError to resNotFound if it can't find the resource on a Get(1)Resource 
call. To add to the bizarreness of it all, Get(1)NamedResource DOES set 
ResError.

------------------------------------------------------------------------------
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

mnkonar@gorby.SRC.Honeywell.COM (Murat N. Konar) (06/22/89)

In article <32576@apple.Apple.COM> keith@Apple.COM (Keith Rollin) writes:
>
>I don't know why you aren't finding your resource, but the fact that the 
>Resource Manager is returning "noErr" was a deliberate "feature". I honestly 
>don't know why it does this, but the Resource Manager intentionally doesn't 
>set ResError to resNotFound if it can't find the resource on a Get(1)Resource 
>call. To add to the bizarreness of it all, Get(1)NamedResource DOES set 
>ResError.


Do you mean that any time I call GetResource and GetResource fails to find
the resource I want, resErr=0?  Or only inside WDEFs (or anyDEFs for that 
matter)  Wow, this is weird.  

Is this discussed in a tech-note or somewhere?

Thanks,




____________________________________________________________________
Have a day. :^|
Murat N. Konar        Honeywell Systems & Research Center, Camden, MN
mnkonar@SRC.honeywell.com (internet) {umn-cs,ems,bthpyd}!srcsip!mnkonar(UUCP)

Greg@AppleLink.Apple.Com (Greggy) (06/22/89)

In article <24302@srcsip.UUCP> mnkonar@src.honeywell.com (Murat N. Konar) 
writes:
> Then GetResource
> returns a nil handle but resError = noErr. (!)

GetResource will return a nil handle and set resError=noErr when it can't 
find any resources of the requested type in any open file.  If it sees 
the type you asked for, but can't match the id, then resError=resNotFound.

Hope this helps,

  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  + Greg Marriott               +                    AppleLink: Greg +
  + Just Some Guy               +                                    +
  + "My phone is always busy"   + Internet: Greg@AppleLink.Apple.Com +
  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  + Apple Computer, Inc.                                             +
  + 20525 Mariani Ave, MS-46z, Cupertino, CA  95014                  +
  + (408)974-busy                                                    +
  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

svc@well.UUCP (Leonard Rosenthol) (06/22/89)

> [ problems with GetResource in LSP WDEF ]
>
>I'm trying to work around this by storing a handle
>to my resource in the dataHandle of a windowRecord
>during the wInit message, but this is a suboptimal 
>solution.
>
	Beleive it or not YOU NEED TO DO THIS!  When running on MultiFinder,
and your window gets an update (and your WDEF gets a draw message) from the
foreground you WDEF will get called FROM THE FOREGROUND APPS HEAP!  This means
that your GetResource will probably fail since it won't be able to find your
appl resources that it needs.  I consider this a bug in the window mgr, Apple
tells me its a feature and can't promise to fix it for System 7.0.

-- 
+--------------------------------------------------+
Leonard Rosenthol        |  GEnie : MACgician
Lazerware, inc.          |  MacNet: MACgician
UUCP: svc@well.UUCP      |  ALink : D0025

mnkonar@manyjars.SRC.Honeywell.COM (Murat N. Konar) (06/23/89)

In article <32576@apple.Apple.COM> keith@Apple.COM (Keith Rollin) writes:
>
>I don't know why you aren't finding your resource, but the fact that the 
>Resource Manager is returning "noErr" was a deliberate "feature". I honestly 
>don't know why it does this, but the Resource Manager intentionally doesn't 
>set ResError to resNotFound if it can't find the resource on a Get(1)Resource 
>call. To add to the bizarreness of it all, Get(1)NamedResource DOES set 
>ResError.

Egg is on my face.  I re-read the Resource Manager
chapter in IM and there it was in Black and White.
GetResource returns nil if it can't find the requested
resource. Thanks to Keith Rollin and Greg Marriott of
DTS for their responses.

In case some of you out there in the listening audience
are interested, here's why I wasn't finding my resource: 
LSP sets the current resource file to itself (the 
LSP application) before its "window manager" calls 
the WDEF with a message of wHit.  The solution then 
is to paste your resource into the LSP application 
or the System file (not recommended) so that the 
resource is always available.

This method needs only to be used in the LSP environment;
compiled applications will run fine with resource in 
their own file.


____________________________________________________________________
Have a day. :^|
Murat N. Konar        Honeywell Systems & Research Center, Camden, MN
mnkonar@SRC.honeywell.com (internet) {umn-cs,ems,bthpyd}!srcsip!mnkonar(UUCP)

brecher@well.UUCP (Steve Brecher) (06/23/89)

In article <2445@internal.Apple.COM>, Greg@AppleLink.Apple.Com (Greggy)
writes:

> GetResource will return a nil handle and set resError=noErr when it can't
> find any resources of the requested type in any open file.  If it sees the
> type you asked for, but can't match the id, then resError=resNotFound.

Get[1]Resource will always set resError=noErr if the requested resource is
not found, regardless of whether the requested type exists.  In other words,
Get[1]Resource will never set resError to resNotFound.
-- 

brecher@well.UUCP (Steve Brecher)

mnkonar@manyjars.SRC.Honeywell.COM (Murat N. Konar) (06/24/89)

In article <12322@well.UUCP> svc@well.UUCP (Leonard Rosenthol) writes:
[edited for length]
>> [ problems with GetResource in LSP WDEF worked around by storing
>>  handle to resource in theWindowPeek^.dataHandle]]
>> 

> Beleive it or not YOU NEED TO DO THIS! When running on MultiFinder, (and your 
> WDEF gets a draw message) from the>foreground your WDEF will get called FROM 
> THE FOREGROUND APPS HEAP!  This means>that your GetResource will probably fail 
> since it won't be able to find your appl resources that it needs.  

Unless the resource is loaded into the system heap, right?  Or am
I missing something?
                                                                   



____________________________________________________________________
Have a day. :^|
Murat N. Konar        Honeywell Systems & Research Center, Camden, MN
mnkonar@SRC.honeywell.com (internet) {umn-cs,ems,bthpyd}!srcsip!mnkonar(UUCP)

svc@well.UUCP (Leonard Rosenthol) (06/25/89)

In article <24471@srcsip.UUCP>, mnkonar@manyjars.SRC.Honeywell.COM (Murat N. Konar) writes:
> In article <12322@well.UUCP> svc@well.UUCP (Leonard Rosenthol) writes:
> [edited for length]
> >> [ problems with GetResource in LSP WDEF worked around by storing
> >>  handle to resource in theWindowPeek^.dataHandle]]
> 
>>Beleive it or not YOU NEED TO DO THIS! When running on MultiFinder, (and your 
>>WDEF gets a draw message) from the>foreground your WDEF will get called FROM 
>>THE FOREGROUND APPS HEAP!  This means>that your GetResource will probably fail
>>since it won't be able to find your appl resources that it needs.  
> 
> Unless the resource is loaded into the system heap, right?  Or am
> I missing something?
>
	That's true.  If the resource is loaded into the system heap, then your
WDEF can find it - but you should be VERY careful about resources into the
system heap.  If, for example, your WDEF needed to get at a particular FONT to
use, loading it into the system heap would give users a real headache figuring
why the only saw font 'xxx' in MacWrite SOMETIMES...  The same is true for most
'standard' resource types since there are LOTS of programs which display 
resource lists in one form or another.
	I ran into this problem recently when I needed a WDEF which drew the
window title in a different FONT than the system font.  I ended up using the
refcon to store the FONT resource so that I could get to later on, and that
would seem to be (as discussed earlier) the best method.

-- 
+--------------------------------------------------+
Leonard Rosenthol        |  GEnie : MACgician
Lazerware, inc.          |  MacNet: MACgician
UUCP: svc@well.UUCP      |  ALink : D0025