Hi,
I have a problem taking screenshot using C#, when I call TakeScreenshot() it
crashes the VM and i catch the error:
e.Message = "The remote procedure call failed. (Exception from HRESULT:
0x800706BE)"

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.

Someone else had the same problem in C++ here:
http://forums.virtualbox.org/viewtopic.php?f=1&t=38431&p=180231&hilit=takeScreenShot#p180231

I'm using VirtualBox-4.0.4-70112-Win and win 7 in the VM.

Can anyone here help me and maybe have any suggestions on how to solve this?

Anyway, here is my code:

.................

                Session session;
                IMachine machine;
                VirtualBox.VirtualBox vb;
                uint screenWidth;
                uint screenHeight;
                uint bitsPerPixel;
                uint bufferSize;
                Byte[] screenShotBuffer;


                vb = new VirtualBox.VirtualBox();
                machine = vb.FindMachine("MyMachine");
                if (machine.State == MachineState.MachineState_PoweredOff ||
machine.State == MachineState.MachineState_Aborted)
                {
                    IProgress myProgress = machine.LaunchVMProcess(session,
"gui", "");
                    myProgress.WaitForCompletion(-1);
                }
                else
                {
                    machine.LockMachine(session, LockType.LockType_Shared);
                }

                getScreenResolution(out screenWidth, out screenHeight, out
bitsPerPixel);
                bufferSize = screenWidth * screenHeight * 4;
                screenShotBuffer = new Byte[bufferSize];

                bmp = takeScreenShot(0);

                ..............

       public Bitmap takeScreenShot(uint monitor)
        {
            if (screenShotBuffer == null)
                return null;

            try
            {
                Bitmap bmp;
                unsafe
                {
                    fixed (byte* ptr = screenShotBuffer)
                    {
                        session.Console.Display.TakeScreenShot(monitor, ref
screenShotBuffer[0], screenWidth, screenHeight);   *// <-- Crashes VM here*
                        bmp = new Bitmap((int)screenWidth,
(int)screenHeight, (int)screenWidth * 4, PixelFormat.Format24bppRgb, new
IntPtr(ptr));
                    }
                }
                return bmp;
            }
            catch (Exception e)
            {
                logger.Error("Couldn't take screenshot: " + e.Message);
            }
            return null;
        }


........................

        private void getScreenResolution(out uint width, out uint height,
out uint bitsPerPixel)
        {
            try
            {
                session.Console.Display.GetScreenResolution(0, out width,
out height, out bitsPerPixel);
            }
            catch (Exception e)
            {
                logger.Error("Couldn't get screen resolution: " +
e.Message);
                width = 0;
                height = 0;
                bitsPerPixel = 0;
            }
        }

Thanks,
Magnus
_______________________________________________
vbox-dev mailing list
[email protected]
http://vbox.innotek.de/mailman/listinfo/vbox-dev

Reply via email to