我在 Linux 上使用一个专有库,它使用SAFEARRAY
输入回调函数:
HRESULT Write(SAFEARRAY *Data)
SAFEARRAY
在头文件中定义为typedef void SAFEARRAY
.
我必须定义一个回调函数来获取数据(例如*unsigned char
)和它的长度(例如int
or size_t
)并将数据写入某处。
就像是:
HRESULT MyWrite(SAFEARRAY *Data) {
unsigned char *data = SafeArrayGetData(Data);
size_t length = SafeArrayGetLength(Data);
write_data_somewhere(data, length);
}
然后将其与库一起使用:
ProprietaryLib::ExportThing(thing, MyWrite);
所以我的问题是:如何在linux上获取数据及其长度,我没有oaidl.h https://learn.microsoft.com/en-us/windows/desktop/api/oaidl/ or oleauto.h https://learn.microsoft.com/en-us/windows/desktop/api/oleauto/头文件。
对于这个问题有两个想法:
-
也许你已经看过了,但是 Wine 实现了SAFEARRAY
。因此你可以看看
- https://github.com/wine-mirror/wine/blob/master/dlls/oleaut32/safearray.c https://github.com/wine-mirror/wine/blob/master/dlls/oleaut32/safearray.c
- https://github.com/wine-mirror/wine/blob/master/include/oaidl.idl https://github.com/wine-mirror/wine/blob/master/include/oaidl.idl
- https://github.com/wine-mirror/wine/blob/master/include/oleauto.h https://github.com/wine-mirror/wine/blob/master/include/oleauto.h
-
在我看来,要获取数组的长度和数据,只需访问结构体的成员就可以了。例如,在safearray.c
他们只是阅读cbElements
各个地方以及方法SafeArrayAccessData
基本上只返回pvData
。 (此外,它“锁定”数组。“锁定”似乎是在调整 SAFEARRAY 大小或释放 SAFEARRAY 时检查的引用计数器。)
一个想法为什么你的MYSAFEARRAY
(评论中提到)不起作用的是
结构打包可能会干扰。在https://learn.microsoft.com/en-us/cpp/build/reference/zp-struct-member-alignment https://learn.microsoft.com/en-us/cpp/build/reference/zp-struct-member-alignment他们说 Windows SDK 预先假定结构体打包在 8 字节边界上。因此,也许您可以输出原始字节并查看是否检测到模式。如果这确实是问题所在,请尝试更改编译器设置。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)