Exemplo n.º 1
0
        private static MCIResult ProcessMCIRequest(MCIRequest request, IntPtr hwndHandle = new IntPtr())
        {
            var           mciResult = new MCIResult();
            StringBuilder ret       = null;

            if (request.retLen > 0)
            {
                ret = new StringBuilder(request.retLen);
            }

            // send the command string to the MCI
            mciResult.ReturnValue = mciSendString(request.MCICommand, ret, request.retLen, hwndHandle);

            // if an error was returned, raise the event, and throw exception if appropriate
            if (mciResult.IsError())
            {
                var buffer = new StringBuilder(128);
                mciGetErrorString(mciResult.ReturnValue, buffer, 128);
                ret = buffer;
            }

            if (ret != null)
            {
                mciResult.ReturnMessage = ret.ToString();
            }
            else
            {
                mciResult.ReturnMessage = string.Empty;
            }

            if (mciResult.IsError())
            {
                if (Error != null)
                {
                    Error(new MCIErrorEventArgs(request.MCICommand, mciResult.ReturnValue, mciResult.ReturnMessage));
                }

                if (MCIErrorsThrowExceptions)
                {
                    throw new MediaPlayerException(request.MCICommand, mciResult.ReturnValue, mciResult.ReturnMessage);
                }
            }

#if DEBUG
            Console.WriteLine(string.Format("Sent at: {4}   Tick Count: {0}   Command: {1}   Result: {2} '{3}'",
                                            Environment.TickCount,
                                            request.MCICommand,
                                            mciResult.ReturnValue.ToString(),
                                            mciResult.ReturnMessage,
                                            request.Tick));
#endif

            return(mciResult);
        }
Exemplo n.º 2
0
        private MCIResult SendMCICommand(string mciCommand, int retLen)
        {
            var           mciResult = new MCIResult();
            StringBuilder ret       = null;

            if (retLen > 0)
            {
                ret = new StringBuilder(retLen);
            }

            // send the command string to the MCI
            mciResult.ReturnValue = mciSendString(mciCommand, ret, retLen, IntPtr.Zero);

            // if an error was returned, raise the event, and throw exception if appropriate
            if (mciResult.IsError())
            {
                var buffer = new StringBuilder(128);
                mciGetErrorString(mciResult.ReturnValue, buffer, 128);
                ret = buffer;
            }

            if (ret != null)
            {
                mciResult.ReturnMessage = ret.ToString();
            }
            else
            {
                mciResult.ReturnMessage = string.Empty;
            }

            return(mciResult);
        }
Exemplo n.º 3
0
        private MCIResult SendMCICommand(string mciCommand, int retLen)
        {
            var mciResult = new MCIResult();
            StringBuilder ret = null;

            if (retLen > 0)
                ret = new StringBuilder(retLen);

            // send the command string to the MCI
            mciResult.ReturnValue = mciSendString(mciCommand, ret, retLen, IntPtr.Zero);

            // if an error was returned, raise the event, and throw exception if appropriate
            if (mciResult.IsError())
            {
                var buffer = new StringBuilder(128);
                mciGetErrorString(mciResult.ReturnValue, buffer, 128);
                ret = buffer;
            }

            if (ret != null)
                mciResult.ReturnMessage = ret.ToString();
            else
                mciResult.ReturnMessage = string.Empty;

            return mciResult;
        }
Exemplo n.º 4
0
        private static MCIResult ProcessMCIRequest(MCIRequest request, IntPtr hwndHandle = new IntPtr())
        {
            var mciResult = new MCIResult();
            StringBuilder ret = null;

            if (request.retLen > 0)
                ret = new StringBuilder(request.retLen);

            // send the command string to the MCI
            mciResult.ReturnValue = mciSendString(request.MCICommand, ret, request.retLen, hwndHandle);

            // if an error was returned, raise the event, and throw exception if appropriate
            if (mciResult.IsError())
            {
                var buffer = new StringBuilder(128);
                mciGetErrorString(mciResult.ReturnValue, buffer, 128);
                ret = buffer;
            }

            if (ret != null)
                mciResult.ReturnMessage = ret.ToString();
            else
                mciResult.ReturnMessage = string.Empty;

            if (mciResult.IsError())
            {
                if (Error != null)
                    Error(new MCIErrorEventArgs(request.MCICommand, mciResult.ReturnValue, mciResult.ReturnMessage));

                if (MCIErrorsThrowExceptions)
                    throw new MediaPlayerException(request.MCICommand, mciResult.ReturnValue, mciResult.ReturnMessage);
            }

            #if DEBUG
            Console.WriteLine(string.Format("Sent at: {4}   Tick Count: {0}   Command: {1}   Result: {2} '{3}'",
                Environment.TickCount,
                request.MCICommand,
                mciResult.ReturnValue.ToString(),
                mciResult.ReturnMessage,
                request.Tick));
            #endif

            return mciResult;
        }