private void btnJpegCapture_Click(object sender, EventArgs e) { m_bJpegCapture = true; IntPtr ptrJpeg = new IntPtr(); uint nBuffersize = 2 * 1024 * 1024; ptrJpeg = Marshal.AllocHGlobal((int)nBuffersize); uint dwJpegSize = 0; if (PlayCtrl.PlayM4_GetJPEG(m_lPort, ptrJpeg, nBuffersize, ref dwJpegSize)) { DebugInfo("PlayM4_GetJPEG succ"); } else { uint dwErrorNo = PlayCtrl.PlayM4_GetLastError(m_lPort); DebugInfo("PlayM4_GetJPEG fail"); } FileStream fs = new FileStream("C:/GetJpegSave.jpg", FileMode.Create); byte[] by = new byte[dwJpegSize]; Marshal.Copy(ptrJpeg, by, 0, (int)dwJpegSize); fs.Write(by, 0, (int)dwJpegSize); fs.Close(); Marshal.FreeHGlobal(ptrJpeg); //public static extern bool PlayM4_GetJPEG(int nPort, ref byte pJpeg, uint nBufSize, ref uint pJpegSize); }