我的 C++ 技能充其量只是业余水平,我需要编写一些代码以通过制造商提供的 .dll 与 3rd 方传感器接口
因此,函数定义由制造商提供,但我真的不确定实现它们的正确方法。
我有两个结构,根据 API 文档,按照该文档定义,但我不知道如何将结构的指针传递给所需的函数 - HPK_GetSensorInformation(DeviceHandle, PUNIT_INTEGRATION_PARAMETER 整数参数, PUNIT_SENSOR_INFORMATION 传感器信息 );.
任何帮助将不胜感激。
谢谢!
附上代码:
#include <iostream>
#include <windows.h>
#include "CMOS_USB.h"
using namespace std;
int main(){
typedef struct _tag_UnitIntegrationParameter {
unsigned short Xray_Start_Threshold = 10;
unsigned short Integration_Stop_Threshold = 20;
double Integration_Time = 100;
} UNIT_INTEGRATION_PARAMETER, *PUNIT_INTEGRATION_PARAMETER;
typedef struct _tag_UnitSensorInformation {
UNIT_INTEGRATION_PARAMETER IntegParam;
unsigned short XXXX;
unsigned char YY;
unsigned char FW;
} UNIT_SENSOR_INFORMATION,*PUNIT_SENSOR_INFORMATION;
unsigned short ProductID = 0x4400;
HANDLE DeviceHandle;
HANDLE PipeHandle;
unsigned long sensor_return_status;
DeviceHandle = WINAPI USB_OpenDevice(ProductID);
PipeHandle = WINAPI USB_OpenPipe(DeviceHandle);
sensor_return_status = WINAPI HPK_GetSensorInformation(DeviceHandle,
PUNIT_INTEGRATION_PARAMETER IntegParam,
PUNIT_SENSOR_INFORMATION SensorInfo
);
WINAPI USB_CloseDevice(DeviceHandle);
return 0;
}
答案 0 :(得分:0)
我无法帮助您处理任何特定于 Windows 的东西,但使用通用 C++:
HPK_GetSensorInformation(DeviceHandle, &UNIT_INTEGRATION_PARAMETER, &UNIT_SENSOR_INFORMATION );.
&
表示“传递此结构的地址”。也就是说,它传递了一个指针。
答案 1 :(得分:0)
您看起来是在复制这些结构的定义,而不是创建一个。
#include <iostream>
#include <windows.h>
#include "CMOS_USB.h"
int main(){
unsigned short ProductID = 0x4400;
UNIT_SENSOR_INFORMATION SensorInformation;
HANDLE DeviceHandle = USB_OpenDevice(ProductID);
// not used?
HANDLE PipeHandle = USB_OpenPipe(DeviceHandle);
unsigned long sensor_return_status = HPK_GetSensorInformation(DeviceHandle, &SensorInformation.IntegParam, &SensorInformation);
USB_CloseDevice(DeviceHandle);
return 0;
}