[vbox-dev] MSCOM example

aru aru.ourmail at gmail.com
Fri Jul 15 00:11:34 PDT 2011

Hi Thanks for the help, but when I tried to compile the cpp program I got
the following error:

E:\vbox\mscom\samples>g++ -Wall -I e:\vbox\mscom\include helloworld.cpp -o
In file included from helloworld.cpp:1:
e:\vbox\mscom\include/VirtualBox.h:19: warning: ignoring #pragma warning
helloworld.cpp: In function 'int main(int, char**)':
helloworld.cpp:26: warning: format '%x' expects type 'unsigned int', but
argument 2 has type 'HRESULT'
undefined reference to `_imp__CoInitialize at 4'
undefined reference to `IID_IVirtualBox'
undefined reference to `CLSID_VirtualBox'
undefined reference to `_imp__CoCreateInstance at 20'
undefined reference to `_imp__CoUninitialize at 0'
collect2: ld returned 1 exit status

It seems that the colored red are related to COM/RPC. And colored blue are
realted to VBOX

For ref: the following is the cpp I'm using
#include "VirtualBox.h"
#include <stdio.h>

int main(int argc, char *argv[])
     HRESULT rc;
      IVirtualBox *virtualBox;

             /* Initialize the COM subsystem. */

            /* Instantiate the VirtualBox root object. */
             rc = CoCreateInstance(CLSID_VirtualBox,       /* the VirtualBox
base object */
                                  NULL,                   /* no aggregation
                                   CLSCTX_LOCAL_SERVER,    /* the object
lives in a server process on this machine */
                                   IID_IVirtualBox,        /* IID of the
interface */

             if (!SUCCEEDED(rc))
                 printf("Error creating VirtualBox instance! rc = 0x%x\n",

         } while (0);

         return 0;
    printf("Hello, world\n");

    return 0;


On Thu, Jul 14, 2011 at 10:34 PM, Klaus Espenlaub <
klaus.espenlaub at oracle.com> wrote:

> On 14.07.2011 13:07, aru wrote:
>> Hi,
>> Some one please send me a mscom example to start VM or access VM.
> http://www.virtualbox.org/**browser/trunk/src/VBox/Main/**
> testcase/tstVBoxAPIWin.cpp<http://www.virtualbox.org/browser/trunk/src/VBox/Main/testcase/tstVBoxAPIWin.cpp>
> Usually it's worth having a peek at the VirtualBox sources - if everything
> else fails there's VBoxManage, which uses pretty much all interfaces and
> methods.
> There are only very few places in VirtualBox where it's an option to take
> shortcuts, so generally all the VirtualBox code goes through the API as
> well.
> Klaus
>> Thanks
>> Arun
> ______________________________**_________________
> vbox-dev mailing list
> vbox-dev at virtualbox.org
> http://vbox.innotek.de/**mailman/listinfo/vbox-dev<http://vbox.innotek.de/mailman/listinfo/vbox-dev>

Fight back spam! Download the Blue Frog.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.virtualbox.org/pipermail/vbox-dev/attachments/20110715/08ad8124/attachment-0001.html 

More information about the vbox-dev mailing list