CallFunction for a local procedure [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5601
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

CallFunction for a local procedure [Resolved]

Post by Kwai chang caine »

Hello at all

For calling a local procedure with CallFunctionFast(), i do that and that works

Code: Select all

Procedure Kcc(*Variable)
 Debug PeekS(*Variable) + " from the procedure"
 ProcedureReturn *Variable
EndProcedure

*Ptr = CallFunctionFast(@Kcc(), @"Hello")
Debug PeekS(*Ptr)(
But i want to use CallFunction() and that not works :|

Code: Select all

Procedure Kcc(*Variable)
 Debug PeekS(*Variable) + " from the procedure"
 ProcedureReturn *Variable
EndProcedure

*Ptr = CallFunction(0, "Kcc", @"Hello")

If *Ptr
 Debug PeekS(*Ptr)
Else
 Debug "The pointer is empty"
EndIf 
Is it possible to use CallFunction for a local procedure ?
Have a good day
Last edited by Kwai chang caine on Sat Jan 03, 2026 6:12 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
mk-soft
Always Here
Always Here
Posts: 6479
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: CallFunction for a local procedure

Post by mk-soft »

Code: Select all

Procedure Kcc(*Variable)
 Debug PeekS(*Variable) + " from the procedure"
 ProcedureReturn *Variable
EndProcedure

*Ptr = CallFunctionFast(@Kcc(), @"Hello")

If *Ptr
 Debug PeekS(*Ptr)
Else
 Debug "The pointer is empty"
EndIf 
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User_Russian
Addict
Addict
Posts: 1604
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: CallFunction for a local procedure

Post by User_Russian »

Please read the description of the function CallFunction().
Calls a function in the specified library, by using its name. The specified library must have previously been opened with the OpenLibrary() function. The function is expected to use the stdcall calling convention (the standard in most DLLs on Windows).
CallFunction() is not intended for calling local functions. It is needed for calling functions from a DLL / SO / DYLIB.

Use a prototype.

Code: Select all

Procedure.s Kcc(Variable.s)
 Variable + " from the procedure"
 ProcedureReturn Variable
EndProcedure

Prototype.s pKcc(Variable.s)
ProtoKcc.pKcc=@Kcc()
Debug ProtoKcc("Hello")
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5601
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: CallFunction for a local procedure

Post by Kwai chang caine »

Whaoouuh !!
Two greats MASTERS to help little KCC :shock: ...I'm going to play the lottery today :lol:

You'll probably laugh :lol:, but since the Prototype exist, i never understand how really to use it :oops:
When i read a simple example like above, it's still more or less understandable for me
But when i try to replace my several callfunctions...it's the disaster :shock:
It's the reason why i never use it :cry:

@User_Russian
I don't knowing CallFunction are only for DLL, i believed stupidly CallFunctionFast is quicker and use pointers, but i believed it's the "same" function, one who call "by the name" and the other "by pointer"
It's funny because at the begining of my numerous try, CallFunction(0, "Kcc", @"Hello") works, perhaps again a christmas miracle :shock: or perhaps i begin to be mad, after try something, and other thing, all the day :|

Thanks a lot at you two for your nices examples 8)
Have a very good end of day
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
mk-soft
Always Here
Always Here
Posts: 6479
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: CallFunction for a local procedure [Resolved]

Post by mk-soft »

Of course, it also goes over the function name as a string.

Code: Select all


Runtime Procedure Kcc(*Variable)
 Debug PeekS(*Variable) + " from the procedure"
 ProcedureReturn *Variable
EndProcedure

If GetRuntimeInteger("Kcc()")
  *Ptr = CallFunctionFast(GetRuntimeInteger("Kcc()"), @"Hello")
EndIf

If *Ptr
 Debug PeekS(*Ptr)
Else
 Debug "The pointer is empty"
EndIf 
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5601
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: CallFunction for a local procedure [Resolved]

Post by Kwai chang caine »

Waoouuhh !!!
I have forgotten this function Runtime() that i have try there are a long time :oops:
Since this time, i not use it ..

There are so much functions with PB, it's not always simple to memorise it mainly when i never use it :oops:
In fact...KCC is always in v3.94 Functions, the day of he came (Bad day for you all) :mrgreen:

Thanks a lot MASTER for this another method of call 8)
I think I'll be able to start a collection :shock:

Have a very good night
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
Post Reply