Xojo Conferences
XDCMay2019MiamiUSA

Callbacks (Real Studio Plugins Mailinglist archive)

Back to the thread list
Previous thread: weird crash
Next thread: Another thing on Windows pics


macosx and unix paths   -   GOLD
  Callbacks   -   Nick Lockwood
   Re: Callbacks   -   Joseph J. Strout
   Re: Callbacks   -   Nick Lockwood
    Re: Callbacks   -   Thomas Tempelmann
     Re: Callbacks   -   Nick Lockwood

Callbacks
Date: 01.06.04 13:07 (Tue, 1 Jun 2004 13:07:24 +0100)
From: Nick Lockwood
Hi,

I'm trying to write a plugin function that can call a REALbasic
callback function. I've managed to get parameterless functions working
fine using the following code:

static int FeedBack(REALmemoryBlockStruct *fn) {return ((int
(*)())REALMemoryBlockGetPtr(fn))();}

which when called in RB like this...


Function Foo() As Integer
return 4+5
End Function

Return Feedback(AddressOf Foo)

...returns 9 as you would expect. However, if I try to give my feedback
function a parameter, such as an integer, like this:

static int FeedBack(REALmemoryBlockStruct *fn, int p) {return ((int
(*)(int))REALMemoryBlockGetPtr(fn))(p);}

Then it crashes when called in RB.

Any idea what I'm doing wrong?

Nick

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Callbacks
Date: 01.06.04 15:39 (Tue, 1 Jun 2004 09:39:13 -0500)
From: Joseph J. Strout
At 1:07 PM +0100 6/1/04, Nick Lockwood wrote:

>I'm trying to write a plugin function that can call a REALbasic
>callback function.

You should have your plugin invoke an event instead.

Re: Callbacks
Date: 01.06.04 15:58 (Tue, 1 Jun 2004 15:58:49 +0100)
From: Nick Lockwood
That would be an alternative way of getting callback functionality,
yes, but it's not what I'm trying to do.

I wish to write this callback plugin as part of a grander scheme which
will require me to be able to call functions by address without
necessarily caring whether they were written in RB. Is there a reason
why it can't be done this way? it seems to me that if REALbasic
callbacks use a standard interface, and if I am calling them in the
correct way that one would normally call a callback function then it
should work.

If I get a function pointer from a C function instead of from REALbasic
and use it with the exact same code then it works fine. What am I
missing?

Nick

>> I'm trying to write a plugin function that can call a REALbasic
>> callback function.
>
> You should have your plugin invoke an event instead.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Callbacks
Date: 06.06.04 20:13 (Sun, 6 Jun 2004 21:13:49 +0200)
From: Thomas Tempelmann
Nick Lockwood wrote:

>static int FeedBack(REALmemoryBlockStruct *fn) {return ((int
>(*)())REALMemoryBlockGetPtr(fn))();}

Just a guess: Have you tried using "fn" directly as a proc ptr
instead of using "REALMemoryBlockGetPtr(fn)"?

Thomas

Re: Callbacks
Date: 07.06.04 19:48 (Mon, 7 Jun 2004 19:48:23 +0100)
From: Nick Lockwood
>> static int FeedBack(REALmemoryBlockStruct *fn) {return ((int
>> (*)())REALMemoryBlockGetPtr(fn))();}
>
> Just a guess: Have you tried using "fn" directly as a proc ptr
> instead of using "REALMemoryBlockGetPtr(fn)"?

I tried that first, but it appears to make no difference. I suspect
this is something to do with Codewarrior applying its own calling
conventions that are different from those for system callbacks. Note
that function call and return appears to work, it is only when I try to
send parameters that it crashes.

I tried experimenting with hand-compiling some instructions in machine
code (essentially just put a value in r3 and then do a standard branch
return) in a struct and calling them via a function pointer. This works
in GCC/Xcode but not in codewarrior, which, it seems to me is probably
related to the reason why calls to RB functions crash. Naturally RB
calling conventions aren't documented anywhere, but I assume they are
the same as the system uses or callbacks would be pretty useless.

Is there some way to tell codewarrior to use these conventions? I tried
all likely-looking options, but nothing made a difference.

Nick

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>