[vbox-dev] How to get screenshot of a guest OS using COM api?

Grigory eyeofhell at me.com
Thu Sep 17 00:43:36 PDT 2009


I have tried to allocate buffer of requested size - virtualbox just  
crashes on takescreenshot(). It seems I must be in same process to  
call it, so it can be used only inside a complete GUI? Maybe it is  
possible to use get/setframebuffer - but how? :)

Sent from my iPhone

On 16.09.2009, at 21:56, Klaus Espenlaub <Klaus.Espenlaub at Sun.COM>  
wrote:

> Grigory Petrov schrieb:
>> Hello.
>> I'm using VirtualBox to automate old DOS program and need to takes  
>> screenshots of guest OS in order to manipulate a program correctly.  
>> I have tried the following test code:
>> void main( void )
>> {
>>  ::CoInitialize( 0 );
>>  IVirtualBox* poVbox = 0;
>>  ::CoCreateInstance( CLSID_VirtualBox, 0, CLSCTX_ALL,  
>> IID_IVirtualBox, (void**)& poVbox );
>>  SAFEARRAY* poVmList = 0;
>>  poVbox->get_Machines( & poVmList );
>>    IMachine** ppoVmArray = 0;
>>  ::SafeArrayAccessData( poVmList, (void**)& ppoVmArray );
>>  BSTR oVmId;
>>  (* ppoVmArray)->get_Id( & oVmId );
>>  ISession* poSession = 0;
>>  HRESULT hRet = ::CoCreateInstance( CLSID_Session, 0, CLSCTX_ALL,
>>    IID_ISession, (void**)& poSession );
>>  IProgress* poProgress = 0;
>>  BSTR oEnvir = ::SysAllocString( L"" );
>>    hRet = poVbox->OpenRemoteSession( poSession,  
>> oVmId, ::SysAllocString( L"gui" ), oEnvir, & poProgress );
>>  // Wait resonable time for VM to start and to display something.
>>  ::Sleep( 10000 );
>>  IConsole* poConsole = 0;
>>  hRet = poSession->get_Console( & poConsole );
>>  IDisplay* poDisplay = 0;
>>  hRet = poConsole->get_Display( & poDisplay );
>>    UINT32 anMem[ 100 ] = { 0 };
>>  hRet = poDisplay->TakeScreenShot( (BYTE*)anMem, 10, 10 );
>>  assert( SUCCEEDED( hRet ) );
>> }
>> All works, VirtualBox starts and loads guest OS, but after calling  
>> TakeScreenShow() it returns E_NOTIMPL :(. Does anyone know what can  
>> i do? Maybe i need to use other API functions, get screen buffer,  
>> register for updates notifications or something? Host OS is windows  
>> XP SP3, latest VirtualBox and SDK from site. I will be very glad if  
>> someone can share an working example on how to take an screenshot /  
>> image of guest OS desktop, that will help a lot! Or maybe it's some  
>> error in my code?
>
> The error says it all. The code can't deal with scaling, and as you  
> request a 10x10 pixel screenshot that'll fail. Make sure you request  
> the width and height of the framebuffer (and have enough buffer size  
> available for that). An example is in the GUI code, but remember  
> that this uses different API wrappers so the calling conventions are  
> a bit different than the normal (xp)com API calls.
>
> Klaus




More information about the vbox-dev mailing list