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

Robert Ramsay robert.alan.ramsay at gmail.com
Sun Jul 4 23:55:39 GMT 2010


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




More information about the vbox-dev mailing list