In a comment on HOW-TO: Retrieve the ICC-ID using the SIM Manager APIs, Paul requested some help in translating the VB code to C#. Here it is in all its glory.
P/Invoke prototypes:
[DllImport("cellcore.dll")] static extern int SimInitialize ( uint dwFlags, IntPtr lpfnCallback, uint dwParam, ref IntPtr lphSim); [DllImport("cellcore.dll")] static extern int SimDeinitialize (IntPtr hSim); [DllImport("cellcore.dll")] static extern int SimReadRecord ( IntPtr hSim, uint dwAddress, uint dwRecordType, uint dwIndex, byte[] lpData, uint dwBufferSize, ref int dwSize);
Constants:
const int EF_ICCID = 0x2FE2; const int SIM_RECORDTYPE_TRANSPARENT = 0x1;
Implementation:
IntPtr hSim; byte[] iccid = new byte[10]; int zero = 0; SimInitialize (0, IntPtr.Zero, 0, ref hSim); SimReadRecord (hSim, EF_ICCID, SIM_RECORDTYPE_TRANSPARENT, 0, iccid, (uint)iccid.Length, ref zero); SimDeinitalize (hSim);