private static byte[][] DecodingMultiByteArrayHelper(BerSafeHandle berElement, char fmt, ref int error) { error = 0; // several berval IntPtr ptrResult = IntPtr.Zero; int i = 0; ArrayList binaryList = new ArrayList(); IntPtr tempPtr = IntPtr.Zero; byte[][] result = null; try { error = Wldap32.ber_scanf_ptr(berElement, new string(fmt, 1), ref ptrResult); if (error == 0) { if (ptrResult != IntPtr.Zero) { tempPtr = Marshal.ReadIntPtr(ptrResult); while (tempPtr != IntPtr.Zero) { berval ber = new berval(); Marshal.PtrToStructure(tempPtr, ber); byte[] berArray = new byte[ber.bv_len]; Marshal.Copy(ber.bv_val, berArray, 0, ber.bv_len); binaryList.Add(berArray); i++; tempPtr = Marshal.ReadIntPtr(ptrResult, i * IntPtr.Size); } result = new byte[binaryList.Count][]; for (int j = 0; j < binaryList.Count; j++) { result[j] = (byte[])binaryList[j]; } } } else { Debug.WriteLine("ber_scanf for format character 'V' failed"); } } finally { if (ptrResult != IntPtr.Zero) { Wldap32.ber_bvecfree(ptrResult); } } return(result); }
private static byte[][] DecodingMultiByteArrayHelper(BerSafeHandle berElement, char fmt, ref int error) { error = 0; IntPtr zero = IntPtr.Zero; int num = 0; ArrayList list = new ArrayList(); IntPtr ptr = IntPtr.Zero; byte[][] bufferArray = null; try { error = Wldap32.ber_scanf_ptr(berElement, new string(fmt, 1), ref zero); if ((error != 0) || !(zero != IntPtr.Zero)) { return(bufferArray); } for (ptr = Marshal.ReadIntPtr(zero); ptr != IntPtr.Zero; ptr = Marshal.ReadIntPtr(zero, num * Marshal.SizeOf(typeof(IntPtr)))) { berval structure = new berval(); Marshal.PtrToStructure(ptr, structure); byte[] destination = new byte[structure.bv_len]; Marshal.Copy(structure.bv_val, destination, 0, structure.bv_len); list.Add(destination); num++; } bufferArray = new byte[list.Count][]; for (int i = 0; i < list.Count; i++) { bufferArray[i] = (byte[])list[i]; } } finally { if (zero != IntPtr.Zero) { Wldap32.ber_bvecfree(zero); } } return(bufferArray); }
private static byte[][] DecodingMultiByteArrayHelper(BerSafeHandle berElement, char fmt, ref int error) { error = 0; IntPtr intPtr = (IntPtr)0; int num = 0; ArrayList arrayLists = new ArrayList(); byte[][] item = null; try { error = Wldap32.ber_scanf_ptr(berElement, new string(fmt, 1), ref intPtr); if (error == 0 && intPtr != (IntPtr)0) { for (IntPtr i = Marshal.ReadIntPtr(intPtr); i != (IntPtr)0; i = Marshal.ReadIntPtr(intPtr, num * Marshal.SizeOf(typeof(IntPtr)))) { berval _berval = new berval(); Marshal.PtrToStructure(i, _berval); byte[] numArray = new byte[_berval.bv_len]; Marshal.Copy(_berval.bv_val, numArray, 0, _berval.bv_len); arrayLists.Add(numArray); num++; } item = new byte[arrayLists.Count][]; for (int j = 0; j < arrayLists.Count; j++) { item[j] = (byte[])arrayLists[j]; } } } finally { if (intPtr != (IntPtr)0) { Wldap32.ber_bvecfree(intPtr); } } return(item); }