1

Hello Everyone!!! I am novice in Telephony Application and trying to make a very simple Panasonic telephone application to change class of service (COS) using Windows Tapi32.dll and panasonic TSP.I have made a function which will change the class of service in PBX ..But on running the application class of service is not changing in the PBX neither is my code giving me any type of error...Below is my code...

[DllImport("Tapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
   internal static extern int lineDevSpecific(IntPtr hLine,uint dwAddressID,uint hCall, IntPtr lpParams,uint dwSize);

    [StructLayout(LayoutKind.Sequential)]
    public struct UserRec
    {
        public int dwMode
        {
            get
            {
                return dwMode;
            }
            set
            {
                dwMode = 4;
            }
        }

        public int dwParam1
        {
            get
            {
                return dwParam1;
            }
            set
            {
                dwParam1 = 18;
            }
        }
    }

   public static void Main(string[] args)
    {
        uint add = 0;
        uint call = 0;
        uint size = 0;

        string vline = "125";
        //IntPtr hline = &vline;
        IntPtr hline = Marshal.StringToHGlobalUni(vline);

        var sizeUserRec = Marshal.SizeOf(typeof(UserRec));
        var userRec = Marshal.AllocHGlobal(sizeUserRec);
        lineDevSpecific(hline, add, call, userRec, size);
        var x = (UserRec)Marshal.PtrToStructure(userRec, typeof(UserRec));
        Marshal.FreeHGlobal(userRec);
        Console.WriteLine("Hii");

 }

Plz help me or direct me in the write direction to get the things done.Thanx in advance...

vikas
  • 339
  • 2
  • 6
  • 12

1 Answers1

1

lineDevSpecific() exposes error conditions through its return value, not SetLastError(), so:

  • You probably should remove SetLastError=true from the [DllImport] attribute,

  • You should test the return value of the function against the error constants listed in the documentation:

    int result = lineDevSpecific(hline, add, call, userRec, size);
    if (result < 0) {
        // Handle error, depending on the value of 'result'.
    }
    
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • @Frederick Thanx Sir for ur response...Sir i changed the code as u suggested and its giving error will u plz tell me how to getoff this error.. – vikas Mar 04 '13 at 11:41
  • @Frederick Plz sir guide me how to catch the error in this case as 'result' is giving negative value.. – vikas Mar 04 '13 at 11:55
  • @vikas, well, as I said you have to compare the value of `result` with the constants listed in the documentation. You will probably have to fetch the value of each constant from the header file (`tapi.h`) in order to redefine them in your managed module. – Frédéric Hamidi Mar 04 '13 at 12:03
  • @Frederick Thank u sir for ur response As i am novice i have no clue how to fetch value from header file and sir i am using c# .If u elaborate or direct me to the right place ..will be gratefull Sir.Thank you very much – vikas Mar 04 '13 at 12:12