空指针铸造的问题 [英] Problem with Void Pointer Casting
问题描述
嘿!
我最近一直在研究VC ++中的一种软件,该软件可以与Decive(示波器)进行通信.制造商提供了基于C的库(.h文件和lib x64).
问题在于DLL中的某些功能具有viod指针.这是一些示例.
Hey!
I have been recently working on a software in VC++ that can communicate with a decive (Oscilloscope). The manufacturer provided with Library (.h file and a lib x64) based on C.
The problem is that some of the functions in the DLL have viod pointers. here are a few examples.
#include "CAENDIGITIZER.h"
/**************************************************************************//**
* \param [IN] waveforms
* \param [IN] events
******************************************************************************/
CAEN_DGTZ_ErrorCode CAENDGTZ_API CAEN_DGTZ_MallocDPPWaveforms(int handle, void **waveforms, uint32_t *allocatedSize);
CAEN_DGTZ_ErrorCode CAENDGTZ_API CAEN_DGTZ_MallocDPPEvents(int handle, void **events, uint32_t *allocatedSize);
输入参数不是void,而是以下类型的模板:
The input parameters are not void, but are type template of:
typedef struct // for void **events
{
uint32_t Format;
uint32_t TimeTag;
int16_t ChargeShort;
int16_t ChargeLong;
int16_t Baseline;
int16_t Pur;
uint32_t *Waveforms;
} CAEN_DGTZ_DPP_PSD_Event_t;
typedef struct //for void **Waveforms
{
uint32_t Ns;
uint8_t dualTrace;
uint8_t anlgProbe;
uint8_t dgtProbe1;
uint8_t dgtProbe2;
uint16_t *Trace1;
uint16_t *Trace2;
uint8_t *DTrace1;
uint8_t *DTrace2;
uint8_t *DTrace3;
uint8_t *DTrace4;
} CAEN_DGTZ_DPP_PSD_Waveforms_t;
在C语言中,我可以使用一个或多或少像这样的脚本来轻松调用该函数:
In C, i can easily call the function with a script that reads more or less like this:
// main.c
CAEN_DGTZ_DPP_PSD_Event_t *Events1[MaxNChannels]; // events buffer
CAEN_DGTZ_DPP_PSD_Waveforms_t *Waveform=NULL; // waveforms buffer
int AllocatedSize, handle;
public: void progDEVICE()
/* Allocate memory for the events */
ret = CAEN_DGTZ_MallocDPPEvents(handle, Events1, &AllocatedSize);
/* Allocate memory for the waveforms */
ret = CAEN_DGTZ_MallocDPPWaveforms(handle, &Waveform, &AllocatedSize);
if (!ret==0) {
printf("Can't allocate memory buffers\n");
}
}
由于实时和其他偏好的数据处理量巨大,因此我倾向于使用C ++.但是,问题在于C ++在没有显式强制转换的情况下不喜欢void指针.但我无法一辈子抛弃这些:(
我正在使用VC ++ 2010 Pro. MScompiler和intel编译器只会出现令人讨厌的转换错误.
Due to extremely huge ammount of data processing in realtime and other preferences, I am inclined to use C++. However, the bugger is that C++ donot like void pointers without having an explicit casting. but i am unable to cast these for the life of me:(
I am using VC++2010 Pro. MScompiler and intel Compiler only turn up with nasty casting errors.
error C2664: 'CAEN_DGTZ_MallocDPPEvents' : cannot convert parameter 2 from 'CAEN_DGTZ_DPP_PSD_Event_t *[8]' to 'void **'
我希望有人能帮助我.我没有该库的源代码,只有.h和.lib文件.
非常感谢!
cheers
I was hoping someone can help me out. I donot have the source code of the library, but only the .h and .lib files.
Thanks a Lot!
cheers
推荐答案
//this is your solution:
ret = CAEN_DGTZ_MallocDPPEvents(handle, (void **)Events1, &AllocatedSize);
顺便说一句,这条线在某些方面很糟糕
由于实时处理大量数据以及其他偏好,我倾向于使用C ++.
by the way, in few ways this line is crappy
Due to extremely huge ammount of data processing in realtime and other preferences, I am inclined to use C++.
这篇关于空指针铸造的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!