Example #1
0
        private static int ReadDelegate(IntPtr buf, int sz, int nmemb,
                                        IntPtr parm)
        {
            int bytes = sz * nmemb;

            byte[] b = new byte[bytes];
            //GCHandle gch = (GCHandle)parm;
            //Easy easy = (Easy)gch.Target;
            Easy easy = _CurrentEasy;

            if (easy == null)
            {
                return(0);
            }
            if (easy.m_pfRead == null)
            {
                return(0);
            }
            int nRead = easy.m_pfRead(b, sz, nmemb, easy.m_readData);

            if (nRead > 0)
            {
                for (int i = 0; i < nRead; i++)
                {
                    Marshal.WriteByte(buf, i, b[i]);
                }
            }
            return(nRead);
        }