如何从DLL中检索数组变量? (Visual C ++)

问题描述 投票:1回答:1

第三方C库包含以下全局变量和函数:

typedef RtBasis float[4][4];

RI_EXPORT RtBasis RiCatmullRomBasis;
RI_EXPORT void    RiBasis(RtBasis u);

我想从DLL中检索变量和函数,并在我的C ++代码中使用它们。当我执行以下操作时:

// Get the function.
void (*RiBasis)(RtBasis);
RiBasis = (void (*)(RtBasis))GetProcAddress(h, "RiBasis");

// Get the variable.
RtBasis *RiCatmullRomBasis;
RiCatmullRomBasis = (RtBasis*)GetProcAddress(h, "RiCatmullRomBasis");

// Call the function, passing it the variable.
RiBasis(RiCatmullRomBasis);

Visual C ++在调用RiBasis时给出了这个编译错误:

error C2664: 'void (float [][4])': cannot convert argument 1
from 'RtBasis (*)' to 'float [][4]'

我尝试从RiCatmullRomBasis变量中删除一个间接级别:

// Get the variable.
RtBasis RiCatmullRomBasis;
RiCatmullRomBasis = (RtBasis)GetProcAddress(h, "RiCatmullRomBasis");

// Call the function, passing it the variable.
RiBasis(RiCatmullRomBasis);

但是这给了我关于GetProcAddress调用的以下内容:

error C2440: 'type cast': cannot convert from 'FARPROC' to 'RtBasis'
note: There are no conversions to array types, although there are
conversions to references or pointers to arrays

在C ++代码中声明类型的正确方法是什么?

c++ visual-c++ dll
1个回答
2
投票

在第一个版本中,将呼叫设为:

RiBasis(*RiCatmullRomBasis);

您需要获取变量的地址(这是GetProcAddress可以返回的),但该函数采用实例而不是指针,因此您必须取消引用返回的指针。

© www.soinside.com 2019 - 2024. All rights reserved.