【问题标题】:Reading an array<Byte> in unmanaged c++在非托管 C++ 中读取数组<Byte>
【发布时间】:2011-10-03 04:36:11
【问题描述】:

我有一个托管 C++ 类,其构造函数签名为:

tools_package_net::PackageInfo::PackageInfo(array<Byte>^ bytes)

在构造函数中,我希望使用签名调用非托管类的方法:

bool PackageInformation::ReadProject(const unsigned char *data, size_t size)

所以我想调用“ReadProject”,从我的“bytes”数组中传递数据。我可以使用“bytes.Length”传递的“大小”。但是我怎样才能获得数据本身呢?我可以简单地对第一个元素 &bytes[0] (ala std::vector) 进行类型转换吗?

任何帮助将不胜感激。

【问题讨论】:

    标签: c++ arrays unmanaged command-line-interface managed


    【解决方案1】:
    cli::pin_ptr<unsigned char> pb = &(bytes[0]);
    unsigned char* p = static_cast<unsigned char*>(pb);
    

    据此book

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-24
      • 2010-09-16
      • 2023-03-30
      • 1970-01-01
      • 2011-10-19
      • 2011-09-15
      • 1970-01-01
      • 2017-04-02
      相关资源
      最近更新 更多