Pointers and fixed size buffers only be used in unsafe context .


  • Hi ,


          For getting mobile number in windows mobile emulators i wrote the following code .but it giving error like "Pointers and fixed size buffers only be used in unsafe context".Please suggest how to Correct this .And suggest it's the code is working for to get the mobile number from windows mobile emulators .


                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 =


                    pCurrent += Marshal.SizeOf(phoneaddr.AddressType);

                    phoneaddr.Address = Marshal.PtrToStringUni((IntPtr)pCurrent);


    Wednesday, April 20, 2011 6:53 AM


  •  Microsoft has an article describing how to access SIM information in C# and VB.NET using those APIs here:

    The article does say "This function is declared unsafe as we're directly reading from memory from managed code", but they leave out the actual function declaration. You just have to add the "unsafe" keyword to your function declaration as shown here:


    Wednesday, April 20, 2011 2:31 PM