Oxygen Basic

Information => Development => DLLC => Topic started by: JRS on April 21, 2020, 12:54:18 PM

Title: DLLC status
Post by: JRS on April 21, 2020, 12:54:18 PM
Charles,

I would like to use DLLC's FFI definition and calling functionality in Windows 32 bit. Does this update work with core DLLC functionality?
Title: Re: DLLC status
Post by: Charles Pegge on April 21, 2020, 02:03:18 PM
Hi John, hang on to the previous version. There's a glitch.
Title: Re: DLLC status
Post by: JRS on April 21, 2020, 07:17:21 PM
Not in a rush. Let me know when you solved it. Thanks!

Not doing anything with threading or IUP with DLLC. All I'm after is a FFI and C types and structures. The virtual DLL feature is nice.
Title: Re: DLLC status
Post by: Charles Pegge on April 22, 2020, 06:19:43 AM
Hi John,

In DllcBuild.o2bas:

sys CallBackTable[16]

should be:

sys CallBackTable[32]

This is all that needs to be done, but i have re-posted OxygenBasicProgress.zip

The array overflow caused the whole DLL to be inoperable!


Title: Re: DLLC status
Post by: JRS on April 22, 2020, 10:29:37 PM
Outstanding!  Thanks.

Just in time for my new SBWin32 Inno installer that was recompile on Windows 10 Pro using TDM-GCC-32. I wanted to include DLLC in the build.

Curious. How difficult do you think it would be to convert your FFI DLLC code to C so I can use it with Linux shared objects?


C:\OxygenBasic\projectsC\ScriptBasic>BuildInstallDLLC.bat

C:\OxygenBasic\projectsC\ScriptBasic>..\..\co2 DLLCbuild.o2bas

C:\OxygenBasic\projectsC\ScriptBasic>..\..\co2 DLLCtestDLL.o2bas

C:\OxygenBasic\projectsC\ScriptBasic>copy ..\..\Oxygen.dll  \ScriptBasic\modules
        1 file(s) copied.

C:\OxygenBasic\projectsC\ScriptBasic>copy DLLC*.dll          \ScriptBasic\modules
dllc.dll
DLLCtestDLL.dll
        2 file(s) copied.

C:\OxygenBasic\projectsC\ScriptBasic>pause
Press any key to continue . . .

C:\OxygenBasic\projectsC\ScriptBasic>


I gave most of the ScriptBasic / DLLC test programs a try and all seems good on my Windows 10 Pro laptop.
Title: Re: DLLC status
Post by: JRS on April 23, 2020, 09:59:55 AM
Charles,

I noticed your DLLC build script copies Oxygen and the test dll into modules. That directory isn't in the system path and only ScriptBasic extension modules can be found there. The bin is in the system path and where I put dependency executables like the IUP DLLs. ScriptBasic can be installed anywhere. I will try to move them to bin and see how that works out not using hard coded paths.

Title: Re: DLLC status
Post by: JRS on April 24, 2020, 07:46:00 PM
Charles,

What is a safe array as referenced in the COM / VB world?

Can they be accessed using your existing  COM interface in DLLC?

