public void AllocateForPostView(short wStreamNum, int cbBuffer, out INSSBuffer ppBuffer, IntPtr pvContext) { m_Alloc = true; TempBuff b = new TempBuff(100000); ppBuffer = b as INSSBuffer; }
public void OnHeader([In, MarshalAs(UnmanagedType.Interface)] INSSBuffer pHeader) { byte[] buffer; uint Length; if (pHeader is ManBuffer) { buffer = ((ManBuffer)pHeader).Buffer; Length = ((ManBuffer)pHeader).UsedLength; } else { NSSBuffer b = new NSSBuffer(pHeader); Length = b.Length; buffer = new byte[Length]; b.Read(buffer, 0, (int)Length); } if (!m_HeaderWrote) { if (m_outputStream.CanSeek) { m_HeaderPosition = m_outputStream.Position; m_HeaderLength = Length; } m_HeaderWrote = true; m_outputStream.Write(buffer, 0, (int)Length); } else if (m_outputStream.CanSeek && (Length == m_HeaderLength)) { long pos = m_outputStream.Position; m_outputStream.Position = m_HeaderPosition; m_outputStream.Write(buffer, 0, (int)Length); m_outputStream.Position = pos; } }
public void AllocateForOutput( int dwOutputNum, int cbBuffer, out INSSBuffer ppBuffer, IntPtr pvContext) { throw new COMException("AllocateForOutput not implemented", E_NotImplemented); }
public void AllocateForStream( short wStreamNum, int cbBuffer, out INSSBuffer ppBuffer, IntPtr pvContext) { throw new COMException("AllocateForStream not implemented", E_NotImplemented); }
public void AllocateForStream(short wStreamNum, int cbBuffer, out INSSBuffer ppBuffer, IntPtr pvContext) { m_AllocateForStream = true; Debug.WriteLine("OnStreamSample"); TempBuff t = new TempBuff(cbBuffer); ppBuffer = t as INSSBuffer; }
public void Reset(INSSBuffer buff) { ReleaseBuffer(); _position = 0; _buffer = buff; _buffer.GetBufferAndLength(out _bufferPtr, out _length); _buffer.GetMaxLength(out _maxLength); }
/// <summary> /// NSSBuffer constructor /// </summary> /// <param name="buff">INSSBuffer to wrap</param> public NSSBuffer(INSSBuffer buff) { m_Buffer = buff; m_Buffer.GetBufferAndLength(out m_BufferPtr, out m_Length); m_Buffer.GetMaxLength(out m_MaxLength); }
/// <summary> /// NSSBuffer constructor /// </summary> /// <param name="buff">INSSBuffer to wrap</param> public NSSBuffer(INSSBuffer buff) { m_Buffer = buff; m_Buffer.GetBufferAndLength(out m_BufferPtr, out m_Length); m_Buffer.GetMaxLength(out m_MaxLength); }
public NSSBuffer(INSSBuffer buff) { if (buff == null) throw new ArgumentNullException("buff", "Invalid INSSBuffer parameter."); _buffer = buff; _buffer.GetBufferAndLength(out _bufferPtr, out _length); _buffer.GetMaxLength(out _maxLength); }
private void ExtractSampleData(INSSBuffer buffer, long duration) { IntPtr source; int dataLength; buffer.GetBufferAndLength(out source, out dataLength); var array = new byte[dataLength]; Marshal.Copy(source, array, 0, dataLength); SaveBytesToLastData(array); timeToNextImage += duration / 100000f; }
public void AllocateDataUnit(int cbDataUnit, out INSSBuffer ppDataUnit) { if (cbDataUnit > 0) { m_AllocateDataUnit = true; } TempBuff t = new TempBuff(cbDataUnit); ppDataUnit = t as INSSBuffer; }
public NSSBuffer(INSSBuffer buff) { if (buff == null) { throw new ArgumentNullException("buff", "Invalid INSSBuffer parameter."); } _buffer = buff; _buffer.GetBufferAndLength(out _bufferPtr, out _length); _buffer.GetMaxLength(out _maxLength); }
private void ExtractSampleData(INSSBuffer buffer, long duration) { IntPtr source; int dataLength; buffer.GetBufferAndLength(out source, out dataLength); var array = new byte[dataLength]; Marshal.Copy(source, array, 0, dataLength); SaveBytesToLastData(array); timeToNextImage += duration / 100000f; }
/// <summary> /// Saves the video. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="profileFileName">Name of the profile file.</param> /// <param name="files">Files.</param> public static void SaveVideo(string fileName, string profileFileName, ulong framesPerSecond, string [] files) { WMEncoder encoder = new WMEncoder(); IWMEncProfile2 profile = WMEncProfile.LoadEncodingProfile(encoder, profileFileName); WMEncProfile.ReleaseEncoder(ref encoder); using (WmvWriter writer = new WmvWriter()) { writer.Initialize((IWMProfile)profile.SaveToIWMProfile(), fileName); VideoInfoHeader viHeader = new VideoInfoHeader(); writer.FindVideoInputFormat(0, MediaSubTypes.WMMEDIASUBTYPE_RGB24, ref viHeader, false); writer.Start(); INSSBuffer sample = null; int bmcount = 0; Bitmap frame = new Bitmap((int)viHeader.bmiHeader.biWidth, (int)viHeader.bmiHeader.biHeight, PixelFormat.Format24bppRgb);; ulong fps = framesPerSecond; for (int i = 0; i < files.Length; i++) { if (files[i] != null) { Bitmap bmp = new Bitmap(files[i]); using (Graphics g = Graphics.FromImage(frame)) { g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.DrawImage(bmp, 0, 0, frame.Width, frame.Height); Console.Out.Write("."); } // Now render to the movie try { ulong time = ((ulong)bmcount++ *TimeSpan.TicksPerSecond) / fps; sample = writer.GetSampleFromBitmap(frame); writer.Writer.WriteSample(0, time, (uint)WMT_STREAM_SAMPLE_TYPE.WM_SF_CLEANPOINT, sample); } finally { Marshal.ReleaseComObject(sample); sample = null; bmp = null; GC.Collect(); } } } } }
// These routines are for testing IWMWriterAdvanced private void TestAdvanced(Bitmap b) { IWMWriterAdvanced adv = m_Writer as IWMWriterAdvanced; WriterStatistics ws; adv.GetStatistics(0, out ws); Debug.Assert(ws.dwCurrentBitrate > 0); INSSBuffer pSample = WriteOne(b); adv.WriteStreamSample(1, 1234, 5678, 101001, SampleFlag.CleanPoint, pSample); }
/// <summary> /// Saves the video. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="profileFileName">Name of the profile file.</param> /// <param name="dr">Dr.</param> public static void SaveVideo(string fileName, string profileFileName, ulong framesPerSecond, SqlDataReader dr) { WMEncoder encoder = new WMEncoder(); IWMEncProfile2 profile = WMEncProfile.LoadEncodingProfile(encoder, profileFileName); WMEncProfile.ReleaseEncoder(ref encoder); using (WmvWriter writer = new WmvWriter()) { writer.Initialize((IWMProfile)profile.SaveToIWMProfile(), fileName); VideoInfoHeader viHeader = new VideoInfoHeader(); writer.FindVideoInputFormat(0, MediaSubTypes.WMMEDIASUBTYPE_RGB24, ref viHeader, false); writer.Start(); INSSBuffer sample = null; int bmcount = 0; Bitmap c = new Bitmap((int)viHeader.bmiHeader.biWidth, (int)viHeader.bmiHeader.biHeight, PixelFormat.Format24bppRgb);; ulong fps = viHeader.AvgTimePerFrame / 100000; while (dr.Read()) { Bitmap b = Image.FromStream(new MemoryStream(dr.GetValue(1) as byte[])) as Bitmap; using (Graphics g = Graphics.FromImage(c)) { g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.DrawImage(b, 0, 0, c.Width, c.Height); } try { ulong time = ((ulong)bmcount++ *TimeSpan.TicksPerSecond) / fps; sample = writer.GetSampleFromBitmap(c); writer.Writer.WriteSample(0, time, (uint)WMT_STREAM_SAMPLE_TYPE.WM_SF_CLEANPOINT, sample); } finally { Marshal.ReleaseComObject(sample); sample = null; b = null; GC.Collect(); } } } }
//------------------------------------------------------------------------------ // Name: CWMVCopy::OnSample() // Desc: Implementation of IWMReaderCallback::OnSample. //------------------------------------------------------------------------------ public void OnSample( int dwOutputNum, long qwSampleTime, long qwSampleDuration, SampleFlag dwFlags, INSSBuffer pSample, IntPtr pvContext) { // // The samples are expected in OnStreamSample // m_hr = E_Unexpected; Console.WriteLine(string.Format("Reader Callback: Received a decompressed sample (hr=0x{0:x}).", m_hr)); m_hEvent.Set(); }
private void TestWrite() { Bitmap b = new Bitmap(@"c:\sga.png"); Initialize(b); m_Writer.SetOutputFilename(sFileName); m_Writer.BeginWriting(); INSSBuffer pSample = WriteOne(b); m_Writer.WriteSample(0, 1, SampleFlag.CleanPoint, pSample); m_Writer.Flush(); TestAdvanced(b); m_Writer.EndWriting(); }
private void Test() { Bitmap b = new Bitmap(@"c:\sga.png"); Initialize(b); m_Writer.SetOutputFilename(sFileName); m_Writer.BeginWriting(); INSSBuffer pSample = WriteOne(b); m_Writer.WriteSample(0, 1, SampleFlag.CleanPoint, pSample); m_Writer.Flush(); m_Writer.EndWriting(); Debug.Assert(m_OnHeader && m_IsRealTime && m_AllocateDataUnit && m_OnDataUnit && m_OnEndWriting); }
public void AllocateForOutput(int dwOutputNum, int cbBuffer, out INSSBuffer ppBuffer, IntPtr pvContext) { int i; lock (this) { i = m_UseNext; m_UseNext = (m_UseNext + 1) % MAXBUFFERS; } ppBuffer = m_InsBuf[i]; while (!m_InsBuf[i].IsBufferFree()) { Thread.Sleep(1); } ppBuffer.SetLength(cbBuffer); }
public void OnDataUnit([In, MarshalAs(UnmanagedType.Interface)] INSSBuffer pDataUnit) { byte[] buffer; int Length; if (pDataUnit is ManBuffer) { buffer = ((ManBuffer)pDataUnit).Buffer; Length = (int)((ManBuffer)pDataUnit).UsedLength; } else { NSSBuffer b = new NSSBuffer(pDataUnit); Length = (int)b.Length; buffer = new byte[Length]; b.Read(buffer, 0, Length); } base.Write(buffer, 0, Length); }
private bool ReadNextSample(out INSSBuffer buffer, out long duration, out SampleFlag sampleFlag) { try { long sampleTime; int outputNum; short streamNum; syncReader.GetNextSample(0, out buffer, out sampleTime, out duration, out sampleFlag, out outputNum, out streamNum); } catch (Exception) { buffer = null; duration = 0; sampleFlag = 0; return(false); } return(true); }
private bool ReadNextSample(out INSSBuffer buffer, out long duration, out SampleFlag sampleFlag) { try { long sampleTime; int outputNum; short streamNum; syncReader.GetNextSample(0, out buffer, out sampleTime, out duration, out sampleFlag, out outputNum, out streamNum); } catch (Exception) { buffer = null; duration = 0; sampleFlag = 0; return false; } return true; }
private void TestSink() { IWMWriterAdvanced pWriterA; pWriterA = m_Writer as IWMWriterAdvanced; pWriterA.AddSink(this); Bitmap b = new Bitmap(@"c:\sga.png"); Initialize(b); m_Writer.SetOutputFilename(sFileName); m_Writer.BeginWriting(); INSSBuffer pSample = WriteOne(b); m_Writer.WriteSample(0, 1, SampleFlag.CleanPoint, pSample); m_Writer.Flush(); m_Writer.EndWriting(); }
public void Close() { //if (m_streamWrapper != null) // m_streamWrapper.Close(); if (m_IO != null) { m_IO.Close(); } if (m_pSample != null) { Marshal.ReleaseComObject(m_pSample); } if (m_syncReader != null) { m_syncReader.Close(); Marshal.ReleaseComObject(m_syncReader); } m_IO = null; m_pSample = null; m_syncReader = null; }
public void OnHeader([In, MarshalAs(UnmanagedType.Interface)] INSSBuffer pHeader) { byte[] buffer; uint length; var manBuff = pHeader as ManBuffer; if (manBuff != null) { buffer = manBuff.Buffer; length = manBuff.UsedLength; manBuff.Dispose(); } else { using (var b = new NSSBuffer(pHeader)) { length = b.Length; buffer = new byte[length]; b.Read(buffer, 0, (int)length); } } if (!m_HeaderWrote) { if (BaseStream.CanSeek) { m_HeaderPosition = BaseStream.Position; m_HeaderLength = length; } m_HeaderWrote = true; base.Write(buffer, 0, (int)length); } else if (BaseStream.CanSeek && (length == m_HeaderLength)) { long pos = BaseStream.Position; BaseStream.Position = m_HeaderPosition; BaseStream.Write(buffer, 0, (int)length); BaseStream.Position = pos; } }
public void OnDataUnit([In, MarshalAs(UnmanagedType.Interface)] INSSBuffer pDataUnit) { byte[] buffer; int length; var manBuff = pDataUnit as ManBuffer; if (manBuff != null) { buffer = manBuff.Buffer; length = (int)manBuff.UsedLength; manBuff.Dispose(); } else { using (var b = new NSSBuffer(pDataUnit)) { length = (int)b.Length; buffer = new byte[length]; b.Read(buffer, 0, length); } } base.Write(buffer, 0, length); }
public void OnSample(int dwOutputNum, long cnsSampleTime, long cnsSampleDuration, SampleFlag dwFlags, INSSBuffer pSample, IntPtr pvContext) { m_CallbackCalled = true; }
public void OnSample(int dwOutputNum, long cnsSampleTime, long cnsSampleDuration, SampleFlag dwFlags, INSSBuffer pSample, IntPtr pvContext) { throw new NotImplementedException(); }
public void AllocateForStream(short wStreamNum, int cbBuffer, out INSSBuffer ppBuffer, IntPtr pvContext) { throw new Exception("The method or operation is not implemented."); }
public void OnStreamSample(short wStreamNum, long cnsSampleTime, long cnsSampleDuration, SampleFlag dwFlags, INSSBuffer pSample, IntPtr pvContext) { throw new Exception("The method or operation is not implemented."); }
public void OnSample(int dwOutputNum, long cnsSampleTime, long cnsSampleDuration, SampleFlag dwFlags, INSSBuffer pSample, IntPtr pvContext) { try { // Check the output number of the sample against the stored output number. // Because only the first audio output is stored, all other outputs, // regardless of type, will be ignored. Shouldn't be an issue since // SetStreams turned off delivery of samples for all streams except the // one we want if (dwOutputNum != m_dwAudioOutputNum) { return; } // The rest of the code in this method uses Windows Multimedia wave // handling functions to play the content. // IntPtr ip = (pSample as INSBuf).GetPtr(); try { // // Send the sample to the wave output device. // int mmr = waveOut.Write(m_hWaveOut, ip, WAVHDRLEN); waveOut.ThrowExceptionForError(mmr); } catch { // // Stop the player. // Stop(); throw; } if (TimeChanged != null) { // Only send time events every 1/10 of a second if (Math.Abs(cnsSampleTime - m_OldTime) > (ONESEC / 10)) { m_OldTime = cnsSampleTime; TimeChangeArgs ta = new TimeChangeArgs(cnsSampleTime); try { TimeChanged(this, ta); } catch { } } } } catch (Exception e) { Debug.WriteLine(e.Message); } finally { // If we weren't allocating our own samples in IWMReaderCallbackAdvanced::AllocateForOutput, // we'd have to free this here. //Marshal.ReleaseComObject(pSample); } }
public void AllocateForOutputEx(int dwOutputNum, int cbBuffer, out INSSBuffer ppBuffer, SampleFlagEx dwFlags, long cnsSampleTime, long cnsSampleDuration, IntPtr pvContext) { throw new Exception("The method or operation is not implemented."); }
public override int Read(byte[] buffer, int offset, int count) { if (m_reader != null) { int read = 0; if ((m_length > 0) && ((m_length - m_position) < count)) { count = (int)(m_length - m_position); } if (m_BufferReader != null) { while ((m_BufferReader.Position < m_BufferReader.Length) && (read < count)) { read += m_BufferReader.Read(buffer, offset, count); } } while (read < count) { INSSBuffer sample = null; ulong SampleTime = 0; ulong Duration = 0; uint Flags = 0; try { m_reader.GetNextSample(m_outputStream, out sample, out SampleTime, out Duration, out Flags, out m_outputNumber, out m_outputStream); } catch (COMException e) { if (e.ErrorCode == WM.NS_E_NO_MORE_SAMPLES) { //No more samples if (m_outputFormat.BitsPerSample == 8) { while (read < count) { buffer[offset + read] = 0x80; read++; } } else { Array.Clear(buffer, offset + read, count - read); read = count; } break; } else { throw (e); } } m_BufferReader = new NSSBuffer(sample); read += m_BufferReader.Read(buffer, offset + read, count - read); } if ((m_BufferReader != null) && (m_BufferReader.Position >= m_BufferReader.Length)) { m_BufferReader = null; } m_position += read; return(read); } else { throw new ObjectDisposedException(this.ToString()); } }
static string GetStringFromNSSBuffer( INSSBuffer NsBuffer) { Debug.WriteLine("CacheProxyPlugin::GetStringFromNSSBuffer entered"); uint bufSize; IntPtr pBuf = IntPtr.Zero; NsBuffer.GetBufferAndLength( pBuf, out bufSize ); byte[] Buf = new byte[bufSize]; Marshal.Copy(pBuf,Buf,0,(int)bufSize); /* string s = Marshal.PtrToStringUni( pBuf, (int) bufSize / 2 ); return s; */ return Convert.ToBase64String(Buf,0,(int)bufSize); }
public void Reset(INSSBuffer buff) { ReleaseBuffer(); _position = 0; _buffer = buff; _buffer.GetBufferAndLength(out _bufferPtr, out _length); _buffer.GetMaxLength(out _maxLength); }
/// <summary> /// NSSBuffer constructor /// </summary> /// <param name="buff">INSSBuffer to wrap</param> public NSSBuffer(INSSBuffer buff) { Reset(buff); }
public Bitmap GetBitmapFromSample(INSSBuffer sample, Guid videoSubType, VideoInfoHeader outputVideoInfoHeader, VideoInfoHeader inputVideoInfoHeader) { IntPtr sampleBuffer; PixelFormat pixelFormat = PixelFormat.DontCare; uint length = 0; sample.GetBufferAndLength(out sampleBuffer, out length); if (videoSubType == MediaSubTypes.WMMEDIASUBTYPE_RGB32) { pixelFormat = PixelFormat.Format32bppRgb; } else if (videoSubType == MediaSubTypes.WMMEDIASUBTYPE_RGB555) { pixelFormat = PixelFormat.Format16bppRgb555; } else if (videoSubType == MediaSubTypes.WMMEDIASUBTYPE_RGB24) { pixelFormat = PixelFormat.Format24bppRgb; } else { throw new ArgumentException("videoSubType", "Unsupported video subtype [" + videoSubType + "]."); } #if DEBUG && DEBUG_SAMPLES Logger.WriteLogMessage("Grabbed sample buffer, length [" + length + "], pixelFormat [" + pixelFormat + "]."); #endif uint stride = outputVideoInfoHeader.bmiHeader.biWidth * outputVideoInfoHeader.bmiHeader.biPlanes * outputVideoInfoHeader.bmiHeader.biBitCount / 8; #if DEBUG && DEBUG_SAMPLES Logger.WriteLogMessage("Creating bitmap [" + outputVideoInfoHeader.bmiHeader.biWidth + "x" + outputVideoInfoHeader.bmiHeader.biHeight + "], stride [" + stride + "], pixelFormat [" + pixelFormat + "]."); #endif Bitmap outputBitmap = new Bitmap((int)outputVideoInfoHeader.bmiHeader.biWidth, (int)outputVideoInfoHeader.bmiHeader.biHeight, (int)stride, pixelFormat, sampleBuffer); Bitmap inputBitmap = new Bitmap((int)inputVideoInfoHeader.bmiHeader.biWidth, (int)inputVideoInfoHeader.bmiHeader.biHeight, outputBitmap.PixelFormat); using (Graphics g = Graphics.FromImage(inputBitmap)) { g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.DrawImage(outputBitmap, 0, 0, inputBitmap.Width, inputBitmap.Height); #if DEBUG && DEBUG_SAMPLES Logger.WriteLogMessage("Copied output bitmap [" + outputBitmap.Width + "x" + outputBitmap.Height + "] to input bitmap [" + inputBitmap.Width + "x" + inputBitmap.Height + "]."); #endif } // // make bitmap was screen-oriented // inputBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); return inputBitmap; }
public int Read(AudioBuffer buff, int maxLength) { buff.Prepare(this, maxLength); int buff_offset = 0; int buff_size = buff.ByteLength; while (m_pSampleSize < buff_size) { if (m_pSampleSize > 0) { IntPtr pdwBuffer; m_pSample.GetBuffer(out pdwBuffer); Marshal.Copy((IntPtr)(pdwBuffer.ToInt64() + m_pSampleOffset), buff.Bytes, buff_offset, m_pSampleSize); buff_size -= m_pSampleSize; buff_offset += m_pSampleSize; m_sampleOffset += m_pSampleSize; m_pSampleSize = 0; Marshal.ReleaseComObject(m_pSample); m_pSample = null; } long cnsSampleTime; long cnsDuration; SampleFlag flags; int dwOutputNum; short wStreamNum; try { m_syncReader.GetNextSample(m_wStreamNum, out m_pSample, out cnsSampleTime, out cnsDuration, out flags, out dwOutputNum, out wStreamNum); } catch (COMException ex) { // EOF if (ex.ErrorCode == NSResults.E_NO_MORE_SAMPLES) { if ((m_sampleOffset % PCM.BlockAlign) != 0) { throw new Exception("(m_sampleOffset % PCM.BlockAlign) != 0"); } m_sampleCount = m_sampleOffset / PCM.BlockAlign; if ((buff_offset % PCM.BlockAlign) != 0) { throw new Exception("(buff_offset % PCM.BlockAlign) != 0"); } return(buff.Length = buff_offset / PCM.BlockAlign); } throw ex; } //if (dwOutputNum != m_dwAudioOutputNum || wStreamNum != m_wStreamNum) //{ //} m_pSampleOffset = 0; m_pSample.GetLength(out m_pSampleSize); } if (buff_size > 0) { IntPtr pdwBuffer; m_pSample.GetBuffer(out pdwBuffer); Marshal.Copy((IntPtr)(pdwBuffer.ToInt64() + m_pSampleOffset), buff.Bytes, buff_offset, buff_size); m_pSampleOffset += buff_size; m_pSampleSize -= buff_size; m_sampleOffset += buff_size; buff_offset += buff_size; buff_size = 0; } if ((buff_offset % PCM.BlockAlign) != 0) { throw new Exception("(buff_offset % PCM.BlockAlign) != 0"); } return(buff.Length = buff_offset / PCM.BlockAlign); }
// recording public void DoRecord(Bitmap bitmap) { try { using (Graphics g = Graphics.FromImage(frame)) { g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.DrawImage(bitmap, 0, 0, frame.Width, frame.Height); } ulong time = ((ulong)bmcount++ * TimeSpan.TicksPerSecond) / fps; sample = writer.GetSampleFromBitmap(frame); writer.Writer.WriteSample(0, time, (uint)WMT_STREAM_SAMPLE_TYPE.WM_SF_CLEANPOINT, sample); Marshal.ReleaseComObject(sample); sample = null; } catch (Exception) { // error handle throw; } }