https://bugs.documentfoundation.org/show_bug.cgi?id=161996

            Bug ID: 161996
           Summary: LO Basic: Arrays are not passed to DLL (in C/C++
                    format).
           Product: LibreOffice
           Version: 24.2.4.2 release
          Hardware: All
                OS: Windows (All)
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: LibreOffice
          Assignee: [email protected]
          Reporter: [email protected]

Description:
First the bunch of Basic code with some notes that should help:

' ... in Standard/Module1 of a Calc sheet.
' Option Compatible ==> This does not change the issue.

Declare Function GetDiag Lib "C:\.........\Math.dll" _
  Alias "GetDiag" (ByVal varName As String, _
                         A() As Double, _
                   ByVal len As Long, _
                   ByVal FunctionName As String, _
                         B() As Double, _
                         C() As Double) As Long
' Declaring 'A' instead of 'A()', 'B' insteaf of 'B()' and 'C' instead of 'C()'
does not change the issue.

Private Sub Test()
    Dim A() As Double, B() As Double, C() As Double
    ' ...... '
    ReDim A(70)
    ReDim B(70)
    ReDim C(70)
' Initializing A() with values, while B() and C() all '0'.
    R = GetDiag("f", A(0), 71, B(0), C(0))
' using 'A' or 'A()' gives Basic error.  Found no description of the syntax for
DLL on book and forums.
' The prototype of GetDiag in DLL is :
' __declspec( dllexport ) long __stdcall GetDiag(char* varName, double* A, long
Len, char* FunctionName, double* B, double* C)
' The same DLL launched from a similar VBA code works perfectly.
' Both L.O. and DLL are for X64.
End Sub

To understand (the crash), with VS2022, I've attached the debugger of Math.dll
code to "soffice.bin" process and set a breakpoint at the very beginning of
GetDiag().
The result is that only A[0], B[0] and C[0] have the expected values, while the
following locations has values with no meaning.
As a further experiment, I invoke from Basic with R = GetDiag("f", A(0), 71,
A(1), A(2)), the debugger shows that the 3 pointers are not
contiguous, differently from what expected for a C array.  I've repeated the
eperiment using arrays of different types (Single, Long and Bytes) getting the
same issue.
>From "L.O. ask" i got the tip to debug LO targeting the MarshalArray() service.
After having evaluated the effort to set up the compiling environment for L.O.,
I've judged this too time expensive for me and therefore open this bug.
Thanks


Steps to Reproduce:
1.Write the Basic code in the description (or equivalent) in a Calc Sheet
module
2.With a test DLL code verify the array that L.O. Basic passes to it


Actual Results:
Only the first element of the array (A[0]) is passed, the other A[1],A[2] and
so on do not follow A[0] location

Expected Results:
Same as in "Actual Results"


Reproducible: Always


User Profile Reset: No

Additional Info:
I'm expecting that the memory location following the first array element A[0]
would include A[1] and so on, according to C/C++ convention for arrays.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to