BS2ErrorCode computeCRC(BS2SmartCardData smartCard, out UInt16 hdrCRC, out UInt16 cardCRC) { BS2ErrorCode result = BS2ErrorCode.BS_SDK_SUCCESS; IntPtr smartCardObj = Marshal.AllocHGlobal(Marshal.SizeOf(smartCard)); int cardTypeOffset = (int)Marshal.OffsetOf(typeof(BS2SmartCardHeader), "cardType"); int cardCRCOffset = (int)Marshal.OffsetOf(typeof(BS2SmartCardHeader), "cardCRC"); IntPtr cardDataObj = smartCardObj + cardTypeOffset; Marshal.StructureToPtr(smartCard, smartCardObj, false); cardCRC = 0xFFFF; hdrCRC = 0xFFFF; result = (BS2ErrorCode)API.BS2_ComputeCRC16CCITT(cardDataObj, (UInt32)(Marshal.SizeOf(typeof(BS2SmartCardData)) - cardTypeOffset), ref cardCRC); if (result == BS2ErrorCode.BS_SDK_SUCCESS) { Marshal.WriteInt16(smartCardObj, cardCRCOffset, (Int16)cardCRC); IntPtr cardCrcObj = smartCardObj + cardCRCOffset; result = (BS2ErrorCode)API.BS2_ComputeCRC16CCITT(cardCrcObj, (UInt32)(Marshal.SizeOf(typeof(BS2SmartCardHeader)) - cardCRCOffset), ref hdrCRC); } Marshal.FreeHGlobal(smartCardObj); return(result); }