Hi,<br>I have a problem taking screenshot using C#, when I call TakeScreenshot() it crashes the VM and i catch the error:<br>e.Message = "The remote procedure call failed. (Exception from HRESULT: 0x800706BE)"<br>
<br>I'm guessing the error message is due to the fact that the VM crashed and the app lost the connection? The screen res is set correctly and enough memory is allocated.<br><br>Someone else had the same problem in C++ here:<br>
<a href="http://forums.virtualbox.org/viewtopic.php?f=1&t=38431&p=180231&hilit=takeScreenShot#p180231">http://forums.virtualbox.org/viewtopic.php?f=1&t=38431&p=180231&hilit=takeScreenShot#p180231</a><br>
<br>I'm using VirtualBox-4.0.4-70112-Win and win 7 in the VM.<br><br>Can anyone here help me and maybe have any suggestions on how to solve this?<br><br>Anyway, here is my code:<br><br>.................<br><br>                Session session;<br>
                IMachine machine;        <br>                VirtualBox.VirtualBox vb;<br>                uint screenWidth;<br>                uint screenHeight;<br>                uint bitsPerPixel;<br>                uint bufferSize;<br>
                Byte[] screenShotBuffer;<br><br><br>                vb = new VirtualBox.VirtualBox();<br>                machine = vb.FindMachine("MyMachine");<br>                if (machine.State == MachineState.MachineState_PoweredOff || machine.State == MachineState.MachineState_Aborted)<br>
                {<br>                    IProgress myProgress = machine.LaunchVMProcess(session, "gui", "");<br>                    myProgress.WaitForCompletion(-1);<br>                }<br>                else<br>
                {<br>                    machine.LockMachine(session, LockType.LockType_Shared);<br>                }<br><br>                getScreenResolution(out screenWidth, out screenHeight, out bitsPerPixel);<br>                bufferSize = screenWidth * screenHeight * 4;<br>
                screenShotBuffer = new Byte[bufferSize];<br><br>                bmp = takeScreenShot(0);<br><br>                ..............<br><br>       public Bitmap takeScreenShot(uint monitor)<br>        {<br>            if (screenShotBuffer == null)<br>
                return null;<br><br>            try<br>            {<br>                Bitmap bmp;<br>                unsafe <br>                {<br>                    fixed (byte* ptr = screenShotBuffer) <br>                    {<br>
                        session.Console.Display.TakeScreenShot(monitor, ref screenShotBuffer[0], screenWidth, screenHeight);   <b style="background-color: rgb(255, 0, 0);">// <-- Crashes VM here</b><br>                        bmp = new Bitmap((int)screenWidth, (int)screenHeight, (int)screenWidth * 4, PixelFormat.Format24bppRgb, new IntPtr(ptr));<br>
                    } <br>                } <br>                return bmp;<br>            }<br>            catch (Exception e)<br>            {<br>                logger.Error("Couldn't take screenshot: " + e.Message);<br>
            }<br>            return null;<br>        }<br><br><br>........................<br><br>        private void getScreenResolution(out uint width, out uint height, out uint bitsPerPixel)<br>        {<br>            try<br>
            {<br>                session.Console.Display.GetScreenResolution(0, out width, out height, out bitsPerPixel);<br>            }<br>            catch (Exception e)<br>            {<br>                logger.Error("Couldn't get screen resolution: " + e.Message);<br>
                width = 0;<br>                height = 0;<br>                bitsPerPixel = 0;<br>            }<br>        }<br><br>Thanks,<br>Magnus<br>