HRESULT RIL_DevSpecific( HRIL hRil, // @parm handle to RIL instance returned by const BYTE* lpbParams, // @parm parameters for the operation to be performed DWORD dwSize // @parm size of the data pointed to by

in bytes ); typedef struct tagRILDevSpecificParams { DWORD dwFunctionID; BYTE *lpInputParameters; BYTE *lpOutputParameters; } RIL_DEVSPECIFIC_PARAMS, *lpRIL_DEVSPECIFIC_PARAMS; //Now my C# Code: [DllImport("ril.dll")] private static extern IntPtr RIL_DevSpecific(IntPtr hRil, ref IntPtr parm, IntPtr dwSize); #endregion RIL_DEVSPECIFIC_PARAMS lbpParams = new RIL.RIL_DEVSPECIFIC_PARAMS(); byte[] lpOut = new byte[256]; lbpParams.dwFunctionID = 0x33; lbpParams.lpInputParameters = new byte[256]; lbpParams.lpInputParameters = System.Text.ASCIIEncoding.ASCII.GetBytes(szCmd); lbpParams.lpOutputParameters = lpOut; int sizOf = Marshal.SizeOf(lbpParams); //here's the first error. IntPtr ptr = Marshal.AllocHGlobal(sizOf); Marshal.StructureToPtr(lbpParams, ptr, true); res = RIL_DevSpecific(hRil, ref ptr, (IntPtr)Marshal.SizeOf(lbpParams));