Question : Passing a structure from VBA in Excel to a C DLL

Hi,

I am trying to pass a structure from VBA in Excel to a C DLL.
I have declared the array of strings as a member of a Type as follows:

Public Type pStruct
    numItems As Long
    schema As String
    qual As String
    fields(10) As String
End Type

In the C DLL I have made an identical Struct as follows:

typedef struct PTS_STRUCT{
      Int numItems
      Char* schema
      Char* qual
      Char** fields
}PTS_STRUCT;

When I try and access the first element of the PTS_STRUCT in the C DLL
fields[0], I get the string value that was set in VBA. However, when I try to access the second string (fields[1]) I get a segfault exception.

How should I go about passing the struct from Excel to the DLL to ensure that the memory of the array of strings can be accessed?

Thanks

Answer : Passing a structure from VBA in Excel to a C DLL

It looks like your C struct should be something like this from the way your VB structure is being used.
1:
2:
3:
4:
5:
6:
7:
typedef struct
	{
      int numItems;
      char* schema;
      char* qual;
      char* fields[1];
	} PTS_STRUCT;
Random Solutions  
 
programming4us programming4us