C++ 如何从DLL中检索数组变量?(Visual C+;+;)
第三方C库包含以下全局变量和函数:C++ 如何从DLL中检索数组变量?(Visual C+;+;),c++,visual-c++,dll,C++,Visual C++,Dll,第三方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))GetPro
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);
VisualC++给出了对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++代码中声明类型的正确方法是如何实现这一工作的?在第一个版本中
< P>使调用为:RiBasis(*RiCatmullRomBasis);
您需要获取变量的地址(即GetProcAddress可以返回的地址),但函数采用实例而不是指针,因此必须取消对返回指针的引用。。为什么要将函数指针的地址强制转换为二维浮点数组?一旦加载库,全局变量应该可以在代码中访问,但即使它不是函数,也要对变量执行GetProcAddress。您是否尝试过只声明一个
外部“C”RtBasis RiCatmullRomBasis代码>然后尝试访问它?根据文档,GetProcAddress()还用于返回导出变量的地址。