[General Questions and Answers] vasiliy535:
I trying to handle incoming SMS using RIL notification (RIL_NOTIFY_MESSAGE). I have a problem with converting lpData to RILMESSAGE structure. There are error "NotSupportedException". I think that problem in my implementation of RILMESSAGE structure in C#. Can anyone help me? See code bellow:

lpData to RILMESSAGE convert code:

try {
RILMESSAGE msg = (RILMESSAGE)Marshal.PtrToStructure(lpData, typeof(RILMESSAGE)); // this code rise "NotSupportedException"
msgInDeliver msgIn = (msgInDeliver)BytesToStruct(msg.Msg, typeof(msgInDeliver));
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}

RILMESSAGE structure on C#

#region RILMESSAGE struct

public struct RILMESSAGE
{
public UInt32 cbSize;
public UInt32 dwParams;
[MarshalAs(UnmanagedType.Struct, SizeConst = 528)]
public RILADDRESS raSvcCtrAddress;
public UInt32 dwType;
public UInt32 dwFlags;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1356)]
public byte[] Msg;
}

#region UNION Struct

[StructLayout(LayoutKind.Sequential)]
public struct msgInDeliver
{
public RILADDRESS raOrigAddress;
public UInt32 dwProtocolID;
public RILMSGDCS rmdDataCoding;
public SYSTEMTIME stSCReceiveTime;
public UInt32 cbHdrLength;
public UInt32 cchMsgLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public byte[] rgbHdr;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] rgbMsg;
}

[StructLayout(LayoutKind.Sequential)]
public struct msgInStatus
{
public UInt32 dwTgtMsgReference;
public RILADDRESS raTgtRecipAddress;
public SYSTEMTIME stTgtSCReceiveTime;
public SYSTEMTIME stTgtDischargeTime;
public UInt32 dwTgtDlvStatus;
public UInt32 dwProtocolID;
public RILMSGDCS rmdDataCoding;
public UInt32 cbHdrLength;
public UInt32 cchMsgLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public byte[] rgbHdr;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] rgbMsg;
}

[StructLayout(LayoutKind.Sequential)]
public struct msgOutSubmit
{
public RILADDRESS raDestAddress;
public UInt32 dwProtocolID;
public RILMSGDCS rmdDataCoding;
public UInt32 dwVPFormat;
public SYSTEMTIME stVP;
public UInt32 cbHdrLength;
public UInt32 cchMsgLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public byte[] rgbHdr;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] rgbMsg;
}

[StructLayout(LayoutKind.Sequential)]
public struct msgOutCommand
{
public UInt32 dwProtocolID;
public UInt32 dwCommandType;
public UInt32 dwTgtMsgReference;
public RILADDRESS raDestAddress;
public UInt32 cbCmdLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public byte[] rgbCmd;
}

[StructLayout(LayoutKind.Sequential)]
public struct msgBcGeneral
{
public UInt32 dwGeoScope;
public UInt32 dwMsgCode;
public UInt32 dwUpdateNumber;
public UInt32 dwID;
public RILMSGDCS rmdDataCoding;
public UInt32 dwTotalPages;
public UInt32 dwPageNumber;
public UInt32 cchMsgLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] rgbMsg;
}

[StructLayout(LayoutKind.Sequential)]
public struct msgOutRaw
{
public UInt32 cchMsgLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] rgbMsg;
}

[StructLayout(LayoutKind.Sequential)]
public struct msgIS637InDeliver
{
public RILADDRESS raOrigAddress;
public RILSUBADDRESS rsaOrigSubaddr;
public SYSTEMTIME stSCReceiveTime;
public SYSTEMTIME stValidityPeriodAbs;
public SYSTEMTIME stValidityPeriodRel;
public SYSTEMTIME stDeferredDelTimeAbs;
public SYSTEMTIME stDeferredDelTimeRel;
public UInt32 dwNumMsgs;
public RILADDRESS raCallBackNumber;
public UInt32 dwMsgPriority;
public UInt32 dwMsgPrivacy;
public bool bUserAckRequest;
public UInt32 dwMsgDisplayMode;
public UInt32 dwTeleservice;
public UInt32 dwMsgID;
public UInt32 dwMsgLang;
public UInt32 dwMsgEncoding;
public UInt32 cchMsgLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] rgbMsg;
}

[StructLayout(LayoutKind.Sequential)]
public struct msgIS637OutSubmit
{
public RILADDRESS raDestAddress;
public RILSUBADDRESS rsaDestSubaddr;
private bool bDigit;
public SYSTEMTIME stValidityPeriodAbs;
public SYSTEMTIME stValidityPeriodRel;
public SYSTEMTIME stDeferredDelTimeAbs;
public SYSTEMTIME stDeferredDelTimeRel;
private bool bDeliveryAckRequest;
private bool bUserAckRequest;
private bool bBearerReplyRequest;
public UInt32 dwReplySeqNumber;
public UInt32 dwMsgDisplayMode;
public RILADDRESS raCallBackNumber;
public UInt32 dwMsgPriority;
public UInt32 dwMsgPrivacy;
public UInt32 dwTeleservice;
public UInt32 dwMsgID;
public UInt32 dwMsgLang;
public UInt32 dwMsgEncoding;
public UInt32 cchMsgLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] rgbMsg;
}

[StructLayout(LayoutKind.Sequential)]
public struct msgIS637InStatus
{
public RILADDRESS raOrigAddress;
public RILSUBADDRESS rsaOrigSubaddr;
public SYSTEMTIME stSCReceiveTime;
public UInt32 dwCauseCode;
public UInt32 dwReplySeqNumber;
public UInt32 dwUserResponseCode;
public UInt32 dwMsgStatusType;
public UInt32 dwMsgID;
public UInt32 dwMsgLang;
public UInt32 dwMsgEncoding;
public UInt32 cchMsgLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] rgbMsg;
}

[StructLayout(LayoutKind.Sequential)]
public struct msgIS637OutStatus
{
public RILADDRESS raDestAddress;
public RILSUBADDRESS rsaDestSubaddr;
public bool bDigit;
public UInt32 dwReplySeqNumber;
public UInt32 dwUserResponseCode;
public UInt32 dwMsgID;
public UInt32 dwMsgLang;
public UInt32 dwMsgEncoding;
public UInt32 cchMsgLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] rgbMsg;
}

#endregion

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct RILSUBADDRESS
{
public UInt32 cbSize;
public UInt32 dwParams;
public UInt32 dwType;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string wszSubAddress;
}

[StructLayout(LayoutKind.Sequential)]
public struct RILMSGDCS
{
public UInt32 cbSize;
public UInt32 dwParams;
public UInt32 dwType;
public UInt32 dwFlags;
public UInt32 dwMsgClass;
public UInt32 dwAlphabet;
public UInt32 dwIndication;
public UInt32 dwLanguage;
}

[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;

public override string ToString()
{
return wYear.ToString() + "-" + wMonth.ToString() + "-" + wDay.ToString() + " "
+ wHour.ToString() + ":" + wMinute.ToString() + ":" + wSecond.ToString();
}
}

[StructLayout(LayoutKind.Explicit)]
public class RILADDRESS
{
[FieldOffset(0)]
public uint dwSize;
[FieldOffset(4)]
public uint dwParams;
[FieldOffset(8)]
public uint dwType;
[FieldOffset(12)]
public uint dwNumPlan;
[FieldOffset(16)]
public byte[] sAddress = new byte[256 * 2];
//[FieldOffset(528)]
}

#endregion