无法将参数从 WCHAR[100] 转换为 WCHAR**
我有一个需要 WCHAR** 的方法,我需要从该方法中获取一些数据。我声明一个数组 WCHAR[100] 并将其传递给函数。编译器抛出此错误:
WCHAR result[100];
UINT i;
hr = SomeFunc(handle, &i, result);
错误 C2664: 'XXXX' : 无法将参数 3 从 'WCHAR [100]' 转换为 'WCHAR **'
I have a method expecting WCHAR**, i need to get some data back from this method. I am declaring an array WCHAR[100] and passing it to the function. The compiler throws this error:
WCHAR result[100];
UINT i;
hr = SomeFunc(handle, &i, result);
error C2664: 'XXXX' : cannot convert parameter 3 from 'WCHAR [100]' to 'WCHAR **'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,如果一个函数接受一个指向指针的指针(在本例中为
WCHAR**
),那么它将分配自己的内存并将指向的指针设置为该内存。SomeFunc
的文档应该描述这是否确实发生了。如果是这种情况,那么您可能需要类似的内容:
如果成功,则使用
result
。当然,在这种情况下,您很可能还需要担心释放
result
设置为指向的内存。SomeFunc
的文档也应该明确说明执行此操作所需的内容。Generally speaking, if a function takes a pointer to a pointer (
WCHAR**
in this case) then it will allocate its own memory and set the pointed-to pointer to that memory. The documentation ofSomeFunc
should describe if this is indeed what happens.If that is the case, then you would likely need something like:
And then make use of
result
if successful.Of course, in that case you also most likely need to worry about deallocating the memory that
result
was set to point to. The documentation ofSomeFunc
should explicitly say what's necessary to do that as well.