
FB II Compiler
PG PRO
Debugging
Memory
System
Mathematics
Resources
Disk I/O
Windows
Controls
Menus
Mouse
Keyboard
Text
Fonts
Drawing
Sound
Clipboard
Printing
Communication
ASM
|
MEMORY
Understand the difference between HLOCK and SETRESATTRS
For a long time I have been reading resources and normally making them hang around in memory using the toolbox call "FN HLOCK(Hndl&)". While it seems to work, I was looking at SETRESATTRS today and wondering if perhaps with resources it should be done that way instead.
In other words, for Handles you create using NEWHANDLE, you use HLOCK/HUNLOCK. But for resources you read in (GETRESOURCE) you should use SETRESATTRS.
So which is the right way? Or does it matter?
My reason for asking is that I was writing a print routine to send a TEXT resource to a printer. It works fine on every printer except an HP inkjet. It would print garbage on the inkjet each time not the text. Turned out, when the printer driver started it Purged Memory and removed/moved my resource (but the resource handle was still good).
I did have it loaded and it was HLOCKed. Would SetResAttrs have prevented this?
SetResAttrs is for setting the attributes of a resource when saving it to disk. This is usually done to ensure that the next time a resource is loaded into memory, it is locked, purgeable, preload, etc. These are the attributes you see when viewing resources in ResEdit or Resorcerer. You shouldn't have to mess with this unless you are creating your own resources and wish to have them load a certain way the next time they are loaded. I wouldn't worry about it - it can get complicated, and isn't something you really need.
|