TakeScreenShotToArray Not Implemented (0x80004001)

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
agill6
Posts: 5
Joined: 9. Feb 2016, 19:33

TakeScreenShotToArray Not Implemented (0x80004001)

Post by agill6 »

I am currently running VirtualBox 5.0.16 with the 5.0.16 SDK on Linux Ubuntu. I am developing using the XPCOM and C++ as the development language. I am trying to make use of the TakeScreenShotToArray function of Display to save a screenshot's data to be processed later. The code compiles cleanly, but the TakeScreenShotToArray function returns the NOT IMPLEMENTED error code rc=0x80004001. Here is my function's code:

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;
}

I am not sure what is causing this error.The GetScreenResolution function seems to work just fine, otherwise I would think there was something wrong with my console or session objects. Any insight is greatly appreciated.

agill6
Last edited by agill6 on 23. Mar 2016, 16:20, edited 1 time in total.
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: TakeScreenShotToArray Not Implemented

Post by noteirak »

You are not using a shared lock for the session. I don't see anything in your code sample for it, and that would typically be the error returned in that case.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
agill6
Posts: 5
Joined: 9. Feb 2016, 19:33

Re: TakeScreenShotToArray Not Implemented (0x80004001)

Post by agill6 »

Ah, That looks like it may be the problem. I do establish a shared lock in earlier parts of the code, but it may have been broken by the time it hits this code. In this case, is it normal that GetScreenResolution works anyway? I will attempt to fix the issue and reply with the results.

agill6
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: TakeScreenShotToArray Not Implemented (0x80004001)

Post by noteirak »

yes I would expect getscreenresolution to work - it is a read-only operation that does not require a lock AFAIK, while taking a screenshot is an active operation on the console (and so access to the VM process) that require a session lock
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
agill6
Posts: 5
Joined: 9. Feb 2016, 19:33

Re: TakeScreenShotToArray Not Implemented (0x80004001)

Post by agill6 »

Hi All,

So it turns out the problem was not a shared lock and was with the TakeScreenShotToArray function call itself. Although the code will compile using an integer for the BitmapFormat parameter, it requires use of the BitmapFormat declaration or else it will return as "not implemented".

I changed this line:

Code: Select all

  rc = display->TakeScreenShotToArray(0, width, height, 4, &dataSize, &img); 
To this line:

Code: Select all

  rc = display->TakeScreenShotToArray(0, width, height, BitmapFormat::RGBA, &dataSize, &img); 
And now it works!

This seemed strange to me since BitmapFormat looks like it is just an enumeration, but it works if you use the definition in the second line. Just thought I would post the solution in case anyone else ran into this problem.

Thanks!

agill6
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: TakeScreenShotToArray Not Implemented (0x80004001)

Post by noteirak »

Thank you for the follow up!
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply