pointers - 为什么 C++/WinRT IDL 文件不允许我使用指针作为参数定义方法?
问题描述
我正在使用 C# UWP 项目中的代码在一个短数组中生成数据,将此数据传递给 C++/WinRT 组件项目中的代码(使用指针和数组的长度),修改数据,然后传回一个新数组(使用指针和数组的长度)到 C# 代码。使用下面的代码,我不会立即得到错误。但是,构建 C++/WinRT 项目失败,因为我的 idl 文件收到错误:MIDL2025 [msg]syntax error [context]: Expecting an identifier near "*"。
是否可以将指针从 C# 传递到 C++/WinRT?(如果您发现我的代码或其效率有任何其他问题,请随时告诉我。)
我在 Internet 上搜索了有关 C++/WinRT(不是 C++/CX)和 .idl 文件的所有信息。我认为对于 C++/WinRT 来说,几年前的任何东西都不会是准确的。C++/WinRT 于 2015 年 6 月 23 日发布,在此之前有关 WinRT 的任何内容实际上都只是 C++/CX。我按照此处的示例编写了代码:https ://github.com/microsoft/Windows-appsample-photo-editor/blob/master/PhotoEditor/Photo.idl 。另外,我认为 C++/WinRT 中的 idl 文件实际上是 MIDL 3.0。查看此链接https://docs.microsoft.com/en-us/uwp/midl-3/intro#types,我将 idl 文件更改为接受Int32
而不是int
而Int16*
不是short*
(如果没有必要,请告诉我) . 我研究了一些关于out
关键字,但它似乎不适用于 MIDL 3.0。需要明确的是,我想返回short*
指针,而不是short
值。
这是我的idl文件:
//.idl file
namespace MyNamespace
{
[default_interface]
runtimeclass MyClass
{
MyClass();
void DoStuff(Int32 length, Int16* inbuf, Int16* outbuf);
}
}
这是我的头文件:
//.h file
#pragma once
#include "MyClass.g.h"
namespace winrt::MyProject::implementation
{
struct MyClass: MyClassT<MyClass>
{
MyClass() = default;
void DoStuff(int length, short* inbuf, short* outbuf);
};
}
namespace winrt::MyProject::factory_implementation
{
struct MyClass: MyClassT<MyClass, implementation::MyClass>
{
};
}
这是我的 C++ 文件:
//.cpp file
#include "pch.h"
#include "MyClass.h"
#include "MyClass.g.cpp"
namespace winrt::MyProject::implementation
{
void MyClass::DoStuff(int length, short* inbuf, short* outbuf)
{
//Process data here by editing outbuf
}
}
先感谢您!
解决方案
推荐阅读
- php - 当为真时阻止数据库中重复用户名的功能,当为真时将名称插入数据库
- javascript - 控制台在 node.js 中记录 python 脚本控制台输出
- firebase - 了解使用 firebase 登录 facebook 的行为
- r - 如何使用 sparklyr 行绑定两个 Spark 数据帧?
- javascript - 无法在 React Native IOS 中解析模块,但可以在 Android 中使用
- javascript - 当用户按下一个键时遍历“下拉”元素
- javascript - 当我点击提交时增加字段 user.entries
- c# - 当试图调用 GetComponent<>() 我的类“库存”返回为空
- coldfusion - 使用 ColdFusion 从 URL 中提取域
- python - CSV 类阅读器没有获得实际图像