Thursday, 15 May 2014

excel - Accessing a nested structure in C++ from VBA -


I have a library written in C ++ and using Visual Studio 2010 Has been compiled as DLL. DLL has multiple export functions Export operations are accessible from Excel using declared function .

I am trying to implement a new feature in the program which requires the nested structures in the ++ portion which is then accessed from VBA. The C ++ code looks like this.

First Structure

  Structure parameter {double value; Four * label; Four * description; Four * units; };  

Second Structure

This structure is used as the following structure:

  Struct output {parameter field_1; Parameter field_2; Parameter field 4; };  

There are a few ways that I am thinking of reaching the structure from VBA. One of these is with the zero function, such as.

  zero function 1 (output * output_function 1);  

The second is an action that gives the output structure, such as

  Output function 2 ();  

Internal on the two tasks given above does not matter at this point. I have verified that both implementations work as intended in C ++ code.

Issue

I am unable to use either of these two structures using VBA either Function1 or Function2 .

I declared two custom types in VBA.

  Type parameter as parameter field 3 as parameter field 2 String termination type type output field 1 string values ​​as string units double as the label value Function1  for the parameter end type   

I have declared the exported function as follows.

  Sub Function 1 Lib "C: Path \ to \ library.dll" (Output as Bayreaf Output Start)  

and Function2 < For / code>, the following.

  declare output  

function 2 gives crash excel and Function1 as sub Function2 Lib "C: \ Path \ to \ library.dll" error me vba byref logic type mismatch .

What am I doing wrong here? What is the right approach?

If you define your structures #pragma pack (4) .. #pragma pack () instructions.

C:

  #pragma pack (4) structure parameter {double value; Four * label; Four * description; Four * units; }; Structure output {struct parameter field}; Structure parameter field_2; Struct parameter field_3; }; #pragma pack () Fixed four buffer [4096]; Fixed Zero Append_Field_Values ​​(straight parameter * field) {Fixed four b [1024]; Sprintf (b, "% f% s% s% s \ n", field - & gt; value, field -> label, field -> description, field -> units); Dome (buffer, b); } Zero_Stired function 1 (Structure output * Output_function1) {Buffer [0] = 0; Append_Field_Values ​​(& amp; Output_function 1 - & gt; Field_1); Append_Field_Values ​​(& amp; Output_function1 - & gt; Field_2); Append_Field_Values ​​(and output_function1 - & gt; Field_3); Messagebox (0, buffer, "FUNCTION1", 0); }  

VB:

  type parameter value double as string label description string units as string end type type output field 1 parameter field 2 As described in parameter field 3 as parameter parameter named as "Function1 Lib" E: \ Serge \ StackOverflow \ NestedStructures \ debug \ NestedStructures.dll "(ByRef OutputStruct as output) Dim Out1 As output sub test1 () Out1.Field1.Value = 3.14 Out1.Field1.Label = "ARINC 429" Out1.Field2.Units = "miles and inches" Out1.Field3.Description = "Read MSDN" Function1 (out1) End Sub Call  

< / P>


No comments:

Post a Comment