在C ++ - DLL和VBA

时间:2015-09-22 08:20:34

标签: c++ vba dll struct parameters

任何人都可以确认或解释这种奇怪的行为吗?并非结构的所有变量都是从用C ++编写的DLL传递给我的VBA函数。

假设我在VBA中有以下内容

Type struct1
  b as Double
  c as Double
  a as Double
End Type

Type struct2
  month as Integer
  year as Integer
  substruct as struct1
End Type

在C ++中关注

struct struct1
{
  double b;
  double c;
  double a;
};

struct struct2
{
  int month;
  int year;
  struct1 substruct;
};

通过ByRef我将struct2的对象从VBA传递给我的C ++ - DLL。我的函数原型看起来像

void __stdcall someFunction(struct2 &objectFromVBA);

我指定的值如下:

objectFromVBA = myDLLobjects[1];// this is a list of struct2 elements

当我监视VBA中的输出时,我可以在参数年中检测到 NO 值。 VBA将观察列表中的顺序更改为:

month
substruct
year

(也许是字母顺序,这是我的第一个猜测)。 所有其他值都是正确的。现在我采用了我的C ++ - DLL struct2中的顺序为字母顺序。然后年份包含正确的值。订单是理由,如果是,那么:

为什么如上所示,如何订购struct1的元素无关紧要?无论如何,这些值都是正确的。

我正在使用VS2015 C ++ Express和VBA 7.0。两者都是64位。

注意,在C ++之间传递结构 - DLL按预期工作,并且忽略了我没有按照它们的顺序排列它们。

提前谢谢!

0 个答案:

没有答案
相关问题