PB5.31; ScintillaGadget; direct access to functions;

Windows specific forum
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

PB5.31; ScintillaGadget; direct access to functions;

Post by HanPBF »

Hello,

I've found some C-code I (obviously) don't fully understand...
It's a way to bypass sendScintillaMessage and do a faster call to it.

Here's the C code from the Scintilla homepage:

Code: Select all

int (*fn)(void*,int,int,int);
void * ptr;
int canundo;

fn = (int (__cdecl *)(void *,int,int,int))SendMessage(
	hwndScintilla,SCI_GETDIRECTFUNCTION,0,0);
ptr = (void *)SendMessage(hwndScintilla,SCI_GETDIRECTPOINTER,0,0);

canundo = fn(ptr,SCI_CANUNDO,0,0) // this is the final example function pointer for fast call
Or is there already a fast call library for scintilla?

I tried this code with PB:

EnableExplicit

Code: Select all

InitScintilla()

Declare   ScintillaCallBack(Gadget, *N.SCNotification)

define NrWin = OpenWindow(#PB_Any, 128, 128, 640, 512, "Scintilla Test")

if NrWin
  define  w = 640-16,
          h = 512-16-32
  
  define NrBoxSci = ContainerGadget(#PB_Any, 8, 32, w, h, #PB_Container_BorderLess)
    define NrSci = ScintillaGadget(#PB_Any, -2, -2, w + 4, h + 4, @ScintillaCallBack())
  CloseGadgetList()

  ; get some direct functions
  Prototype SciPrototype(NrSci, Msg.i, WParam.i=0, LParam.i=0) ; or PrototypeC?
    
define fn.SciPrototype = ScintillaSendMessage(NrSci, #SCI_GETDIRECTFUNCTION)
; same prototype for fn and canSciUndo/setSciText?
define ptr = ScintillaSendMessage(NrSci, #SCI_GETDIRECTPOINTER)

; HERE IS THE PROBLEM: both vars are zero ********************************  
define canSciUndo.SciPrototype = fn(ptr, #SCI_CANUNDO, 0, 0)
define setSciText.SciPrototype = fn(ptr, #SCI_SETTEXT, 0, 0)

debug "canSciUndo = " + Str(canSciUndo)
debug "setSciText = " + Str(setSciText)
  
  repeat
    define Evt = WaitWindowEvent()
    
    
    select Evt
      case #PB_Event_CloseWindow
        break
        
      default
      
    endSelect 
  forever 
endif

Procedure ScintillaCallBack(Gadget, *N.SCNotification)
  if *N\message<>0
    debug Str(*N\message)
  endif
EndProcedure
What went wrong from translating C code to PB code?

Really appreciate any help!
Thanks a lot!!!
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Re: PB5.31; ScintillaGadget; direct access to functions;

Post by hallodri »

canundo is a result from "fn(ptr,SCI_CANUNDO,0,0)", This is not a function.
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

Re: PB5.31; ScintillaGadget; direct access to functions;

Post by HanPBF »

Hello!

Thanks a lot for the info!

Problems I got so far:
- local created strings were destroyed when calling fn(ptr,...)
did put call in a procedure then the "error" was solved

- returning from procedure got an error, because signature (prototype) was wrong
need to use PrototypeC to call fn(ptr,...)

Then it worked!

Thanks!
Post Reply