private void GatherAddressCaps() { var lac = new LINEADDRESSCAPS(); byte[] rawBuffer = null; int rc, neededSize = 1024; do { lac.dwTotalSize = neededSize; IntPtr pLac = Marshal.AllocHGlobal(neededSize); Marshal.StructureToPtr(lac, pLac, true); rc = NativeMethods.lineGetAddressCaps(_lineOwner.TapiManager.LineHandle, _lineOwner.Id, _addressId, (int)_lineOwner.NegotiatedVersion, 0, pLac); Marshal.PtrToStructure(pLac, lac); if (lac.dwNeededSize > neededSize) { neededSize = lac.dwNeededSize; rc = NativeMethods.LINEERR_STRUCTURETOOSMALL; } else if (rc == NativeMethods.LINEERR_OK) { rawBuffer = new byte[lac.dwUsedSize]; Marshal.Copy(pLac, rawBuffer, 0, lac.dwUsedSize); } Marshal.FreeHGlobal(pLac); }while (rc == NativeMethods.LINEERR_STRUCTURETOOSMALL); _addrCaps = new AddressCapabilities(lac, rawBuffer, _lineOwner.StringFormat); }
/// <summary> /// Constructor for the AddressCapabilties /// </summary> /// <param name="lac"></param> /// <param name="rawBuffer"></param> /// <param name="stringFormat"></param> internal AddressCapabilities(LINEADDRESSCAPS lac, byte[] rawBuffer, int stringFormat) { _lac = lac; _rawBuffer = rawBuffer; _stringFormat = stringFormat; _callFeatures = new CallFeatureSet(lac.dwCallFeatures); // Grab the available call treatments if (_lac.dwCallTreatmentListSize > 0 && _lac.dwNumCallTreatments > 0) { IntPtr pi = Marshal.AllocHGlobal(_lac.dwCallTreatmentListSize); var lce = new LINECALLTREATMENTENTRY(); _treatments = new CallTreatment[_lac.dwNumCallTreatments]; int len = Marshal.SizeOf(lce); for (int i = 0; i < _lac.dwNumCallTreatments; i++) { Marshal.Copy(rawBuffer, _lac.dwCallTreatmentListOffset + (i * len), pi, len); Marshal.PtrToStructure(pi, lce); _treatments[i] = new CallTreatment(lce.dwCallTreatmentID, NativeMethods.GetString(rawBuffer, lce.dwCallTreatmentNameOffset, lce.dwCallTreatmentNameSize, stringFormat)); } Marshal.FreeHGlobal(pi); } }