Author Topic: DLLC status  (Read 15568 times)

0 Members and 2 Guests are viewing this topic.

jack

  • Guest
Re: DLLC status
« Reply #30 on: May 10, 2020, 05:07:48 AM »
Jack,

Are you using the latest version of FreeImage?
yes, version 3.18 and O2H 0.2.9 2020-04-21T14:29:11
I suspect that there's a way to write the program so that it will compile on either 32 or 64-bit, perhaps Arnold or Aurel could help with that
« Last Edit: May 10, 2020, 05:21:55 AM by jack »

JRS

  • Guest
Re: DLLC status
« Reply #31 on: May 10, 2020, 05:37:33 AM »
I thought calling _FreeImage_Initialise@4 might help but no joy.  :(

Code: C
  1. #if defined(__MINGW32__) && defined(_WINDOWS_H)
  2. #define _WINDOWS_       // prevent a bug in MinGW32
  3. #endif // __MINGW32__
  4.  

My guess at this point is FreeImage can no longer be called via FFI due to structures or defines not preset.

I tried version 3.13 (2009) and it still doesn't work. Not sure what changed in O2?
« Last Edit: May 10, 2020, 06:08:45 AM by John »

JRS

  • Guest
Re: DLLC status
« Reply #32 on: May 10, 2020, 07:09:29 AM »
I gave DYC (what DLLC replaced) a try and it returns a string pointer to the FreeImage version return string.

This eliminates FreeImage, ScriptBasic and O2 native. (based on Jack's positive results with O2)

Looks like a bug in DLLC using the latest O2 build.

Code: Script BASIC
  1. DECLARE SUB DLL ALIAS "dyc" LIB "dyc"
  2.  
  3. PRINT DLL("mc,p,freeimage.dll,_FreeImage_GetVersion@0,P",0),"\n"
  4.  


C:\ScriptBASIC\examples>sbc testfi.sb
270788360

C:\ScriptBASIC\examples>


Here is the DLLC code that is failing with FreeImage.dll.

Code: OxygenBasic
  1.   function dllproc (sys pSt, ppModuleInternal, pParameters, pReturnValue) as sys
  2.   ==============================================================================
  3.   '
  4.  sys oa
  5.   string ms
  6.   '
  7.  if pParameters=0
  8.     exit function
  9.   end if
  10.   '
  11.  CountParams pParameters,c
  12.   '
  13.  if c<2
  14.     exit function
  15.   elseif c>=3
  16.     pm=GetParamPtr pparameters,3 'DIRECT CALL ADDRESS
  17.    oa=GetLongParam pst,pm
  18.   end if
  19.   '
  20.  e++
  21.   ll[e].metatype=2 'metatype PROCEDURE CALLS=2
  22.  '
  23.  pm=GetParamPtr pparameters,2
  24.   s=GetStringParam pst,pm
  25.   '
  26.  readentityspec 'encode and store the prototype
  27.  '
  28.  pm=GetParamPtr pparameters,1
  29.   a=GetLongParam pst,pm
  30.   if a=0
  31.     errors+= "library not found for " ll[e].name cr
  32.     errn++
  33.     e--
  34.     exit function
  35.   end if
  36.   '
  37.  if oa
  38.     ll[e].library=0
  39.     ll[e].handle=oa 'specify call address
  40.    a=e
  41.   else
  42.     ll[e].library=a
  43.     if a then
  44.       ll[e].handle=GetProcAddress ll[a].handle, ll[e].name
  45.       a=e
  46.     end if
  47.   end if
  48.   if ll[e].handle=0
  49.     errors+="procedure not located: " ll[e].name cr
  50.     e--
  51.     errn++
  52.     a=0
  53.   end if
  54.   *pReturnValue=ReturnLong(pst,a)
  55.   '
  56.  end function
  57.  



Charles Pegge

  • Guest
Re: DLLC status
« Reply #33 on: May 10, 2020, 11:27:56 AM »
Hi John,

It was the mangled names :(

I've fixed this in dllc: sbutil.inc getword(). ascii 64 '@'

Also, If the dll is located in the exepath, the system should find it without a full path name.

JRS

  • Guest
Re: DLLC status
« Reply #34 on: May 10, 2020, 12:29:20 PM »
Thank you Charles!

Glad this is behind us.

FYI: I had to declare a few for variables in the examples. It seems O2 is more picky about type definitions. At least in functions.

Works great by just replacing my extension module with your compiled dllc.dll that came in the zip.

Can't be happier. An open ended easy to use scripting engine with a kickass JIT BASIC compiler seamlessly embedded.
« Last Edit: May 10, 2020, 04:49:11 PM by John »

JRS

  • Guest
Re: DLLC status
« Reply #35 on: May 11, 2020, 07:19:23 AM »
My next goal is to use DLLC to create virtual callback functions for both IUP and the COM/OLE automation based WSO GUI toolkit.

Any suggestions or examples are welcome.

JRS

  • Guest
Re: DLLC status
« Reply #36 on: May 11, 2020, 09:02:04 AM »
In theory, I would like to define standard callback functions based on the event and keep an array of controls that subscribe to them. The callback would lookup the control ID in the array and do a SB function call in the case of IUP or return the C function callback address for the WSO GUI toolkit.

The current VB6 OCX form callbacks work in this way with ScriptBasic. I would like to provide the same strategy for IUP and WSO.
« Last Edit: May 11, 2020, 09:23:58 AM by John »

JRS

  • Guest
Re: DLLC status
« Reply #37 on: May 12, 2020, 06:41:54 AM »
The ScriptBasic VB6 OCX form example I did is a good example of solving the callback delemia. Before the form is shown, ScriptBasic via its COM extension assigns values to a collection which the OCX uses to call the right ScriptBasic function/ sub.

JRS

  • Guest
Re: DLLC status
« Reply #38 on: July 19, 2020, 09:10:18 AM »
Charles,

DLLC is working great with my current IUP based project. The only request I have is can we change the callback to SB functions to uses the hook call rather than having to start a thread just to get the execution object's pointer?

JRS

  • Guest
Re: DLLC status
« Reply #39 on: July 22, 2020, 10:29:20 AM »
Thanks Charles for your response (email) about DLLC unable to make IUP calls in a callback. Once the IUP message loop starts, the only way to change the form is in a callback with IupSetAttribute.

When I have time I will give DLLC and IUP another try not running as a thread and depending on the MAIN function for IUP interaction. I think my idea of using a DLLC virtual function as a callback and using ScriptBasic's hook call to make the callback to SB could be the solution.

I'm still on the fence if a dynamic FFI interface will work with IUP and the required dependencies.

Charles Pegge

  • Guest
Re: DLLC status
« Reply #40 on: July 22, 2020, 01:25:52 PM »
I remember we tried to access the hook function, but it was set to null.

JRS

  • Guest
Re: DLLC status
« Reply #41 on: July 22, 2020, 01:52:15 PM »
The hook function doesn't require a execution object pointer and assumes the current instance. Dave Zimmer used it in his COM extension module. I'm using it for my VB6 OCX form project as well.

Code: C
  1.   besHOOK_CALLSCRIBAFUNCTION(EntryPoint,
  2.     pArg->Value.aValue,
  3.     1,
  4.     &FunctionResult);
  5.  
  6.   retVal = FunctionResult->Value.lValue;
  7.   besRELEASE(pArg);
  8.   besRELEASE(FunctionResult);
  9.  

Here is a LINK to my OCX form example.
« Last Edit: July 25, 2020, 11:54:39 AM by John »

JRS

  • Guest
Re: DLLC status
« Reply #42 on: July 25, 2020, 06:46:40 PM »
Charles,

Here is a bare bones examples of a VB6 ActiveX DLL form calling back to ScriptBasic functions.

Code: Script BASIC
  1. IMPORT COM.sbi
  2.  
  3. FUNCTION ML_Selected_Click
  4.   PRINT "Selected Button Clicked\n"
  5.   ML_Selected_Click = TRUE
  6. END FUNCTION  
  7.  
  8.  
  9. FUNCTION ML_Auto_Click
  10.   PRINT "Auto Button Clicked\n"
  11.   ML_Auto_Click = TRUE
  12. END FUNCTION
  13.  
  14.  
  15. FUNCTION ML_Cancel_Click
  16.   PRINT "Cancel Button Clicked\n"
  17.   ML_Cancel_Click = TRUE
  18. END FUNCTION
  19.  
  20.  
  21. FUNCTION ML_Setup_Click
  22.   PRINT "Setup Button Clicked\n"
  23.   ML_Setup_Click = TRUE
  24. END FUNCTION
  25.  
  26.  
  27. FUNCTION ML_Exit_Click
  28.   PRINT "Exit Button Clicked\n"
  29.   ML_Exit_Click = TRUE
  30. END FUNCTION
  31.  
  32.  
  33. obj = COM::CREATE(:SET, "MASLink.OCXForm")
  34.  
  35. oCollection = COM::CBN(obj, "CallBackHandlers", :GET)
  36. COM::CBN oCollection, "Add", :CALL, ADDRESS(ML_Selected_Click()), "MLForm.ML_Selected_Click"
  37. COM::CBN oCollection, "Add", :CALL, ADDRESS(ML_Auto_Click()), "MLForm.ML_Auto_Click"
  38. COM::CBN oCollection, "Add", :CALL, ADDRESS(ML_Cancel_Click()), "MLForm.ML_Cancel_Click"
  39. COM::CBN oCollection, "Add", :CALL, ADDRESS(ML_Setup_Click()), "MLForm.ML_Setup_Click"
  40. COM::CBN oCollection, "Add", :CALL, ADDRESS(ML_Exit_Click()), "MLForm.ML_Exit_Click"
  41.  
  42. COM::CBN obj, "ShowOCXForm"
  43.  
  44. COM::RELEASE obj
  45.  

VB Form Code
Code: Visual Basic
  1. Private Declare Function ext_SBCallBack Lib "COM.dll" Alias "SBCallBack" (ByVal EntryPoint As Long, ByVal arg As Long) As Long
  2. Private Declare Function ext_SBCallBackEx Lib "COM.dll" Alias "SBCallBackEx" (ByVal EntryPoint As Long, ByRef v As Variant) As Variant
  3.  
  4. Private m_owner As OCXForm
  5. Private Type ControlPositionType
  6.     Left As Single
  7.     Top As Single
  8.     Width As Single
  9.     Height As Single
  10.     FontSize As Single
  11. End Type
  12.  
  13. Private m_ControlPositions() As ControlPositionType
  14. Private m_FormWid As Single
  15. Private m_FormHgt As Single
  16.  
  17.  
  18. Function ShowMLform(owner As OCXForm) As Long
  19.     On Error Resume Next
  20.     Set m_owner = owner
  21.     Me.Show 1
  22.     Set m_owner = Nothing
  23.     ShowMLform = 0
  24.     Unload Me
  25. End Function
  26.  
  27. Private Function TriggerCallBack(nodeID As Long, argValue As Long) As Long
  28.     TriggerCallBack = ext_SBCallBack(nodeID, argValue)
  29. End Function
  30.  
  31. Private Function TriggerCallBackEx(nodeID As Long, v() As Variant)
  32.     TriggerCallBackEx = ext_SBCallBackEx(nodeID, v)
  33. End Function
  34.  
  35. Private Sub Form_Load()
  36.  
  37.   TableGrid.Row = 0
  38.   TableGrid.FormatString = "^Live Tables|^Last Update|^Update Freq|^Duration|^Temp Table|^Map Function"
  39.    
  40.   TableGrid.ColWidth(0) = 3000
  41.   TableGrid.ColWidth(1) = 1700
  42.   TableGrid.ColWidth(2) = 1200
  43.   TableGrid.ColWidth(3) = 1200
  44.   TableGrid.ColWidth(4) = 3200
  45.   TableGrid.ColWidth(5) = 3200
  46.  
  47. End Sub
  48.  
  49. Private Sub ML_Selected_Click()
  50.     Dim nodeID As Long
  51.     Dim arg As Long
  52.     Dim rtnVal As Long
  53.    
  54.     nodeID = m_owner.CallBackHandlers("MLForm.ML_Selected_Click")
  55.     arg = False
  56.     rtnVal = TriggerCallBack(nodeID, arg)
  57. End Sub
  58.  
  59. Private Sub ML_Auto_Click()
  60.     Dim nodeID As Long
  61.     Dim arg As Long
  62.     Dim rtnVal As Long
  63.    
  64.     nodeID = m_owner.CallBackHandlers("MLForm.ML_Auto_Click")
  65.     arg = False
  66.     rtnVal = TriggerCallBack(nodeID, arg)
  67. End Sub
  68.  
  69. Private Sub ML_Cancel_Click()
  70.     Dim nodeID As Long
  71.     Dim arg As Long
  72.     Dim rtnVal As Long
  73.    
  74.     nodeID = m_owner.CallBackHandlers("MLForm.ML_Cancel_Click")
  75.     arg = False
  76.     rtnVal = TriggerCallBack(nodeID, arg)
  77. End Sub
  78.  
  79. Private Sub ML_Setup_Click()
  80.     Dim nodeID As Long
  81.     Dim arg As Long
  82.     Dim rtnVal As Long
  83.    
  84.     nodeID = m_owner.CallBackHandlers("MLForm.ML_Setup_Click")
  85.     arg = False
  86.     rtnVal = TriggerCallBack(nodeID, arg)
  87. End Sub
  88.  
  89. Private Sub ML_Exit_Click()
  90.     Dim nodeID As Long
  91.     Dim arg As Long
  92.     Dim rtnVal As Long
  93.    
  94.     nodeID = m_owner.CallBackHandlers("MLForm.ML_Exit_Click")
  95.     arg = False
  96.     rtnVal = TriggerCallBack(nodeID, arg)
  97. End Sub
  98.  

VB Class Code
Code: Visual Basic
  1. Public CallBackHandlers As New Collection
  2.  
  3. Public Function ShowOCXForm() As Long
  4.     ShowOCXForm = MLform.ShowMLform(Me)
  5. End Function
  6.  

Output

C:\Matt\maslink>sbc maslink.sb
Selected Button Clicked
Auto Button Clicked
Cancel Button Clicked
Setup Button Clicked
Exit Button Clicked

C:\Matt\maslink>

« Last Edit: July 25, 2020, 07:57:13 PM by John »

JRS

  • Guest
Re: DLLC status
« Reply #43 on: July 31, 2020, 04:04:57 PM »
Charles,

Can you post an example of creating a virtual callback function with DLLC that an IUP button callback would expect? Once I understand O2 virtual callback functions I can also use it with the WSO GUI OCX library.

Can I assume that I can use the existing O2 code that generates an IUP callback then calls a ScriptBasic function repurposed to run in the same instance?

John
« Last Edit: July 31, 2020, 06:03:19 PM by John »

Charles Pegge

  • Guest
Re: DLLC status
« Reply #44 on: August 03, 2020, 07:22:10 AM »
Hi John,

Unfortunatately, I have found that calling an sb function from a callback seems to destabilise the main sb program, even if the sb function does nothing.