Code: Select all
int getScreenshot(Image* pImg)
{
nsresult rc;
nsCOMPtr<IConsole> console = nsnull;
nsCOMPtr<IDisplay> display = nsnull;
PRUint32 width=0, height=0, bpp=0, dataSize=0;
PRInt32 xOrigin=0, yOrigin=0;
PRUint8* img=0;
//Guest Session Status
PRUint32 guestSess;
//get the console
rc = m_session->GetConsole(getter_AddRefs(console));
XPCOM_ERR_CHK(rc, "Error taking screenshot - couldn't get console");
//get the display
rc = console->GetDisplay(getter_AddRefs(display));
XPCOM_ERR_CHK(rc, "Error taking screenshot - couldn't get display");
//get the width and height of the display
rc = display->GetScreenResolution(0, &width, &height, &bpp, &xOrigin, &yOrigin, &guestSess);
XPCOM_ERR_CHK(rc, "Error taking screenshot - couldn't get resolution");
//take the screenshot
//ERROR OCCURS HERE
rc = display->TakeScreenShotToArray(0, width, height, 4, &dataSize, &img);
XPCOM_ERR_CHK(rc, "Error taking screenshot - couldn't take VM screenshot rc=%#x");
//create the Image from the data
*pImg = Image(img, width, height);
//free local objects
console = nsnull;
display = nsnull;
return 0;
}
agill6