Understanding VirtualBox SDK ShowConsoleWindow() function

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
AdityaM
Posts: 31
Joined: 8. Nov 2016, 06:12

Understanding VirtualBox SDK ShowConsoleWindow() function

Post by AdityaM »

Hello,
I'm using SDK version 5.1, and would like to have some clarifications related to this function (ShowConsoleWindow) -

1) As from the documentation I understand that this function can be used to Activate (or deactivate) the console window on host PC. So if I don't want to display the console window (i.e. deactivate it) I can use this function as
machine ->ShowConsoleWindow(0); (by passing zero in argument, so that no window appears on foreground)
"Is my above understanding correct??"

I learnt this from the sample source code provided along with SDK (refer file attachment; tstVBoxAPIWin.cpp; function testStartVM(); line number 228)

2) If I am launching VM Process in 'headless' mode (passing sessiontype as "headless") by using LaunchVMProcess (virtualBoxSession, sessiontype, NULL, &progress) (in Sample file attached it is in 'gui' mode),
then also, is it required that I use machine ->ShowConsoleWindow(0)????

3) Before using machine ->ShowConsoleWindow(0), I tried to use canShowConsoleWindow() function, and if it returns true, only then I call machine ->ShowConsoleWindow(0) function. So canShowConsoleWindow() function takes int as argument (where the output of the function is stored), so I am assuming that if the argument returned is non-zero it means function has returned true and vice-versa. Is this understanding correct??

Thanks in advance for your support.
Regards
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: Understanding VirtualBox SDK ShowConsoleWindow() function

Post by noteirak »

IMachine::showConsoleWindow() can only be used to ask VirtualBox to activate the window of the VM, if one exists.
The winId parameter you see in the SDK reference is not an input parameter for the function to use, but an out parameter for the function (a return value if you want) which is used to tell you which Window ID can actually perform the activation, if VirtualBox cannot.

1) using showConsoleWindow(0); won't deactivate the window, since the value 0 is not used by the function.

2) if you use headless mode, there is no VM window (which is the point of headless) and therefore that function won't do anything.

3) canShowConsoleWindow() takes a boolean parameter for the return value (can it be done or not). If the value is true, you would expect showConsoleWindow() to return 0, else the window ID of the actual window needed to be activated to bring the VM window to the foreground is given. It's up to you to perform OS-specific commands to bring that window to the foreground.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply