Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从C+中的地址引用返回值+;_C++_Void Pointers - Fatal编程技术网

C++ 从C+中的地址引用返回值+;

C++ 从C+中的地址引用返回值+;,c++,void-pointers,C++,Void Pointers,如果我的措辞不正确,很抱歉,但代码如下: typedef struct { unsigned char bSaveRestore; unsigned short wPresetId; } uvcx_ucam_preset_t; ... uvcx_ucam_preset_t data; data.wPresetId = 0; data.bSaveRestore = 0; setProperty(&data); ... setProperty(void *data ...

如果我的措辞不正确,很抱歉,但代码如下:

typedef struct
{
    unsigned char bSaveRestore;
    unsigned short wPresetId;
}
uvcx_ucam_preset_t;
...
uvcx_ucam_preset_t data;
data.wPresetId = 0;
data.bSaveRestore = 0;  
setProperty(&data);
...
setProperty(void *data ...)
{
  //How to access wPresetId and bSaveRestore here...
  // The next line is where I'm using it.
  hr = ksControl->KsProperty((PKSPROPERTY)&extProp, sizeof(extProp), data, dataLen, &bytesReturned);}
  /* Here is from hsproxy.h
   STDMETHOD(KsProperty)(
        THIS_
        _In_reads_bytes_(PropertyLength) PKSPROPERTY Property,
        _In_ ULONG PropertyLength,
        _Inout_updates_bytes_(DataLength) LPVOID PropertyData,
        _In_ ULONG DataLength,
        _Inout_opt_ ULONG* BytesReturned
  */
最后,我试图弄明白为什么我的相机会在上面提到的线路上重新启动,而其他结构似乎正常。我只是看不到任何数据,但如果我在通话前中断,我可以看到数据是正常的。在调用之前,我尝试创建了一个变量void*test=&data,但在尝试访问数据时遇到了同样的问题

我不知道如何处理setProperty中的数据。从我在调试中的尝试:

data is the address.
&data is the address of the address.
*data gives an error "expression must be a point to a complete object type"

data
是类型为
uvcx\u ucam\u preset\u t
的对象,
和data
返回
数据的地址,即类型为
uvcx\u ucam\u preset\u t*
的指针
setProperty
void*
作为参数,当传递
&data
时,指针将隐式转换为
void*

setProperty
中,如果要访问数据成员
wPresetId
bsaverstore
,则需要显式地将指针转换回。e、 g

setProperty(void *data)
{
    uvcx_ucam_preset_t* p = static_cast<uvcx_ucam_preset_t*>(data);
    p->bSaveRestore = ...;
    p->wPresetId = ...;
}
setProperty(void*data)
{
uvcx_ucam_预设_t*p=静态_投射(数据);
p->bsaverstore=。。。;
p->wPresetId=。。。;
}

听起来像是您已向前声明了
uvcx\u ucam\u preset\u t
,并且在尝试使用它时没有提供完整的定义。您能否提供一个适当的示例?为什么
setProperty
void*
作为参数?为什么不
uvcx\U ucam\U preset\U t*
?KsProperty要求数据LPVOID@JohnSmith您需要执行显式转换,例如<代码>静态广播(数据)->wPresetId…
。感谢您的回答。我会试试看,但这会带来另一个问题。因为hr=ksControl->KsProperty((PKSPROPERTY)和extProp、sizeof(extProp)、data、dataLen和bytes返回);是一个内置函数,既然它是一个LPVOID,它怎么知道结构数据是什么呢?基于这个问题,我接受了这个答案。我相信我已经发现我的代码对于setProperty行之前发生的事情是不正确的。@JohnSmith我想它也会执行转换;基于某种惯例。