[問題] 記憶體配置

作者: howshow (好笑)   2014-10-30 14:46:02
大家好
小弟在幫一個POS_DATA_2D_F64 結構進行記憶體配置出了點錯誤
[StructLayout(LayoutKind.Sequential)]
public struct POS_DATA_2D_F64
{ public UInt32 u32_opt;
public Double f64_x;
public Double f64_y;
public Double f64_theta;
}
UInt32 cnt = 5;
POS_DATA_2D_F64* a;
IntPtr ap = Marshal.AllocHGlobal(sizeof(POS_DATA_2D_F64) * cnt);
a = (POS_DATA_2D_F64*)ap;
===
Error 4 Argument '1': cannot convert from 'long' to System.IntPtr
cnt 如果不用Uint32就會過
但是cnt 必須是Uint32
請問此部分要怎麼改
感謝各位~~~
作者: yeo1987 (Archie)   2014-10-31 22:33:00
對應AllocHGlobal方法中傳入參數的型別,做適當轉換吧

Links booklink

Contact Us: admin [ a t ] ucptt.com