How to pass Complex Structure from VBA Macro to 64 bit XLL C++ Function

rajkumarbapu vrs 1 Reputation point
2021-08-15T07:34:56.357+00:00

How to pass Complex Structure from VBA Macro to 64 bit XLL C++ Function.
My part of the code is given below
C++ Code
typedef struct _oper
{
union
{
double num;//Able to pass value
LPSTR str;
WORD boolxll;
WORD err;
struct
{
struct _oper FAR *lparray;//Not sure how to create this structure in VBA
WORD rows;
WORD columns;
} array;
} val;
WORD type;
}OPER;
typedef OPER FAR *LPOPER;

LPOPER __stdcall MODEL_VERSION
//(char &s)
(LPOPER LPOPER_IOP1, LPOPER LPOPER_OP1,
LPOPER LPOPER_IOP2, LPOPER LPOPER_OP2,
LPOPER LPOPER_IOP3, LPOPER LPOPER_OP3,
LPOPER LPOPER_TEND,
LPOPER LPOPER_UNITS,
LPOPER LPOPER_MSG);

VBA Code
Type darray
lparray As oper
rows As Integer
columns As Integer
End Type

Type dval
num As Double
str As String
boolxll As Integer
err As Integer
array As darray
End Type

Type oper
val As dval
type As Integer
End Type

Private Declare PtrSafe Function MODEL_VERSION_XLL Lib "C:\Raj\Deact_XLL_64\x64\Debug\Deact_XLL_64.xll" (ByVal LPOPER_IOP1 As LongPtr, ByRef LPOPER_OP1 As LongPtr, ByRef LPOPER_IOP2 As LongPtr, ByRef LPOPER_OP2 As LongPtr, ByRef LPOPER_IOP3 As LongPtr, ByRef LPOPER_OP3 As LongPtr, ByRef LPOPER_TEND As LongPtr, ByRef LPOPER_UNITS As LongPtr, ByRef LPOPER_MSG As LongPtr) As LongPtr

Dim da As darray
da.lparray = "HT_Code_T1_R1"
Dim a1 As oper
Dim a2 As oper
Dim a3 As oper
Dim a4 As oper
Dim a5 As oper
Dim a6 As oper
Dim a7 As oper
Dim a8 As oper
Dim a9 As oper
a1.val.array = da 'Not sure how to pass data
a1.val.num = 225 'Value passed correctly
Dim p1 As LongPtr
p1 = VarPtr(a1)
'a2.val.array = HT_Data_T1_R1
'a3.val.array = HT_Code_T1_R2
'a4.val.array = HT_Data_T1_R2
'a5.val.array = HCK_Code_T1_R1
'a6.val.array = HCK_Data_T1_R1
'a7.val.array = TarDOS_T1
'a8.val.array = units
'a9.val.array = 0
temp = MODEL_VERSION_XLL(p1, VarPtr(a2), VarPtr(a3), VarPtr(a4), VarPtr(a5), VarPtr(a6), VarPtr(a7), VarPtr(a8), VarPtr(a9))

In 32 bit XLL without VBA type def and function prototyping everything worked fine, it is not working in 64 bit. By referencing any website I come to know about VBA type def and function prototyping. I am stuck in self referencing pointer. Not sure my approach is correct or not. I appreciate your help in advance.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,637 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,720 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Cesare Vesdani 11 Reputation points
    2021-08-15T21:33:47.173+00:00

    I don't know.

    1 person found this answer helpful.
    0 comments No comments