PDA 实现拨打电话 C#源代码
来源:互联网 发布:ip端口号查询 编辑:程序博客网 时间:2024/04/29 17:37
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace dropcallDemo
{
/// <summary>
/// Identifies the phone number type specified.
/// </summary>
public enum AddressType
{
/// <summary>Unknown phone number type.</summary>
Unknown,
/// <summary>International phone number.</summary>
International,
/// <summary>National phone number.</summary>
National,
/// <summary>Network-specific phone number.</summary>
NetworkSpecific,
/// <summary>Subscriber phone number.</summary>
Subscriber,
/// <summary>Alphanumeric phone number.</summary>
Alphanumeric,
/// <summary>Abbreviated phone number.</summary>
Abbreviated
}
/// <summary>
/// Information about the phone number.
/// </summary>
public struct PhoneAddress
{
/// <summary>The address type.</summary>
public AddressType AddressType;
/// <summary>The phone number in string format.</summary>
public String Address;
}
/// <summary>
/// Phone control.
/// </summary>
public class Phone
{
private static long PMCF_DEFAULT = 0x00000001;
private static long PMCF_PROMPTBEFORECALLING = 0x00000002;
private struct PhoneMakeCallInfo
{
public IntPtr cbSize;
public IntPtr dwFlags;
public IntPtr pszDestAddress;
public IntPtr pszAppName;
public IntPtr pszCalledParty;
public IntPtr pszComment;
}
[DllImport("phone.dll")]
private static extern IntPtr PhoneMakeCall(ref PhoneMakeCallInfo ppmci);
/// <summary>
/// Dials the specified phone number.
/// </summary>
/// <param name="PhoneNumber">Phone number to dial.</param>
public static void MakeCall(string PhoneNumber)
{
MakeCall(PhoneNumber, false);
}
/// <summary>
/// Dials the specified phone number.
/// </summary>
/// <param name="PhoneNumber">Phone number to dial.</param>
/// <param name="PromptBeforeCall">Prompts the user before the call is placed.</param>
unsafe public static void MakeCall(string PhoneNumber, bool PromptBeforeCall)
{
IntPtr res;
PhoneNumber += '/0';
char[] cPhoneNumber = PhoneNumber.ToCharArray();
fixed (char* pAddr = cPhoneNumber)
{
PhoneMakeCallInfo info = new PhoneMakeCallInfo();
info.cbSize = (IntPtr)Marshal.SizeOf(info);
info.pszDestAddress = (IntPtr)pAddr;
if (PromptBeforeCall)
{
info.dwFlags = (IntPtr)PMCF_PROMPTBEFORECALLING;
}
else
{
info.dwFlags = (IntPtr)PMCF_DEFAULT;
}
res = PhoneMakeCall(ref info);
}
}
}
/// <summary>
/// Reads information from the Subscriber Identity Module (SIM)
/// </summary>
public class Sim
{
private static long SERVICE_PROVIDER = 0x00006F46;
[StructLayout(LayoutKind.Sequential)]
private struct SimRecord
{
public IntPtr cbSize;
public IntPtr dwParams;
public IntPtr dwRecordType;
public IntPtr dwItemCount;
public IntPtr dwSize;
}
[DllImport("sms.dll")]
private static extern IntPtr SmsGetPhoneNumber(IntPtr psmsaAddress);
[DllImport("cellcore.dll")]
private static extern IntPtr SimInitialize(IntPtr dwFlags, IntPtr lpfnCallBack, IntPtr dwParam, out IntPtr lphSim);
[DllImport("cellcore.dll")]
private static extern IntPtr SimGetRecordInfo(IntPtr hSim, IntPtr dwAddress, ref SimRecord lpSimRecordInfo);
[DllImport("cellcore.dll")]
private static extern IntPtr SimReadRecord(IntPtr hSim, IntPtr dwAddress, IntPtr dwRecordType, IntPtr dwIndex, byte[] lpData, IntPtr dwBufferSize, ref IntPtr lpdwBytesRead);
[DllImport("cellcore.dll")]
private static extern IntPtr SimDeinitialize(IntPtr hSim);
/// <summary>
/// Gets the phone number from the SIM.
/// </summary>
/// <returns>PhoneAddress structure with phone number.</returns>
unsafe public static PhoneAddress GetPhoneNumber()
{
PhoneAddress phoneaddr = new PhoneAddress();
Byte[] buffer = new Byte[516];
fixed (byte* pAddr = buffer)
{
IntPtr res = SmsGetPhoneNumber((IntPtr)pAddr);
if (res != IntPtr.Zero)
throw new Exception("Could not get phone number from SIM");
byte* pCurrent = pAddr;
phoneaddr.AddressType = (AddressType)Marshal.ReadInt32((IntPtr)pCurrent);
pCurrent += Marshal.SizeOf(phoneaddr.AddressType);
phoneaddr.Address = Marshal.PtrToStringUni((IntPtr)pCurrent);
}
return phoneaddr;
}
/// <summary>
/// Gets the current wireless carriers network name from the SIM.
/// </summary>
/// <returns>The carrier description.</returns>
public static string GetServiceProvider()
{
IntPtr hSim, res;
res = SimInitialize(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, out hSim);
if (res != IntPtr.Zero)
throw new Exception("Could not initialize SIM");
SimRecord rec = new SimRecord();
rec.cbSize = (IntPtr)Marshal.SizeOf(rec);
res = SimGetRecordInfo(hSim, (IntPtr)SERVICE_PROVIDER, ref rec);
if (res != IntPtr.Zero)
throw new Exception("Could not read the service provider information from the SIM");
byte[] bData = new byte[(int)rec.dwSize + 1];
IntPtr dwBytesRead = IntPtr.Zero;
res = SimReadRecord(hSim, (IntPtr)SERVICE_PROVIDER, rec.dwRecordType, IntPtr.Zero, bData, (IntPtr)bData.Length, ref dwBytesRead);
if (res != IntPtr.Zero)
throw new Exception("Could not read the service provider from the SIM");
byte[] bScrubbed = new byte[(int)dwBytesRead];
int nPos = 0;
// Scrub the non-ascii characters
for (int i = 0; i < (int)dwBytesRead; i++)
{
if (((int)bData[i] > 19) && ((int)bData[i] < 125))
{
bScrubbed[nPos] = bData[i];
nPos++;
}
}
SimDeinitialize(hSim);
return Encoding.ASCII.GetString(bScrubbed, 0, bScrubbed.Length);
}
}
}
- PDA 实现拨打电话 C#源代码
- Android_Phone源代码拨打电话解读
- Android_Phone源代码拨打电话解读
- android实现拨打电话
- android实现拨打电话
- 快速实现拨打电话
- android实现拨打电话
- Unity实现拨打电话
- Android 实现拨打电话
- android电话拨打的实现
- 拨打电话的简单实现
- 代码实现电话的拨打
- Android 实现拨打电话功能
- 实现电话自动拨打、挂断
- 拨打电话的简单实现
- 实现电话自动拨打、挂断
- 实现电话自动拨打、挂断
- android拨打电话功能实现
- (转)面试常见问题
- 转:Flex事件讲解
- SQL 有条件地筛选重复数据
- 消息映射深度探索
- 如果你出现这十种迹象,你就该跳槽了
- PDA 实现拨打电话 C#源代码
- 能上QQ但不能浏览网页01
- 简便实现Oracle数据库文件移动方法
- C#基础知识(1)
- 能上QQ但不能浏览网页02
- テスト・カバレッジ(テスト網羅率)
- (转载)EMC面经
- 什么是文件系统?
- 能上QQ不能打开网页的解决办法