c++ - 将指向结构的指针传递给函数
问题描述
我的 C++ 技能充其量是业余的,我需要编写一些代码以通过制造商提供的 .dll 与第 3 方传感器接口
因此,功能定义是由制造商提供的,但我真的不确定实现它们的正确方法。
根据 API 文档,我有两个结构,根据该文档定义,但我无法弄清楚如何将结构的指针传递给所需的函数 - HPK_GetSensorInformation(DeviceHandle, PUNIT_INTEGRATION_PARAMETER IntegParam, PUNIT_SENSOR_INFORMATION SensorInfo);。
任何帮助将不胜感激。
谢谢!
附上代码:
#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;
}
解决方案
我无法帮助您处理任何特定于 Windows 的内容,但使用通用 C++:
HPK_GetSensorInformation(DeviceHandle, &UNIT_INTEGRATION_PARAMETER, &UNIT_SENSOR_INFORMATION );.
说“传递这个&
结构的地址”。也就是说,它传递一个指针。
推荐阅读
- python - 无法在 python 3.7 中使用 cx_oracle 6.4 将 Django 2.0.7 与 oracle 12c 连接
- docker - 基于windowsservercore的docker下载问题(Appveyor, Visual Studio 2017)
- xml - 使用 xslt 对标签设置条件?
- javascript - 如果所有现有幻灯片都在 BX Slider 中结束,则循环到第一张幻灯片
- html - 在知道组件字符串名称的Angular 2中动态插入组件
- ios - 将 StoryBoard 从 Xcode8 更新到 Xcode9 时出现 UI 问题
- kotlin - TypeConverters 无法弄清楚如何将此字段保存到数据库中
- react-native - 无法从 React 本机项目调用 ios 本机模块
- c# - 使用终结器关闭 EventHubClient
- android - 如何从相机捕获多张图像并使用位图将其编码为字符串?