• Updated 2023-07-12: Hello, Guest! Welcome back, and be sure to check out this follow-up post about our outage a week or so ago.

RealBasic - Opening the Resource Fork as a Binary Stream

Phipli

Well-known member
Afternoon Folks,

Does anybody know how I might be able to open the resource fork of an external file as a binary stream using RealBasic 2.x (or 3.x at a push).

My understanding is that this was never possible natively in RealBasic, but I'm hoping someone can show me a way.

I was happily writing a program to batch process creating MacBinaries until I realised that I couldn't just read the resource fork and write it to a file like I'd planned!

1686140150234.png
 

Crutch

Well-known member
I’ve never used RealBasic but does it allow for calling out to Toolbox routines? The Toolbox call you need for this is OpenRF (which is a glue routine provided by the dev environments) or _PBOpenRF (in ROM). If you can access either of those, you should be all set. Documented in the File Manager (not Resource Manger) chapter of Inside Mac Volume II.
 

Phipli

Well-known member
I’ve never used RealBasic but does it allow for calling out to Toolbox routines? The Toolbox call you need for this is OpenRF (which is a glue routine provided by the dev environments) or _PBOpenRF (in ROM). If you can access either of those, you should be all set. Documented in the File Manager (not Resource Manger) chapter of Inside Mac Volume II.
Thank you Crutch - I believe it is possible. I will go that route if I can't find anything. But you'll have to forgive me - I've never got more than a few chapters into Macintosh C Programming Primer... I can make lots of lines wizz around the screen but have very little toolbox experience! It will take me a bit of time to work out what I'm looking at, but will probably be good for my brain.
 

Juror22

Well-known member
I think that I did something similar to that within FutureBasic (it was a long time ago) I will look it up and see if it is applicable to your question about RealBasic.
 

twelvetone12

Well-known member
You can absolutely call Toolbox from RealBasic, I used it all the time back in the day. There is a specific syntax to map the routines, people would often make modules wrapping Toolbox stuff, you could probably even find something still online that does what you need. There was also a way to pass pointers, but my memory is a bit fuzzy on that.
 

twelvetone12

Well-known member
Well I'm not sure if you will find it useful or not, but I went down the memory lane and found a couple examples from my code that show how to call the Toolbox.

sub CreateControl
Declare Function NewControl Lib "InterfaceLib" (owningWindow as integer, boundsRect as Ptr, controlTitle as PString, initiallyVisible as Boolean, iv as Short, min as Short, max as Short, procID as Short, cr as Integer) as integer Inline68K("A954")
Dim M as MemoryBlock
Dim r as Integer
M = NewMemoryBlock(8)

if Default then
M.Short(0) = Me.Top+4
M.Short(2) = Me.Left+4
M.Short(4) = Me.Top +Me.Height-4
M.Short(6) = Me.Left+Me.Width-4
else
M.Short(0) = Me.Top
M.Short(2) = Me.Left
M.Short(4) = Me.Top +Me.Height
M.Short(6) = Me.Left+Me.Width
end if

Active = True
ControlHandle = NewControl(WindowPtr, M, Title, true, Value, Min, Max, ProcId, 0)
if Default then
DrawRoundRect
end if

end sub

This sub creates a control via NewControl, you can see how the memory is allocated for the control and how the call is declared.

Sub ShowModalDialog
Declare Function GetNewDialog Lib "InterfaceLib" (dialogID as Short, dStorage as integer, behind as integer) as integer Inline68K("A97C")
Declare Sub DisposeDialog Lib "InterfaceLib" (theDialog as integer) Inline68K("A983")
Declare Sub ModalDialog Lib "InterfaceLib" (modalFilter as integer, itemHit as Ptr) Inline68K("A991")
Declare Sub SetPort Lib "InterfaceLib" (port as integer) Inline68K("A873")
Declare Sub FrameRoundRect Lib "InterfaceLib" (r as Ptr, ovalWidth as Short, ovalHeight as Short) Inline68K("A8B0")

Dim MyDialog as integer
Dim intPtr as MemoryBlock
Dim rect as MemoryBlock
intPtr = newMemoryBlock(2)
rect = newMemoryBlock(8)

myDialog = GetNewDialog(128, 0, -1)
SetPort myDialog

rect.Short(0) = 118
rect.Short(2) = 202
rect.Short(4) = 202
rect.Short(6) = 232

FrameRoundRect rect, 4, 4

while (true = true)
ModalDialog 0, intPtr
if intPtr.Short(0) = 1 then
exit
end if
wend

DisposeDialog MyDialog
End Sub

This one is a bit more involved - it created a dialog box from a res file and shows it with ModalDialog().

I forgot how cool RealBasic was, there were so many plugins and modules. IIRC at some point it could also target Windows machines if I'm not wrong!
 

Phipli

Well-known member
Well I'm not sure if you will find it useful or not, but I went down the memory lane and found a couple examples from my code that show how to call the Toolbox.



This sub creates a control via NewControl, you can see how the memory is allocated for the control and how the call is declared.



This one is a bit more involved - it created a dialog box from a res file and shows it with ModalDialog().

I forgot how cool RealBasic was, there were so many plugins and modules. IIRC at some point it could also target Windows machines if I'm not wrong!
Thank you, I was looking and the examples and it looks similar but your examples are more involved and answer some questions I had.

1686154620784.png
 
Top