⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smsmessage.cs

📁 在PDA上打开收件箱,要将ReadSMS.dll拷到此程序部署到PDA的目录下
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace OpenInbox
{
    public class SmsMessage : IDisposable
    {
        public enum RecipientType { UNKNOWN, TO, CC, BCC };
        protected IntPtr pMessage;

        public SmsMessage()
        {
            pMessage = IntPtr.Zero;
        }

        public SmsMessage(IntPtr pMessage)
        {
            this.pMessage = pMessage;
        }

        ~SmsMessage()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (pMessage != IntPtr.Zero)
            {
                MessageClose(pMessage);
                pMessage = IntPtr.Zero;
            }
        }

        public IntPtr MessagePointer { get { return pMessage; } }
        public void GetSenderName(StringBuilder strSenderName)
        {
            MessageGetSenderName(pMessage, strSenderName, strSenderName.Capacity);
        }
        public void GetSenderEmail(StringBuilder strSenderEmail)
        {
            MessageGetSenderEmail(pMessage, strSenderEmail, strSenderEmail.Capacity);
        }
        public void GetSubject(StringBuilder strSubject)
        {
            MessageGetSubject(pMessage, strSubject, strSubject.Capacity);
        }
        /// <summary>
        /// Gets the received time
        /// </summary>
        /// <param name="dt">DateTime received</param>
        /// <returns>true on success</returns>
        public bool GetReceivedTime(out DateTime dt)
        {
            int nYear, nMonth, nDay, nHour, nMinute, nSecond;
            bool bResult = MessageGetReceivedTime(pMessage, out nYear, out nMonth, out nDay, out nHour, out nMinute, out nSecond);
            dt = new DateTime(nYear, nMonth, nDay, nHour, nMinute, nSecond);
            return bResult;
        }

        /// <summary>
        /// Gets the received time using the default format (MM/dd/yyyy hh:mm:ss tt)
        /// </summary>
        /// <param name="strReceivedTime">buffer to receive</param>
        /// <returns>true on success</returns>
        public bool GetReceivedTime(StringBuilder strReceivedTime)
        {
            return MessageGetReceivedTimeString(pMessage, strReceivedTime, strReceivedTime.Capacity, "");
        }

        /// <summary>
        /// Gets the received time
        /// </summary>
        /// <param name="strReceivedTime">buffer to receive</param>
        /// <param name="strFormat">format string for date (empty for default)</param>
        /// <returns>true on success</returns>
        public bool GetReceivedTime(StringBuilder strReceivedTime, string strFormat)
        {
            return MessageGetReceivedTimeString(pMessage, strReceivedTime, strReceivedTime.Capacity, strFormat);
        }

        /// <summary>
        /// Gets the submit time
        /// </summary>
        /// <param name="dt">DateTime submitted</param>
        /// <returns>true on success</returns>
        public bool GetSubmitTime(out DateTime dt)
        {
            int nYear, nMonth, nDay, nHour, nMinute, nSecond;
            bool bResult = MessageGetSubmitTime(pMessage, out nYear, out nMonth, out nDay, out nHour, out nMinute, out nSecond);
            dt = new DateTime(nYear, nMonth, nDay, nHour, nMinute, nSecond);
            return bResult;
        }

        /// <summary>
        /// Gets the submit time using the default format (MM/dd/yyyy hh:mm:ss tt)
        /// </summary>
        /// <param name="strSubmitTime">buffer to receive</param>
        /// <returns>true on success</returns>
        public bool GetSubmitTime(StringBuilder strSubmitTime)
        {
            return MessageGetSubmitTimeString(pMessage, strSubmitTime, strSubmitTime.Capacity, "");
        }

        /// <summary>
        /// Gets the submit time
        /// </summary>
        /// <param name="strSubmitTime">buffer to receive</param>
        /// <param name="strFormat">format string for date (empty for default)</param>
        /// <returns>true on success</returns>
        public bool GetSubmitTime(StringBuilder strSubmitTime, string strFormat)
        {
            return MessageGetSubmitTimeString(pMessage, strSubmitTime, strSubmitTime.Capacity, strFormat);
        }
        /// <summary>
        /// Get the recipients table, call this before calling GetNextRecipient
        /// </summary>
        /// <returns>true on success</returns>
        public bool GetRecipients()
        {
            return MessageGetRecipients(pMessage);
        }

        /// <summary>
        /// Gets the next recipient
        /// </summary>
        /// <param name="strName">Name of recipient</param>
        /// <param name="strEmail">Email of recipient</param>
        /// <param name="nType">RecipientType (TO, CC, BCC)</param>
        /// <returns>true on success</returns>
        public bool GetNextRecipient(StringBuilder strName, StringBuilder strEmail, out RecipientType nType)
        {
            int nRecipientType;
            nType = RecipientType.UNKNOWN;
            if (MessageGetNextRecipient(pMessage, strName, strName.Capacity, strEmail, strEmail.Capacity, out nRecipientType))
            {
                nType = (RecipientType)nRecipientType;
                return true;
            }
            return false;
        }
        [DllImport("ReadSMS.dll")]
        protected static extern void MessageClose(IntPtr pMessage);
        [DllImport("ReadSMS.dll")]
        protected static extern void MessageGetSenderName(IntPtr pMessage, StringBuilder strSenderName, int nMaxLength);

        [DllImport("ReadSMS.dll")]
        protected static extern void MessageGetSenderEmail(IntPtr pMessage, StringBuilder strSenderEmail, int nMaxLength);

        [DllImport("ReadSMS.dll")]
        protected static extern void MessageGetSubject(IntPtr pMessage, StringBuilder strSubject, int nMaxLength);

        [DllImport("ReadSMS.dll")]
        protected static extern bool MessageGetReceivedTime(IntPtr pMessage, out int nYear, out int nMonth, out int nDay, out int nHour, out int nMinute, out int nSecond);

        [DllImport("ReadSMS.dll")]
        protected static extern bool MessageGetReceivedTimeString(IntPtr pMessage, StringBuilder strReceivedTime, int nMaxLength, string szFormat);

        [DllImport("ReadSMS.dll")]
        protected static extern bool MessageGetSubmitTime(IntPtr pMessage, out int nYear, out int nMonth, out int nDay, out int nHour, out int nMinute, out int nSecond);

        [DllImport("ReadSMS.dll")]
        protected static extern bool MessageGetSubmitTimeString(IntPtr pMessage, StringBuilder strSubmitTime, int nMaxLength, string szFormat);

        [DllImport("ReadSMS.dll")]
        protected static extern bool MessageGetRecipients(IntPtr pMessage);

        [DllImport("ReadSMS.dll")]
        protected static extern bool MessageGetNextRecipient(IntPtr pMessage, StringBuilder strName, int nMaxLenName, StringBuilder strEmail, int nMaxLenEmail, out int nType);

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -