Code: Select all
procedure dosomething()
;more code here
endprocedure
*Proc = @dosomething();proc now has the address of dosomething
Code: Select all
*ProcRGBA = @RGBA();well, I tried and it didn't work, is there any other way?
Code: Select all
procedure dosomething()
;more code here
endprocedure
*Proc = @dosomething();proc now has the address of dosomething
Code: Select all
*ProcRGBA = @RGBA();well, I tried and it didn't work, is there any other way?
Code: Select all
; myRGBA with optimize C Backend
Procedure.l myRGBA(r.a, g.a, b.a, a.a)
ProcedureReturn a | b<<8 | g<<16 | r<<24 ; r=(((v_a|(v_b<<8))|(v_g<<16))|(v_r<<24)); return r;
EndProcedure
; 0000000140001000 | 0FB6D2 | movzx edx,dl |
; 0000000140001003 | C1E1 18 | shl ecx,18 |
; 0000000140001006 | 45:0FB6C9 | movzx r9d,r9b |
; 000000014000100A | C1E2 10 | shl edx,10 |
; 000000014000100D | 45:0FB6C0 | movzx r8d,r8b |
; 0000000140001011 | 09CA | Or edx,ecx |
; 0000000140001013 | 41:C1E0 08 | shl r8d,8 |
; 0000000140001017 | 44:09CA | Or edx,r9d |
; 000000014000101A | 89D0 | mov eax,edx |
; 000000014000101C | 44:09C0 | Or eax,r8d |
; 000000014000101F | C3 | ret |
*procRGBA=@myRGBA() ; p_procrgba=((integer)f_myrgba);
SetClipboardText(Hex(*procRGBA)+" "+Hex(CallFunctionFast(*procRGBA,$47,$11,$12,$ff), #PB_Long))
; 140001000 471112FF
Code: Select all
Procedure _RGBA(r, g, b, a)
ProcedureReturn RGBA(r, g, b, a)
EndProcedure
Procedure getProc()
ProcedureReturn @_RGBA()
EndProcedure
Prototype.i Proc(r, g, b ,a)
proc.Proc = getProc()
Debug Hex(proc($11, $22, $33, $44)) ; 44332211
I'm sure the RGBA() was just mentioned as a placeholder for this question in general.juergenkulow wrote: ↑Wed Oct 20, 2021 9:01 amCode: Select all
; myRGBA with optimize C Backend Procedure.l myRGBA(r.a, g.a, b.a, a.a) ProcedureReturn a | b<<8 | g<<16 | r<<24 ; r=(((v_a|(v_b<<8))|(v_g<<16))|(v_r<<24)); return r; EndProcedure ; 0000000140001000 | 0FB6D2 | movzx edx,dl | ; 0000000140001003 | C1E1 18 | shl ecx,18 | ; 0000000140001006 | 45:0FB6C9 | movzx r9d,r9b | ; 000000014000100A | C1E2 10 | shl edx,10 | ; 000000014000100D | 45:0FB6C0 | movzx r8d,r8b | ; 0000000140001011 | 09CA | Or edx,ecx | ; 0000000140001013 | 41:C1E0 08 | shl r8d,8 | ; 0000000140001017 | 44:09CA | Or edx,r9d | ; 000000014000101A | 89D0 | mov eax,edx | ; 000000014000101C | 44:09C0 | Or eax,r8d | ; 000000014000101F | C3 | ret | *procRGBA=@myRGBA() ; p_procrgba=((integer)f_myrgba); SetClipboardText(Hex(*procRGBA)+" "+Hex(CallFunctionFast(*procRGBA,$47,$11,$12,$ff), #PB_Long)) ; 140001000 471112FF
Code: Select all
#include <stdio.h>
#include <math.h>
int main(int argc, char **argv) {
float (*sinpointer)(float) = &sinf;
printf("%f\n", sinpointer(45*3.14159265/180));
printf("%f\n", sinf(45*3.14159265/180));
}
It's not my intention to do that. I just want to call them from my code using pointers.juergenkulow wrote: ↑Wed Oct 20, 2021 2:52 pm The PureBasic license explicitly forbids the creation of DLL's whose main function is to serve as a 'wrapper' for PureBasic functions.
Code: Select all
Prototype.d Func(p.d)
Procedure.d MyRadians(Degrees.d)
ProcedureReturn Degrees * #PI / 180
EndProcedure
*mr.Func = @MyRadians()
Debug *Mr(45)
a.f = Radian(45)
Debug a
*rd.Func = #Null
! LEA rax,[PB_Radian_DOUBLE]
! PUSH rax
! POP qword [p_rd]
b.f = *rd(45)
Debug b