C# SIM卡读取,添加,删除 网上没有只好自己写了
BY: 飞龙
QQ:316118740
BLOG: http://hi.baidu.com/alalmn
using System.Runtime.InteropServices; //DLL引用
namespace _11111111
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public const int SIM_CAPSTYPE_ALL = 0x3F; // 所有联系人
public const int SIM_PBSTORAGE_SIM = 0x10; //
public const int SIM_SMSSTORAGE_SIM = 0x2; //
[DllImport("cellcore.dll")]
public static extern int SimInitialize(uint dwFlags,int lpfnCallBack, uint dwParam, ref int lphSim);
[DllImport("cellcore.dll")]
public static extern int SimGetPhonebookStatus(int hSim,uint dwLocation, ref uint lpdwUsed, ref uint lpdwTotal);
//[DllImport("cellcore.dll")]
//public static extern int SimGetDevCaps(int hSim,uint dwCapsType, ref SimCaps lpSimCaps);
//[DllImport("cellcore.dll")]
//public static extern int SimGetSmsStorageStatus(int hSim,uint dwStorage, ref uint lpdwUsed, ref uint lpdwTotal);
[DllImport("cellcore.dll")]
public static extern int SimDeinitialize(int hSim);
[DllImport("cellcore.dll")]
public static extern int SimReadPhonebookEntry(int hSim, uint dwLocation, uint dwIndex, ref SIMPHONEBOOKENTRY entry);
/// <summary>
///
/// </summary>
/// <param name="hSim"></param>
/// <param name="dwLocation"></param>
/// <param name="dwIndex"></param>
/// <returns></returns>
[DllImport("cellcore.dll", SetLastError = true)] //删除
public static extern int SimDeletePhonebookEntry(int hSim, uint dwLocation, uint dwIndex);
[DllImport("cellcore.dll", SetLastError = true)] //添加
public static extern int SimWritePhonebookEntry(int hSim, uint dwLocation, uint dwIndex, ref SIMPHONEBOOKENTRY entry);
/*
[StructLayout(LayoutKind.Sequential)]
public struct SimCaps
{
public uint cbSize;
public uint dwParams;
public uint dwPBStorages;
public uint dwMinPBIndex;
public uint dwMaxPBIndex;
public uint dwMaxPBEAddressLength;
public uint dwMaxPBETextLength;
public uint dwLockFacilities;
public uint dwReadMsgStorages;
public uint dwWriteMsgStorages;
public uint dwNumLockingPwdLengths;
public SimLockingPwdLength rgLockingPwdLengths0;
public SimLockingPwdLength rgLockingPwdLengths1;
public SimLockingPwdLength rgLockingPwdLengths2;
public SimLockingPwdLength rgLockingPwdLengths3;
public SimLockingPwdLength rgLockingPwdLengths4;
public SimLockingPwdLength rgLockingPwdLengths5;
public SimLockingPwdLength rgLockingPwdLengths6;
public SimLockingPwdLength rgLockingPwdLengths7;
public SimLockingPwdLength rgLockingPwdLengths8;
public SimLockingPwdLength rgLockingPwdLengths9;
}*/