I'm not 100% sure what you are trying to do here. Let me assume that that some larger, native, c++ program calls into your hxcpp code. Then at some stage, the hxcpp code wants to callback into the native program and pass a buffer.
You can do this by declaring an class similar to this:
@:cppFileCode('
extern void onHaxeData(unsigned char *inData);
')
class Sender
{
@:native("onHaxeData")
@:extern public static function onHaxeData(ptr:cpp.Star<cpp.UInt8>) { }
public static function sendHaxeData(data:haxe.io.BytesData)
{
onHaxeData( cast cpp.NativeArray.address(data,0) );
}
}
and use it like:
Sender.sendHaxeData( haxe.io.Bytes.ofString("Hello").getData() );
This will be zero-copy (ie, memory alias), although in this case the "ofString" command will do a copy.
If you try to link this code as is, you will get an unresolved for 'onHaxeData'. This is what your enclosing native app will provide.
Hugh