Windows Phone 8(WP8) C# unsafe code?

▼魔方 西西 提交于 2019-12-03 16:45:11

I found a solution.

For simple vector types just do:

Marshal.StructureToPtr(vector, nativePtr, false);

And for arrays do:

var data = new Vector[10];
int size = Marshal.SizeOf(data[0]);
for (int i = 0; i != data.Length; ++i)
{
    Marshal.StructureToPtr(data[i], nativePtr + (size * i), false);
}

If anyone has a better answer that would be good to know too.

This is exactly what C++/CX is there to address (while maintaining the integrity of the sandbox).

For instance for passing int array from C# to C++ use Platform::Array<int> in your C++/CX ref class or interface definition. Check out MSDN for the specifics of how to use this type.

( http://msdn.microsoft.com/en-us/library/windows/apps/hh700131.aspx )

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!