【问题标题】:Passing byte array data from C++ to Haxe将字节数组数据从 C++ 传递到 Haxe
【发布时间】:2017-06-09 17:41:16
【问题描述】:

我们正在尝试将原始数据从 C++ 传递到 Haxe,但我们有很多高音。

我们尝试了这个解决方案http://community.openfl.org/t/passing-bytes-from-c-to-haxe/8046/2,但对我们不起作用。

C++

void Clazz::func(unsigned char *data, int length)
{
    XXX_ENTER_HAXE();
    val_call1(m_callback->get(), alloc_array(length));
    XXX_EXIT_HAXE();
}

斧头

function func(result:ByteArray) : Void {
    //Do the callback
}

【问题讨论】:

    标签: haxe openfl cffi


    【解决方案1】:

    我刚刚学习了 haxe 如何被动地从 C++ 接收字节

    C++:

    int len = 10;
    unsigned char buf[len];
    buf[0] = 12;
    
    ::Helper_obj* helper = new ::Helper_obj();
    printf("Haxe result:%d\n", helper->processBytes(&buf, len));
    

    斧头:

    class Helper{
      public function new(){}
      public function processBytes(raw:cpp.Pointer<cpp.Uint8>, len:Int):Int{
        var array<cpp.Uint8> = cpp.NativeArray.toUnmanagedArray(raw, len);
        var bytes:Bytes = Bytes.ofData(array);
        return bytes.get(0);
      }
    }
    

    输出:

    Haxe result:12
    

    【讨论】:

      猜你喜欢
      • 2017-07-04
      • 2018-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-20
      • 1970-01-01
      相关资源
      最近更新 更多