[vbox-dev] Microsoft COM C++ Display::takeScreenShot() crashes VirtualBox GUI

Nikolay Igotti Nikolay.Igotti at Sun.COM
Mon Jul 5 05:26:00 GMT 2010


     Hi Robert,

  It's recommended to read API function docs before using them (or at 
least when you hit problems :) ):

Docs say:
        Takes a screen shot of the requested size and copies it to the
         32-bpp buffer allocated by the caller and pointed to by @a address.
         A pixel consists of 4 bytes in order: B, G, R, 0.

  So bpp when you calculate buffer size must always be 32.

   Nikolay.

On 7/5/10 3:55 AM, Robert Ramsay wrote:
> Hello VirtualBox Developers,
>
> I'm testing out the C++ COM API and when I use the takeScreenShot
> method over COM the VirtualBox crashes. Please correct me if my code
> is wrong. Although, bad pointers alone shouldn't crash the VM. I'm
> aware that this is the raw COM and not the GLUE methods nor does the
> memory buffer use a COM interface (for reference counting). The source
> code is below.
>
> Thanks,
> Robert Ramsay
>
> int testTakeScreenShot(ISession *session)
> {
>      IConsole *console = NULL;
> 	IDisplay *display = NULL;
> 	unsigned long width, height, bpp;
> 	SIZE_T buffersize;
> 	BYTE* databuff;
>
> 	HRESULT rc;
> 	if (session == NULL)
> 		return 1;
> 	/* Get console object. */
>      session->get_Console(&console);
> 	console->get_Display(&display);
> 	
> 	display->GetScreenResolution(0,&width,&height,&bpp);
> 	printf("Width: %ul Height: %ul Bits Per Pixel: %ul. ", width,height,bpp);
>
> 	buffersize = width*height*bpp/8;
> 	databuff = (BYTE*)CoTaskMemAlloc(buffersize);
> 	// Test databuffer
> 	if (databuff != NULL)
> 	{
> 		rc = display->TakeScreenShot(0,databuff,width,height);
> 		if (SUCCEEDED(rc))
> 		{
> 			printf("Took a screenshot! %d\n", rc);
> 		}
> 		else
> 		{
> 			printf("Error taking screen shot! rc = 0x%x\n", rc);
> 			return rc;
> 		}
> 		CoTaskMemFree(databuff);
> 	}
> 	return 0;
> }
>
> _______________________________________________
> vbox-dev mailing list
> vbox-dev at virtualbox.org
> http://vbox.innotek.de/mailman/listinfo/vbox-dev
>    





More information about the vbox-dev mailing list