Пример #1
0
        private void ReadProviderList()
        {
            var lpl = new LINEPROVIDERLIST();

            int rc, neededSize = 1024;

            do
            {
                lpl.dwTotalSize = neededSize;
                IntPtr pLpl = Marshal.AllocHGlobal(neededSize);
                Marshal.StructureToPtr(lpl, pLpl, true);
                rc = NativeMethods.lineGetProviderList((int)TapiVersion.V21, pLpl);
                Marshal.PtrToStructure(pLpl, lpl);
                if (lpl.dwNeededSize > neededSize)
                {
                    neededSize = lpl.dwNeededSize;
                    rc         = NativeMethods.LINEERR_STRUCTURETOOSMALL;
                }
                else if (rc == NativeMethods.LINEERR_OK)
                {
                    var rawBuffer = new byte[lpl.dwUsedSize];
                    Marshal.Copy(pLpl, rawBuffer, 0, lpl.dwUsedSize);
                    for (int i = 0; i < lpl.dwNumProviders; i++)
                    {
                        _providers.Add(ReadTapiProviderInfo(lpl, rawBuffer, i));
                    }
                }
                Marshal.FreeHGlobal(pLpl);
            }while (rc == NativeMethods.LINEERR_STRUCTURETOOSMALL);
        }
Пример #2
0
        private static TapiProvider ReadTapiProviderInfo(LINEPROVIDERLIST lpl, byte[] rawBuffer, int pos)
        {
            var lpe  = new LINEPROVIDERENTRY();
            int size = Marshal.SizeOf(lpe);

            pos = lpl.dwProviderListOffset + (pos * size);
            IntPtr pLpe = Marshal.AllocHGlobal(size);

            Marshal.Copy(rawBuffer, pos, pLpe, size);
            Marshal.PtrToStructure(pLpe, lpe);
            Marshal.FreeHGlobal(pLpe);

            return(new TapiProvider(lpe.dwPermanentProviderID,
                                    NativeMethods.GetString(rawBuffer,
                                                            lpe.dwProviderFilenameOffset, lpe.dwProviderFilenameSize,
                                                            NativeMethods.STRINGFORMAT_UNICODE)));
        }