关于从AS3代码中向C++中传递ByteArray参数的方法,采用官方Demo中的数据传递方法成功解决了ByteArray传参问题。贴出参考代码:
/////////////////////////////////////////////////////////////////////////////////////////
AS3
/////////////////////////////////////////////////////////////////////////////////////////
// First lets fill a ByteArray like we normally would in ActionScript
var bytes:ByteArray = new ByteArray();
bytes.endian = "littleEndian";
for (var j:int = 0; j < 10; j++)
bytes.writeInt(j);
bytes.position = 0;
// Now we want a pointer to that ByteArray
var bytesPtr:int = CModule.malloc(bytes.length);
// Use CModule.writeBytes() to write the ByteArray we created into flascc's
// main memory. The parameters of writeBytes() are first the pointer in flascc
// memory, the length of the ByteArray, and the ByteArray itself
CModule.writeBytes(bytesPtr, bytes.length, bytes);
printLine("Checksum: " + MyLib.examineBytes(bytesPtr, bytes.length));
CModule.free(bytesPtr);
/////////////////////////////////////////////////////////////////////////////////////////
C
/////////////////////////////////////////////////////////////////////////////////////////
__attribute__((annotate("as3sig:public function _wrap_examineBytes(buffer:int, bufferSize:int):int")))
void _wrap_examineBytes() {
unsigned char *arg1 = (unsigned char *) 0 ;
int arg2 ;
int result ;
{
AS3_GetScalarFromVar(arg1, buffer);
}
{
AS3_GetScalarFromVar(arg2, bufferSize);
}
result = (int)examineBytes((unsigned char const *)arg1,arg2);
{
AS3_DeclareVar(asresult, int);
AS3_CopyScalarToVar(asresult, result);
}
{
AS3_ReturnAS3Var(asresult);
}
}