private void ExtractEx([In] IntPtr rawimage, int width, int height, int res, ref FingerprintTemplate fingerTemplate, int context, int tptFormat) { IntPtr zero = IntPtr.Zero; try { int cb = 0x2710 * Marshal.SizeOf(typeof(byte)); zero = Marshal.AllocHGlobal(cb); int quality = FingerprintException.CheckError(GrFingerprintProxy.GrExtractEx(rawimage, width, height, res, zero, ref cb, context, tptFormat)); zero = Marshal.ReAllocHGlobal(zero, (IntPtr)cb); fingerTemplate = new FingerprintTemplate(zero, cb, quality); } catch (OutOfMemoryException exception) { throw new FingerprintException(-7, exception); } finally { Marshal.FreeHGlobal(zero); } }