This may help. (https://docs.microsoft.com/en-us/archive/msdn-magazine/2017/march/introducing-the-safearray-data-structure)

Quote
That’s because the safe array is a polymorphic C array structure and the data stored in it can be of many different types, from integers of different sizes, to floating point numbers, to BSTR strings, to COM IUnknown interface pointers, and so on.
Title: Re: DLLC status
Post by: JRS on April 25, 2020, 04:48:13 PM
Charles,

I'm trying get a COM/OLE automation driven Windows GUI in an OCX (DLL) to work with ScriptBasic's COM extension module. Problem is the event callback references a function pointer as an argument. I'm thinking that I can wrap the event handler like the other languages that have bindings. Can you take a peek and see if I can capture events and do an ICALL() to a SB function/sub?

WSO Home Page (http://veretennikov.org/Default.aspx?f=WSO%2fDefault.aspx)

WSO 1.1: WindowSystemObject Interface Reference (http://www.veretennikov.org/WSO/Help/html_en/interface_window_system_object.html)

Here is my WSO ScriptBasic test form. (no event support)

Code: Script BASIC
  1. ' WSO Test Dialog
  2.  
  3. IMPORT com.sbi
  4.  
  5. o = COM::CREATE(:SET, "Scripting.WindowSystemObject")
  6.  
  7. COM::CBN(o, "EnableVisualStyles", :LET, TRUE)
  8.  
  9. f = COM::CBN(o, "CreateForm", :CALL, 0, 0, 0, 0)
  10.  
  11. COM::CBN(f, "Text", :LET, "WSO")
  12. COM::CBN(f, "ClientWidth", :LET, 200)
  13. COM::CBN(f, "ClientHeight", :LET, 100)
  14. COM::CBN(f, "CenterControl")
  15.  
  16. Button = COM::CBN(f, "CreateButton", :CALL, 120, 70, 75, 25, "Close")
  17.  
  18. COM::CBN(f, "Show")
  19.  
  20. COM::CBN(o, "Run")
  21. COM::RELEASE(f)
  22. COM::RELEASE(o)
  23.  



Title: Re: DLLC status
Post by: JRS on April 26, 2020, 02:30:38 PM
This is the problem I need to solve.

Code: Script BASIC
  1. COM::CBN(Button, "OnClick", :CALL, function_address)
  2.  

Can I use DLLC to create a virtual function to call back to which would return me back to ScriptBasic so I could do an ICALL() to a SB FUNCTION/SUB before returning to the WSO message event loop?
Title: Re: DLLC status
Post by: JRS on April 26, 2020, 03:33:10 PM
Charles,

I  was looking  at  Dave Zimmer's COM.dll extension module and noticed  this exported function. Not sure if the function exists in the DLL and if it's a SB style call or standard DLL call.

Code: C
  1. VARIANT __stdcall SBCallBackEx(int EntryPoint, VARIANT *pVal)
  2. {
  3. #pragma EXPORT
  4.  
  5.   pSupportTable pSt = g_pSt;
  6.   VARIABLE FunctionResult;
  7.   _variant_t vRet;
  8.  
  9.   if(pSt==NULL){
  10.           MessageBox(0,"pSupportTable is not set?","",0);
  11.           return vRet.Detach();
  12.   }
  13.  
  14.     USES_CONVERSION;
  15.         char buf[1024]={0};
  16.     HRESULT hr;
  17.         long lResult;
  18.         long lb;
  19.         long ub;
  20.     SAFEARRAY *pSA = NULL;
  21.  
  22.         //we only accept variant arrays..
  23.         if (V_VT(pVal) == (VT_ARRAY | VT_VARIANT | VT_BYREF)) //24588
  24.                 pSA = *(pVal->pparray);
  25.         //else if (V_ISARRAY(pVal) && V_ISBYREF(pVal)) //array of longs here didnt work out maybe latter
  26.         //      pSA = *(pVal->pparray);
  27.         else
  28.         {
  29.                 if (V_VT(pVal) == (VT_ARRAY | VT_VARIANT))
  30.                         pSA = pVal->parray;
  31.                 else
  32.                         return vRet.Detach();//"Type Mismatch [in] Parameter."
  33.         };
  34.  
  35.     long dim = SafeArrayGetDim(pSA);
  36.         if(dim != 1) return vRet.Detach();
  37.  
  38.         lResult = SafeArrayGetLBound(pSA,1,&lb);
  39.         lResult = SafeArrayGetUBound(pSA,1,&ub);
  40.  
  41.         lResult=SafeArrayLock(pSA);
  42.     if(lResult) return vRet.Detach();
  43.  
  44.     _variant_t vOut;
  45.         _bstr_t cs;
  46.  
  47.         int sz = ub-lb+1;
  48.     VARIABLE pArg = besNEWARRAY(0,sz);
  49.  
  50.         //here we proxy the array of COM types into the array of script basic types element by element.
  51.         //      note this we only support longs and strings. floats will be rounded, objects converted to objptr()
  52.         //  bytes and integers are ok too..basically just not float and currency..which SB doesnt support anyway..
  53.     for (long l=lb; l<=ub; l++) {
  54.                 if( SafeArrayGetElement(pSA, &l, &vOut) == S_OK ){
  55.                         if(vOut.vt == VT_BSTR){
  56.                                 char* cstr = __B2C(vOut.bstrVal);
  57.                                 int slen = strlen(cstr);
  58.                                 pArg->Value.aValue[l] = besNEWMORTALSTRING(slen);
  59.                                 memcpy(STRINGVALUE(pArg->Value.aValue[l]),cstr,slen);
  60.                                 free(cstr);
  61.                         }
  62.                         else{
  63.                                 if(vOut.vt == VT_DISPATCH){
  64.                                         //todo register handle? but how do we know the lifetime of it..
  65.                                         //might only be valid until this exits, or forever?
  66.                                 }
  67.                                 pArg->Value.aValue[l] = besNEWMORTALLONG;
  68.                                 LONGVALUE(pArg->Value.aValue[l]) = vOut.lVal;
  69.                         }
  70.                 }
  71.     }
  72.  
  73.   lResult=SafeArrayUnlock(pSA);
  74.   if (lResult) return vRet.Detach();
  75.  
  76.   besHOOK_CALLSCRIBAFUNCTION(EntryPoint,
  77.                                                          pArg->Value.aValue,
  78.                              sz,
  79.                              &FunctionResult);
  80.  
  81.   for (long l=0; l <= sz; l++) {
  82.          besRELEASE(pArg->Value.aValue[l]);
  83.      pArg->Value.aValue[l] = NULL;
  84.   }
  85.        
  86.   if(FunctionResult->vType == VTYPE_STRING){
  87.         char* myStr = GetCString(FunctionResult);
  88.         vRet.SetString(myStr);
  89.         free(myStr);
  90.   }
  91.   else{
  92.           switch( TYPE(FunctionResult) )
  93.           {      
  94.                 case VTYPE_DOUBLE:
  95.                 case VTYPE_ARRAY:
  96.                 case VTYPE_REF:
  97.                                 MessageBoxA(0,"Arguments of script basic types [double, ref, array] not supported","Error",0);
  98.                                 break;
  99.                 default:
  100.                                 vRet = LONGVALUE(FunctionResult);
  101.           }
  102.   }
  103.  
  104.   besRELEASE(pArg);
  105.   besRELEASE(FunctionResult);
  106.  
  107.   return vRet.Detach();
  108. }
  109.  

This is the results of the COM extensions Display Interface function  on the WSO object.


Interface: IWindowSystemObject
ProgID: Scripting.WindowSystemObject.1
CLSID: {4CE85115-9B90-419F-9193-1C10C75E1383}
Function CreateForm([Left As Long = 0], [Top As Long = 0], [Width As Long = 0], [Height As Long = 0], [Style As Long = 13565952], pControl As Object) As Hresult
Function CreateDialogForm([Left As Long = 0], [Top As Long = 0], [Width As Long = 0], [Height As Long = 0], [Style As Long = 13107200], pControl As Object) As Hresult
Function CreateImageList(pControl As Object) As Hresult
Function CreateTimer(pControl As Object) As Hresult
Function CreateCOMEvents(COMObject As Object, pControl As Object) As Hresult
Function CreateFindDialog([FindText As String], [Flags As Long = 1], pResult As Object) As Hresult
Function CreateReplaceDialog([FindText As String], [ReplaceText As String], [Flags As Long = 1], pResult As Object) As Hresult
Function CreateTrayIcon(pControl As Object) As Hresult
Function Run() As Hresult
Function Stop() As Hresult
Get Controls(pVal As Object) As Hresult
Function Translate(Text As String, pResult As Object) As Hresult
Function LoadImage(Path As String, pResult As Object) As Hresult
Get Version(pVal As Object) As Hresult
Get Debug(pVal As Object) As Hresult
Let Debug(pVal As Boolean) As Hresult
Function About() As Hresult
Get Regions(pVal As Object) As Hresult
Get PixelsPerInch(pVal As Object) As Hresult
Let PixelsPerInch(pVal As Long) As Hresult
Get Screen(pVal As Object) As Hresult
Function CreateEventHandler(pControl As Object) As Hresult
Get EnableVisualStyles(pVal As Object) As Hresult
Let EnableVisualStyles(pVal As Boolean) As Hresult
Function CreatePrintInfo(pControl As Object) As Hresult
Function CreateStdDispatch(TypeLibrary As String, Major As Long, Minor As Long, Guid As String, Object As VT_UNKNOWN, pControl As Object) As Hresult
Get Console(pControl As Object) As Hresult
Get ActiveForm(pVal As Object) As Hresult
Get ForegroundForm(pVal As Object) As Hresult
Function VirtualKeyCodeToString(VirtualKey As Long, [UseKeyboardState As Boolean = True], pVal As Object) As Hresult
Function SaveLayout(Layout As Object) As Hresult
Function LoadLayout(Layout As String) As Hresult
Get Color(Color As Object) As Hresult
Get EnableVistaFileDialog(pVal As Object) As Hresult
Let EnableVistaFileDialog(pVal As Boolean) As Hresult
Function LoadIcon(FileName As String, Result As Object) As Hresult
Function LoadSysIcon(ID As Long, Result As Object) As Hresult
Function GetIconCount(FileName As String, Result As Object) As Hresult


Title: Re: DLLC status
Post by: JRS on April 26, 2020, 05:49:48 PM
It seems there is a standard DLL export function in the COM extension module that might work. I need to create a standard C callback function and be able to get its function address. In that function it can call the SBCallBack function in the COM extension that would already be loaded.

Code: Visual Basic
  1. 'this is the simple callback it takes one long arg and returns a long
  2. Private Declare Function ext_SBCallBack Lib "COM.dll" Alias "SBCallBack" (ByVal EntryPoint As Long, ByVal arg As Long) As Long
  3.  

The C code function for SBCallBack.

Code: C
  1. int __stdcall SBCallBack(int EntryPoint)
  2. {
  3. #pragma EXPORT
  4.  
  5.   pSupportTable pSt = g_pSt;
  6.   VARIABLE FunctionResult;
  7.   int retVal;
  8.  
  9.   if(pSt==NULL) return -1;
  10.   besHOOK_CALLSCRIBAFUNCTION(EntryPoint, 0, 0, &FunctionResult);
  11.   retVal = FunctionResult->Value.lValue;
  12.   besRELEASE(FunctionResult);
  13.   return retVal;
  14. }
  15.  

Update - I'm unable to call the SBCallBack function becuase the DLL it resides in is in SB format. Not as EXPORTable as I had hoped.

The function is called from VB which works as SB loaded the COM extension module. It makes me wonder if DLLC could provide a smart callback function and provide a function address WSO could use.

What besHOOK_CALLSCRIBAFUNCTION provides is a callback to a SB FUNCTION/SUB in the main thread. WSO is like having a dynamic VB you interface with using COM/OLE automation.

I've attached the IDL file for WSO.
Title: Re: DLLC status
Post by: JRS on April 28, 2020, 07:15:03 AM
If DLLC isn't a good fit to create a dynamic callback function(s), I may create a C extension module with the only functionality being establishing standard callback WSO functions, assigning a SB callback and returning a function pointer to be use by WSO for events.
Title: Re: DLLC status
Post by: JRS on May 05, 2020, 01:10:36 PM
Even VBA has a CallByName() API like ScriptBasic's COM extension.

CallByName in VBA (https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/callbyname-function)
Title: Re: DLLC status
Post by: JRS on May 07, 2020, 10:52:13 PM
Charles,

I was testing the DLLcFreeImage1.sb example for DLLC and it fails trying to load the FreeImage.dll.

fih=dllc_file("FreeImage.dll") 

The DLL is in the same directory as the script. I tried a full path but no luck.

I download the latest release of the DLL before testing on my Widows 10 laptop.

Can you give it a try on your end?
Title: Re: DLLC status
Post by: JRS on May 08, 2020, 09:41:48 AM
My bad. I didn't have Oxygen.dll in the working ScriptBASIC directory.


At least I got by the load error.

I dies on this line.

print dllc_call(Version) & "\n"

I wonder if the new freeimage.dll doesn't use mangled function names and that is the issue?

It seems the DLLC Tests directory of scripts work. Not sure what is the problem is with freeimage.

Update

It seems the DLL function names are okay. It's when I try to call  them does the script return to a command promt.

Fails on this line.

print dllc_call(Version) & "\n"

Here is the dumpbin/EXPORTS for FreeImage.dll (32 bit)


C:\ScriptBASIC\bin>dumpbin /EXPORTS FreeImage.dll
Microsoft (R) COFF Binary File Dumper Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


Dump of file FreeImage.dll

File Type: DLL

  Section contains the following exports for FreeImage.dll

           0 characteristics
    FFFFFFFF time date stamp
        0.00 version
           1 ordinal base
         255 number of functions
         255 number of names

    ordinal hint RVA      name

        194    0 00007480 FreeImage_OutputMessageProc
          1    1 00008520 _FreeImage_AcquireMemory@12
          2    2 00072410 _FreeImage_AdjustBrightness@12
          3    3 00072BD0 _FreeImage_AdjustColors@32
          4    4 000724F0 _FreeImage_AdjustContrast@12
          5    5 00071E70 _FreeImage_AdjustCurve@12
          6    6 00072300 _FreeImage_AdjustGamma@12
          7    7 00001B90 _FreeImage_Allocate@24
          8    8 00069800 _FreeImage_AllocateEx@36
          9    9 000692C0 _FreeImage_AllocateExT@40
         10    A 00001B60 _FreeImage_AllocateHeader@28
         11    B 00001AE0 _FreeImage_AllocateHeaderForBits@36
         12    C 00001B20 _FreeImage_AllocateHeaderT@32
         13    D 00001BC0 _FreeImage_AllocateT@28
         14    E 0005A4A0 _FreeImage_AppendPage@8
         15    F 00072C80 _FreeImage_ApplyColorMapping@24
         16   10 00073300 _FreeImage_ApplyPaletteIndexMapping@20
         17   11 00001E20 _FreeImage_Clone@4
         18   12 000034B0 _FreeImage_CloneMetadata@8
         19   13 00061FA0 _FreeImage_CloneTag@4
         20   14 00008410 _FreeImage_CloseMemory@4
         21   15 00059EB0 _FreeImage_CloseMultiBitmap@8
         22   16 0003FC80 _FreeImage_ColorQuantize@8
         23   17 0003FCA0 _FreeImage_ColorQuantizeEx@20
         24   18 00075920 _FreeImage_Composite@16
         25   19 000400D0 _FreeImage_ConvertFromRawBits@36
         26   1A 0003FFC0 _FreeImage_ConvertFromRawBitsEx@44
         27   1B 000426B0 _FreeImage_ConvertLine16To24_555@12
         28   1C 00042760 _FreeImage_ConvertLine16To24_565@12
         29   1D 000433A0 _FreeImage_ConvertLine16To32_555@12
         30   1E 00043450 _FreeImage_ConvertLine16To32_565@12
         31   1F 00044430 _FreeImage_ConvertLine16To4_555@12
         32   20 00044520 _FreeImage_ConvertLine16To4_565@12
         33   21 00044E60 _FreeImage_ConvertLine16To8_555@12
         34   22 00044F20 _FreeImage_ConvertLine16To8_565@12
         35   23 00041AD0 _FreeImage_ConvertLine16_555_To16_565@12
         36   24 00040EA0 _FreeImage_ConvertLine16_565_To16_555@12
         37   25 00040D10 _FreeImage_ConvertLine1To16_555@16
         38   26 00041940 _FreeImage_ConvertLine1To16_565@16
         39   27 00042560 _FreeImage_ConvertLine1To24@16
         40   28 00043230 _FreeImage_ConvertLine1To32@16
         41   29 00043540 _FreeImage_ConvertLine1To32MapTransparency@24
         42   2A 00044310 _FreeImage_ConvertLine1To4@12
         43   2B 00044DD0 _FreeImage_ConvertLine1To8@12
         44   2C 000412C0 _FreeImage_ConvertLine24To16_555@12
         45   2D 00041EE0 _FreeImage_ConvertLine24To16_565@12
         46   2E 00043500 _FreeImage_ConvertLine24To32@12
         47   2F 00044610 _FreeImage_ConvertLine24To4@12
         48   30 00044FF0 _FreeImage_ConvertLine24To8@12
         49   31 00041320 _FreeImage_ConvertLine32To16_555@12
         50   32 00041F40 _FreeImage_ConvertLine32To16_565@12
         51   33 00042800 _FreeImage_ConvertLine32To24@12
         52   34 000446C0 _FreeImage_ConvertLine32To4@12
         53   35 00045080 _FreeImage_ConvertLine32To8@12
         54   36 00040DB0 _FreeImage_ConvertLine4To16_555@16
         55   37 000419E0 _FreeImage_ConvertLine4To16_565@16
         56   38 000425D0 _FreeImage_ConvertLine4To24@16
         57   39 000432C0 _FreeImage_ConvertLine4To32@16
         58   3A 000435D0 _FreeImage_ConvertLine4To32MapTransparency@24
         59   3B 00044E10 _FreeImage_ConvertLine4To8@12
         60   3C 00040E30 _FreeImage_ConvertLine8To16_555@16
         61   3D 00041A60 _FreeImage_ConvertLine8To16_565@16
         62   3E 00042650 _FreeImage_ConvertLine8To24@16
         63   3F 00043340 _FreeImage_ConvertLine8To32@16
         64   40 00043690 _FreeImage_ConvertLine8To32MapTransparency@24
         65   41 00044380 _FreeImage_ConvertLine8To4@16
         66   42 00041380 _FreeImage_ConvertTo16Bits555@4
         67   43 00041FA0 _FreeImage_ConvertTo16Bits565@4
         68   44 00042850 _FreeImage_ConvertTo24Bits@4
         69   45 00043710 _FreeImage_ConvertTo32Bits@4
         70   46 00044770 _FreeImage_ConvertTo4Bits@4
         71   47 00045110 _FreeImage_ConvertTo8Bits@4
         72   48 00045D50 _FreeImage_ConvertToFloat@4
         73   49 00045800 _FreeImage_ConvertToGreyscale@4
         74   4A 00046610 _FreeImage_ConvertToRGB16@4
         75   4B 000067C0 _FreeImage_ConvertToRGBA16@4
         76   4C 00006C40 _FreeImage_ConvertToRGBAF@4
         77   4D 00046A70 _FreeImage_ConvertToRGBF@4
         78   4E 00040100 _FreeImage_ConvertToRawBits@32
         79   4F 00047230 _FreeImage_ConvertToStandardType@8
         80   50 00047340 _FreeImage_ConvertToType@12
         81   51 0004E7C0 _FreeImage_ConvertToUINT16@4
         82   52 00074D70 _FreeImage_Copy@20
         83   53 00002EE0 _FreeImage_CreateICCProfile@12
         84   54 00061F20 _FreeImage_CreateTag@0
         85   55 00075660 _FreeImage_CreateView@20
         86   56 0000D550 _FreeImage_DeInitialise@0
         87   57 0005A600 _FreeImage_DeletePage@8
         88   58 00061F60 _FreeImage_DeleteTag@4
         89   59 00002F70 _FreeImage_DestroyICCProfile@4
         90   5A 00050150 _FreeImage_Dither@8
         91   5B 00069830 _FreeImage_EnlargeCanvas@28
         92   5C 0000DE60 _FreeImage_FIFSupportsExportBPP@8
         93   5D 0000DE90 _FreeImage_FIFSupportsExportType@8
         94   5E 0000DEC0 _FreeImage_FIFSupportsICCProfiles@4
         95   5F 0000DEF0 _FreeImage_FIFSupportsNoPixels@4
         96   60 0000DE00 _FreeImage_FIFSupportsReading@4
         97   61 0000DE30 _FreeImage_FIFSupportsWriting@4
         98   62 00069170 _FreeImage_FillBackground@12
         99   63 00003480 _FreeImage_FindCloseMetadata@4
        100   64 00003300 _FreeImage_FindFirstMetadata@12
        101   65 00003400 _FreeImage_FindNextMetadata@8
        102   66 00076030 _FreeImage_FlipHorizontal@4
        103   67 00076390 _FreeImage_FlipVertical@4
        104   68 000728C0 _FreeImage_GetAdjustColorsLookupTable@32
        105   69 00003020 _FreeImage_GetBPP@4
        106   6A 00002B40 _FreeImage_GetBackgroundColor@8
        107   6B 000024B0 _FreeImage_GetBits@4
        108   6C 00002A80 _FreeImage_GetBlueMask@4
        109   6D 0006B9D0 _FreeImage_GetChannel@8
        110   6E 000025B0 _FreeImage_GetColorType@4
        111   6F 00003100 _FreeImage_GetColorsUsed@4
        112   70 0006C840 _FreeImage_GetComplexChannel@8
        113   71 00007440 _FreeImage_GetCopyrightMessage@0
        114   72 00003130 _FreeImage_GetDIBSize@4
        115   73 000031E0 _FreeImage_GetDotsPerMeterX@4
        116   74 00003210 _FreeImage_GetDotsPerMeterY@4
        117   75 0000DAF0 _FreeImage_GetFIFCount@0
        118   76 0000DD80 _FreeImage_GetFIFDescription@4
        119   77 0000DD40 _FreeImage_GetFIFExtensionList@4
        120   78 0000DF20 _FreeImage_GetFIFFromFilename@4
        121   79 0000E1C0 _FreeImage_GetFIFFromFilenameU@4
        122   7A 0000DB00 _FreeImage_GetFIFFromFormat@4
        123   7B 0000DBF0 _FreeImage_GetFIFFromMime@4
        124   7C 0000DD10 _FreeImage_GetFIFMimeType@4
        125   7D 0000DDC0 _FreeImage_GetFIFRegExpr@4
        126   7E 00007A10 _FreeImage_GetFileType@8
        127   7F 000079A0 _FreeImage_GetFileTypeFromHandle@12
        128   80 00007AF0 _FreeImage_GetFileTypeFromMemory@8
        129   81 00007A80 _FreeImage_GetFileTypeU@8
        130   82 0000DCE0 _FreeImage_GetFormatFromFIF@4
        131   83 000029E0 _FreeImage_GetGreenMask@4
        132   84 00002FF0 _FreeImage_GetHeight@4
        133   85 000725D0 _FreeImage_GetHistogram@12
        134   86 00002EC0 _FreeImage_GetICCProfile@4
        135   87 000028C0 _FreeImage_GetImageType@4
        136   88 000032D0 _FreeImage_GetInfo@4
        137   89 000032A0 _FreeImage_GetInfoHeader@4
        138   8A 00003050 _FreeImage_GetLine@4
        139   8B 0005AA20 _FreeImage_GetLockedPageNumbers@12
        140   8C 00003EC0 _FreeImage_GetMemorySize@4
        141   8D 00003C90 _FreeImage_GetMetadata@16
        142   8E 00003E10 _FreeImage_GetMetadataCount@8
        143   8F 0005A350 _FreeImage_GetPageCount@4
        144   90 00003190 _FreeImage_GetPalette@4
        145   91 000030A0 _FreeImage_GetPitch@4
        146   92 00008740 _FreeImage_GetPixelColor@16
        147   93 00008630 _FreeImage_GetPixelIndex@16
        148   94 00002940 _FreeImage_GetRedMask@4
        149   95 000085F0 _FreeImage_GetScanLine@8
        150   96 00062260 _FreeImage_GetTagCount@4
        151   97 00062200 _FreeImage_GetTagDescription@4
        152   98 00062220 _FreeImage_GetTagID@4
        153   99 000621E0 _FreeImage_GetTagKey@4
        154   9A 00062280 _FreeImage_GetTagLength@4
        155   9B 00062240 _FreeImage_GetTagType@4
        156   9C 000622A0 _FreeImage_GetTagValue@4
        157   9D 00002520 _FreeImage_GetThumbnail@4
        158   9E 00002D60 _FreeImage_GetTransparencyCount@4
        159   9F 00002CF0 _FreeImage_GetTransparencyTable@4
        160   A0 00002E80 _FreeImage_GetTransparentIndex@4
        161   A1 00007420 _FreeImage_GetVersion@0
        162   A2 00002FC0 _FreeImage_GetWidth@4
        163   A3 00002B20 _FreeImage_HasBackgroundColor@4
        164   A4 000028E0 _FreeImage_HasPixels@4
        165   A5 00002900 _FreeImage_HasRGBMasks@4
        166   A6 0000D010 _FreeImage_Initialise@4
        167   A7 0005A530 _FreeImage_InsertPage@12
        168   A8 00071A90 _FreeImage_Invert@4
        169   A9 00007450 _FreeImage_IsLittleEndian@0
        170   AA 0000DAC0 _FreeImage_IsPluginEnabled@4
        171   AB 00002C70 _FreeImage_IsTransparent@4
        172   AC 00076E80 _FreeImage_JPEGCrop@24
        173   AD 00076FA0 _FreeImage_JPEGCropU@24
        174   AE 00076DF0 _FreeImage_JPEGTransform@16
        175   AF 00077030 _FreeImage_JPEGTransformCombined@32
        176   B0 00077150 _FreeImage_JPEGTransformCombinedFromMemory@32
        177   B1 000770C0 _FreeImage_JPEGTransformCombinedU@32
        178   B2 00076B10 _FreeImage_JPEGTransformFromHandle@40
        179   B3 00076F10 _FreeImage_JPEGTransformU@16
        180   B4 0000D710 _FreeImage_Load@12
        181   B5 0000D680 _FreeImage_LoadFromHandle@16
        182   B6 00008450 _FreeImage_LoadFromMemory@12
        183   B7 0005AAE0 _FreeImage_LoadMultiBitmapFromMemory@12
        184   B8 0000D7A0 _FreeImage_LoadU@12
        185   B9 0005A680 _FreeImage_LockPage@8
        186   BA 000066D0 _FreeImage_LookupSVGColor@16
        187   BB 000065E0 _FreeImage_LookupX11Color@16
        188   BC 00079C70 _FreeImage_MakeThumbnail@12
        189   BD 0005A970 _FreeImage_MovePage@12
        190   BE 000791C0 _FreeImage_MultigridPoissonSolver@8
        191   BF 000083A0 _FreeImage_OpenMemory@8
        192   C0 00059770 _FreeImage_OpenMultiBitmap@24
        193   C1 00059AC0 _FreeImage_OpenMultiBitmapFromHandle@16
        195   C2 000752B0 _FreeImage_Paste@20
        196   C3 00075EF0 _FreeImage_PreMultiplyWithAlpha@4
        197   C4 000085A0 _FreeImage_ReadMemory@16
        198   C5 0000DA20 _FreeImage_RegisterExternalPlugin@20
        199   C6 0000DA00 _FreeImage_RegisterLocalPlugin@20
        200   C7 00079C10 _FreeImage_Rescale@16
        201   C8 00079970 _FreeImage_RescaleRect@36
        202   C9 0006E6D0 _FreeImage_Rotate@16
        203   CA 0006B3D0 _FreeImage_RotateEx@48
        204   CB 0000D8E0 _FreeImage_Save@16
        205   CC 00059BF0 _FreeImage_SaveMultiBitmapToHandle@20
        206   CD 0005ABE0 _FreeImage_SaveMultiBitmapToMemory@16
        207   CE 0000D820 _FreeImage_SaveToHandle@20
        208   CF 000084B0 _FreeImage_SaveToMemory@16
        209   D0 0000D970 _FreeImage_SaveU@16
        210   D1 00008550 _FreeImage_SeekMemory@12
        211   D2 00002C30 _FreeImage_SetBackgroundColor@8
        212   D3 0006C390 _FreeImage_SetChannel@12
        213   D4 0006CD70 _FreeImage_SetComplexChannel@12
        214   D5 00003240 _FreeImage_SetDotsPerMeterX@8
        215   D6 00003270 _FreeImage_SetDotsPerMeterY@8
        216   D7 00003830 _FreeImage_SetMetadata@16
        217   D8 00003D70 _FreeImage_SetMetadataKeyValue@16
        218   D9 00007460 _FreeImage_SetOutputMessage@4
        219   DA 00007470 _FreeImage_SetOutputMessageStdCall@4
        220   DB 00008A80 _FreeImage_SetPixelColor@16
        221   DC 00008950 _FreeImage_SetPixelIndex@16
        222   DD 0000DA90 _FreeImage_SetPluginEnabled@8
        223   DE 000623D0 _FreeImage_SetTagCount@8
        224   DF 00062320 _FreeImage_SetTagDescription@8
        225   E0 00062390 _FreeImage_SetTagID@8
        226   E1 000622C0 _FreeImage_SetTagKey@8
        227   E2 000623F0 _FreeImage_SetTagLength@8
        228   E3 000623B0 _FreeImage_SetTagType@8
        229   E4 00062410 _FreeImage_SetTagValue@8
        230   E5 00002540 _FreeImage_SetThumbnail@8
        231   E6 00002D80 _FreeImage_SetTransparencyTable@12
        232   E7 00002D10 _FreeImage_SetTransparent@8
        233   E8 00002E10 _FreeImage_SetTransparentIndex@8
        234   E9 000732E0 _FreeImage_SwapColors@16
        235   EA 00073600 _FreeImage_SwapPaletteIndices@12
        236   EB 00066770 _FreeImage_TagToString@12
        237   EC 00008580 _FreeImage_TellMemory@4
        238   ED 00050370 _FreeImage_Threshold@8
        239   EE 00051B40 _FreeImage_TmoDrago03@20
        240   EF 00054590 _FreeImage_TmoFattal02@20
        241   F0 00055190 _FreeImage_TmoReinhard05@20
        242   F1 000550E0 _FreeImage_TmoReinhard05Ex@36
        243   F2 000551E0 _FreeImage_ToneMapping@24
        244   F3 00001BF0 _FreeImage_Unload@4
        245   F4 0005A7E0 _FreeImage_UnlockPage@12
        246   F5 00007B60 _FreeImage_Validate@8
        247   F6 00007B40 _FreeImage_ValidateFromHandle@12
        248   F7 00007C40 _FreeImage_ValidateFromMemory@8
        249   F8 00007BD0 _FreeImage_ValidateU@8
        250   F9 000085C0 _FreeImage_WriteMemory@16
        251   FA 0005BD50 _FreeImage_ZLibCRC32@12
        252   FB 0005B980 _FreeImage_ZLibCompress@16
        253   FC 0005BC80 _FreeImage_ZLibGUnzip@16
        254   FD 0005BA40 _FreeImage_ZLibGZip@16
        255   FE 0005B9E0 _FreeImage_ZLibUncompress@16

  Summary

      190000 .data
      16F000 .rdata
       17000 .reloc
        1000 .rsrc
      2AB000 .text
        1000 _RDATA

C:\ScriptBASIC\bin>
Title: Re: DLLC status
Post by: JRS on May 08, 2020, 03:44:10 PM
Back to my original issue of using DLLC to define my callback function and return a function pointer.

dllco2_b.sb seems close.

Code: Script BASIC
  1.  
  2.   include dllc.sbi
  3.  
  4.   oxy=dllfile("oxygen.dll")
  5.  
  6.   o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  7.   o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  8.   o2_error = dllproc( oxy, "o2_error c*=()         " )
  9.   o2_errno = dllproc( oxy, "o2_errno i =()         " )
  10.   o2_len   = dllproc( oxy, "o2_len   i =()         " )
  11.   o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )
  12.  
  13.   dllcall o2_mode,1
  14.   src="""
  15.  extern
  16.  
  17.  function funA(sys v) as sys
  18.  print v
  19.  end function
  20.  
  21.  sub finish()
  22.  terminate
  23.  end sub
  24.  
  25.  end extern
  26.  
  27.  addr funA
  28.  """
  29.  
  30.   function oxygen(src)
  31.   dllcall o2_basic,src
  32.   if (dllcall(o2_errno)<>0) then
  33.     dllprnt dllcall(o2_error)
  34.     a=0
  35.   else
  36.     a=dllcall(o2_exec,0)
  37.   end if
  38.   oxygen=a
  39.   end function
  40.  
  41.   a=oxygen(src)
  42.   dllcald(a,123)
  43.   dllprnt "Return code: " & a & "\n"
  44.   dllfile
  45.   ' line input q
  46.  
  47.  

Return code: 15859792

Is this what I  refer to as an O2 virtual DLL function?

Is the returned value the function pointer address?

Do I need to call the finish() sub before exiting SB?

Can there be more than one function in the O2 code section? If so, how do I call the functions / subs?

Update

dllco2_c.sb answered my questions about multiple O2 functions and  calling finish.

Title: Re: DLLC status
Post by: JRS on May 08, 2020, 09:04:51 PM
Charles,

In the dllco2_e.sb example I noticed an additional argument I haven't seen before. dllcald(a,1)

Hello   = dllproc(a,"Hello   c*=(c*value) ", dllcald(a,1) )

Is this a reference to the link sub?

I found an O2 callback function in an IUP example.

https://www.oxygenbasic.org/forum/index.php?topic=1843.msg20025#msg20025

This should help with my virtual callback function in DLLC.
Title: Re: DLLC status
Post by: Charles Pegge on May 08, 2020, 11:22:14 PM
Sorry John,

I have to withdraw from programming activities for a while. It takes too much time and mental energy in my current circumstances, so I am protecting my health.
Title: Re: DLLC status
Post by: JRS on May 09, 2020, 06:45:48 AM
No problem. Take care of yourself and mum.

The only mystery is why freeimage won't work with the current release of O2.

Roland,

If you get a moment can you try accessing the freeimage.dll in O2 and see if it's something I'm doing wrong. The only unique thing about freeimage is its scrambled function names.

Other DLLC examples seem to be working. I really would like to add DLLC to the next ScriptBasic release.
Title: Re: DLLC status
Post by: jack on May 09, 2020, 12:51:18 PM
@John
what do you mean by "scrambled function names" ?
Title: Re: DLLC status
Post by: JRS on May 09, 2020, 01:22:48 PM
Hi Jack,

Check out the dumpbin output I posted on the page 1 of this thread.
Title: Re: DLLC status
Post by: Aurel on May 09, 2020, 02:02:57 PM
John
That is a lot of functions from FreeImage.dll
and who knows what might be wrong .
Do you can test loading of that dll ?

int fiDLL = LoadLibrary "FreeImage.dll"
print str(fiDLL) ' if is greater than 0 then is loaded
Title: Re: DLLC status
Post by: JRS on May 09, 2020, 02:12:26 PM
Aurel,

The DLL loads fine. Calling it drops ScriptBasic to the command prompt. Using the same DLLC code I can call Oxygen.dll without issue.

The script worked in prior versions O2.
Title: Re: DLLC status
Post by: jack on May 09, 2020, 07:13:19 PM
I can't get it to compile with FreeBasic, no matter what I do ld can't find the symbols
it does compile if I call the dll functions by ordinal but crashes when run
Title: Re: DLLC status
Post by: jack on May 09, 2020, 07:41:43 PM
the 64-bit version works ok
the function names are not scrambled
Title: Re: DLLC status
Post by: JRS on May 09, 2020, 09:02:08 PM
I can't get it to compile with FreeBasic, no matter what I do ld can't find the symbols
it does compile if I call the dll functions by ordinal but crashes when run

Thanks Jack!

That confirms it's a freeimage.dll (32bit) issue, not DLLC (O2).
Title: Re: DLLC status
Post by: jack on May 09, 2020, 10:15:37 PM
sorry John
I took a nap and tried again and both 32 and 64-bit versions work ok using FB, I will try O2 and see what happens
where can I find Freeimage.inc ?
Title: Re: DLLC status
Post by: jack on May 10, 2020, 01:52:54 AM
I am not fluent in O2, but this code works in 32-bit, modified example from https://www.oxygenbasic.org/forum/index.php?topic=631.msg5169#msg5169
Code: [Select]
'include "Freeimage.inc"
'include "RTL64.inc"

type FREE_IMAGE_FORMAT as long
enum
FIF_UNKNOWN = -1
FIF_BMP = 0
FIF_ICO = 1
FIF_JPEG = 2
FIF_JNG = 3
FIF_KOALA = 4
FIF_LBM = 5
FIF_IFF = FIF_LBM
FIF_MNG = 6
FIF_PBM = 7
FIF_PBMRAW = 8
FIF_PCD = 9
FIF_PCX = 10
FIF_PGM = 11
FIF_PGMRAW = 12
FIF_PNG = 13
FIF_PPM = 14
FIF_PPMRAW = 15
FIF_RAS = 16
FIF_TARGA = 17
FIF_TIFF = 18
FIF_WBMP = 19
FIF_PSD = 20
FIF_CUT = 21
FIF_XBM = 22
FIF_XPM = 23
FIF_DDS = 24
FIF_GIF = 25
FIF_HDR = 26
FIF_FAXG3 = 27
FIF_SGI = 28
FIF_EXR = 29
FIF_J2K = 30
FIF_JP2 = 31
FIF_PFM = 32
FIF_PICT = 33
FIF_RAW = 34
FIF_WEBP = 35
FIF_JXR = 36
end enum

type FREE_IMAGE_FILTER as long

type FREE_IMAGE_FILTER as long
enum
FILTER_BOX = 0
FILTER_BICUBIC = 1
FILTER_BILINEAR = 2
FILTER_BSPLINE = 3
FILTER_CATMULLROM = 4
FILTER_LANCZOS3 = 5
end enum

declare function FreeImageGetVersion lib "FreeImage.dll" Alias "_FreeImage_GetVersion@0"()  as zstring ptr
declare function FreeImage_Load lib "FreeImage.dll" Alias "_FreeImage_Load@12" (byval fif as long, byval filename as zstring ptr, byval flags as long) as sys
declare function FreeImage_GetWidth lib "FreeImage.dll" Alias "_FreeImage_GetWidth@4"(byval dib as sys) as ulong
declare function FreeImage_GetHeight lib "FreeImage.dll" Alias "_FreeImage_GetHeight@4"(byval dib as sys) as ulong
declare function FreeImage_Rescale lib "FreeImage.dll" Alias "_FreeImage_Rescale@16"(byval dib as sys, byval dst_width as long, byval dst_height as long, byval filter as long) as sys
declare function FreeImage_Save lib "FreeImage.dll" Alias "_FreeImage_Save@16"(byval fif as long, byval dib as sys, byval filename as zstring ptr, byval flags as long) as BOOL

sys img,imr
long lx,ly,tx,ty,r

img = FreeImage_Load FIF_PNG,"world_flip.png",0
lx  = FreeImage_GetWidth img
ly  = FreeImage_GetHeight img
tx  = lx/2
ty  = ly/2
imr = FreeImage_Rescale img,tx,ty,FILTER_BOX
r   = FreeImage_Save FIF_JPEG,imr,"t.jpg",0
print r
print tx " x " ty "  ok"

print FreeImageGetVersion()
Title: Re: DLLC status
Post by: jack on May 10, 2020, 01:55:03 AM
and this works in 64-bit
Code: [Select]
'include "Freeimage.inc"
'include "RTL64.inc"

type FREE_IMAGE_FORMAT as long
enum
FIF_UNKNOWN = -1
FIF_BMP = 0
FIF_ICO = 1
FIF_JPEG = 2
FIF_JNG = 3
FIF_KOALA = 4
FIF_LBM = 5
FIF_IFF = FIF_LBM
FIF_MNG = 6
FIF_PBM = 7
FIF_PBMRAW = 8
FIF_PCD = 9
FIF_PCX = 10
FIF_PGM = 11
FIF_PGMRAW = 12
FIF_PNG = 13
FIF_PPM = 14
FIF_PPMRAW = 15
FIF_RAS = 16
FIF_TARGA = 17
FIF_TIFF = 18
FIF_WBMP = 19
FIF_PSD = 20
FIF_CUT = 21
FIF_XBM = 22
FIF_XPM = 23
FIF_DDS = 24
FIF_GIF = 25
FIF_HDR = 26
FIF_FAXG3 = 27
FIF_SGI = 28
FIF_EXR = 29
FIF_J2K = 30
FIF_JP2 = 31
FIF_PFM = 32
FIF_PICT = 33
FIF_RAW = 34
FIF_WEBP = 35
FIF_JXR = 36
end enum

type FREE_IMAGE_FILTER as long

type FREE_IMAGE_FILTER as long
enum
FILTER_BOX = 0
FILTER_BICUBIC = 1
FILTER_BILINEAR = 2
FILTER_BSPLINE = 3
FILTER_CATMULLROM = 4
FILTER_LANCZOS3 = 5
end enum

declare function FreeImageGetVersion lib "FreeImage.dll" Alias "FreeImage_GetVersion"()  as zstring ptr
declare function FreeImage_Load lib "FreeImage.dll" Alias "FreeImage_Load" (byval fif as long, byval filename as zstring ptr, byval flags as long) as sys
declare function FreeImage_GetWidth lib "FreeImage.dll" Alias "FreeImage_GetWidth"(byval dib as sys) as ulong
declare function FreeImage_GetHeight lib "FreeImage.dll" Alias "FreeImage_GetHeight"(byval dib as sys) as ulong
declare function FreeImage_Rescale lib "FreeImage.dll" Alias "FreeImage_Rescale"(byval dib as sys, byval dst_width as long, byval dst_height as long, byval filter as long) as sys
declare function FreeImage_Save lib "FreeImage.dll" Alias "FreeImage_Save"(byval fif as long, byval dib as sys, byval filename as zstring ptr, byval flags as long) as BOOL

sys img,imr
long lx,ly,tx,ty,r

img = FreeImage_Load FIF_PNG,"world_flip.png",0
lx  = FreeImage_GetWidth img
ly  = FreeImage_GetHeight img
tx  = lx/2
ty  = ly/2
imr = FreeImage_Rescale img,tx,ty,FILTER_BOX
r   = FreeImage_Save FIF_JPEG,imr,"t.jpg",0
print r
print tx " x " ty "  ok"

print FreeImageGetVersion()
Title: Re: DLLC status
Post by: JRS on May 10, 2020, 03:48:26 AM
Jack,

Are you using the latest version of FreeImage?

I wonder if the problem is FreeImage requires some constant set before executing any functions?
Title: Re: DLLC status
Post by: jack 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
Title: Re: DLLC status
Post by: JRS 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?
Title: Re: DLLC status
Post by: JRS 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.  


Title: Re: DLLC status
Post by: Charles Pegge 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.
Title: Re: DLLC status
Post by: JRS 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.
Title: Re: DLLC status
Post by: JRS 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.
Title: Re: DLLC status
Post by: JRS 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.
Title: Re: DLLC status
Post by: JRS 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.
Title: Re: DLLC status
Post by: JRS 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?
Title: Re: DLLC status
Post by: JRS 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.
Title: Re: DLLC status
Post by: Charles Pegge on July 22, 2020, 01:25:52 PM
I remember we tried to access the hook function, but it was set to null.
Title: Re: DLLC status
Post by: JRS 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 (https://www.allbasic.info/forum/index.php?topic=493.msg5284#msg5284) to my OCX form example.
Title: Re: DLLC status
Post by: JRS 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>

Title: Re: DLLC status
Post by: JRS 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 (http://veretennikov.org/Default.aspx?f=WSO%2fDefault.aspx) 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
Title: Re: DLLC status
Post by: Charles Pegge 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.
Title: Re: DLLC status
Post by: JRS on August 03, 2020, 07:43:58 AM
I think we should abandon the threaded IUP approach.

Can you post an example of using DLLC to generate a dynamic on the fly callback function? Just a modified version of one of your existing virtual function examples would be great. (first step)
Title: Re: DLLC status
Post by: Charles Pegge on August 03, 2020, 08:13:57 AM
I think the stability problem is between DLLC and SB. IUP is ok.

I am looking at variations of projectsC\ScriptBasic\IUP\ButtonsBootB.sb & ButtonsB.sb
Title: Re: DLLC status
Post by: JRS on August 03, 2020, 08:24:34 AM
Sounds good. Looking forward to what you find.

FYI: Dave's COM DLL has a working SB callback function you could call with DLLC FFI. (not a SB ext. module call)

Thanks again Charles for supporting your ScriptBasic extension module. It brings together the best of both worlds of an interpreter and compiler.
Title: Re: DLLC status
Post by: JRS on August 06, 2020, 11:47:20 AM
OT Update

When DLLC and IUP  failed for my project I went for the only option I had left which was the VB6 ActiveX DLL form and using the COM extension module to interface with it.

I wasn't able to thread the form but was able to start a SB thread from a callback. I'm using MT to set inter-process variables and use a VB timer control to callback to SB to update the UI. Working great so far.

Title: Re: DLLC status
Post by: JRS on August 20, 2020, 12:15:30 AM
Charles,

Do you have any news about your efforts with DLLC and callbacks without creating a thread?

Title: Re: DLLC status
Post by: Charles Pegge on August 20, 2020, 01:44:28 AM
Unfortunately not. I'm going to have to give up on DLLC.
Title: Re: DLLC status
Post by: JRS on August 20, 2020, 02:11:38 AM
Sad seeing you invested so much of your time into the interface.

Could you post an example of a virtual callback function so I can see what I can do to keep DLLC relevant?

Title: Re: DLLC status
Post by: Charles Pegge on August 20, 2020, 12:14:53 PM

projectsC\ScriptBasic\DLLCtests\DllcSpec5BootT.sb

It was an interesting excercise in generics, but perhaps too far to be practical. I will not mourn the passing of DLLC.
Title: Re: DLLC status
Post by: JRS on August 20, 2020, 01:16:49 PM
Will you also be glad to rid yourself of ThinBasic now that Eros chose FreeBasic over o2?

I still plan on investing time in DLLC as it gives ScriptBasic an embeddable JIT compiler when speed becomes a factor.
Title: Re: DLLC status
Post by: Charles Pegge on August 20, 2020, 01:45:11 PM
It's a much simpler interface and requires no further maintenance.



https://www.thinbasic.com/community/content.php?47-thinBasic-1-10-8-x

Interesting proposal. I can see thinBasic using FreeBasic as a back-end since most thinBasic apps do not need to be interpretive.

Title: Re: DLLC status
Post by: JRS on August 20, 2020, 01:56:11 PM
Are you going to support your ThinBasic interface when Eros goes FB 64 bit?
Title: Re: DLLC status
Post by: Charles Pegge on August 20, 2020, 02:09:36 PM
Could do, but first I need to complete a self-compiling 64bit oxygen.
Title: Re: DLLC status
Post by: JRS on August 21, 2020, 02:22:05 AM
My understanding is Eros is converting ThinBasic to FreeBasic not just using it to extend the interpreter. Why would he want to use O2 as an extension to FreeBasic?

It would have been a big plus if Eros went with O2 instead of FreeBasic.

The only advantage using FB is it is now a C translator instead of an ASM compiler like O2.
Title: Re: DLLC status
Post by: JRS on August 21, 2020, 09:21:14 AM
Charles,

If I take over maintaining DLLC, will you be willing to answer questions I may have if I hit the wall? DLLC is complete as far as its intended role to replace DYC. The only change I would like to make is use O2 virtual functions to define callbacks and use the SB hook function to call SB functions and subs.

John
Title: Re: DLLC status
Post by: Charles Pegge on August 21, 2020, 05:49:49 PM
I am very tired. I just want to complete o2, wind down and retire.
Title: Re: DLLC status
Post by: JRS on August 21, 2020, 07:42:39 PM
You maintaining O2 will keep you mentally sharp. The brain needs to be challenged or it dies off starting with dementia.

There is nothing wrong with taking a break once O2 becomes production stable.

Title: Re: DLLC status
Post by: Charles Pegge on August 22, 2020, 05:44:28 AM
Creating compilers might be considered a form of dementia. I don't know if I will ever be able to fix those entangled neurons. :)
Title: Re: DLLC status
Post by: JRS on August 22, 2020, 05:58:26 AM
I was fortunate to inherit a language that is rock solid and easy to expand on. Building a compiler is like Elon building his spaceship to Mars.
Title: Re: DLLC status
Post by: JRS on September 08, 2020, 05:41:11 PM
Charles,

Since you lost interest in ScriptBasic and DLLC, I thought I would try embedding O2 in my VB6 projects. I may be able to create an ActiveX DLL to wrap O2 and interface with it via COM/OLE automation.

I can use O2's virtual function feature to create event callback routines.

Title: Re: DLLC status
Post by: Charles Pegge on September 09, 2020, 01:41:03 AM
It sounds complicated but good luck!
Title: Re: DLLC status
Post by: JRS on September 09, 2020, 02:15:15 AM
VB6 can call Windows DLL libraries natively without a FFI interface. I already have a working proof of concept running. I just need to define an COM/OLE API interface to O2 as a compiler wrapped as an ActiveX DLL interface.

This will allow me to use O2 with VBA in Office for example.

I'm going get my feet wet by embedding ScriptBasic as an ActiveX DLL before attempting doing the same with O2.

Actually the ScriptBasic Windows IDE/Debugugger is a good example how ScriptBasic can be embedded as a control.

Title: Re: DLLC status
Post by: JRS on September 09, 2020, 01:29:19 PM
Charles,

As it turns out all I have to do to create a ScriptBasic ActiveX DLL is gut the forms from the IDE and create exportable methods and properties and compile it as a COM DLL. Bonus is one can run their code in single step debug mode as well.