<html><head><title>Re[2]: [vbox-dev] MSCOM example</title>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
</head>
<body>
<span style=" font-family:'Courier New'; font-size: 9pt;">Hi.<br>
<br>
You also need to link with the typelib implementation from ...\mscom\lib directory.<br>
<br>
</span><table>
<tr>
<td width=10 bgcolor= #0000ff><br>
</td>
<td width=1015><span style=" font-family:'courier new'; font-size: 9pt;">Hi Thanks for the help, but when I tried to compile the cpp program I got the following error:<br>
<br>
E:\vbox\mscom\samples>g++ -Wall -I e:\vbox\mscom\include helloworld.cpp -o helloworld.exe<br>
In file included from helloworld.cpp:1:<br>
e:\vbox\mscom\include/VirtualBox.h:19: warning: ignoring #pragma warning<br>
helloworld.cpp: In function 'int main(int, char**)':<br>
helloworld.cpp:26: warning: format '%x' expects type 'unsigned int', but argument 2 has type 'HRESULT'<br>
C:\Users\AKANTH~1.ADO\AppData\Local\Temp\ccYXyN0g.o:helloworld.cpp:(.text+0x1e): <span style=" background-color: #ff0000;">undefined reference to `_imp__CoInitialize@4'<br>
</span>C:\Users\AKANTH~1.ADO\AppData\Local\Temp\ccYXyN0g.o:helloworld.cpp:(.text+0x32): <span style=" background-color: #3366ff;">undefined reference to `IID_IVirtualBox'<br>
</span>C:\Users\AKANTH~1.ADO\AppData\Local\Temp\ccYXyN0g.o:helloworld.cpp:(.text+0x49): <span style=" background-color: #3366ff;">undefined reference to `CLSID_VirtualBox'<br>
</span>C:\Users\AKANTH~1.ADO\AppData\Local\Temp\ccYXyN0g.o:helloworld.cpp:(.text+0x4e): <span style=" background-color: #3366ff;">undefined reference to `_imp__CoCreateInstance@20'<br>
</span>C:\Users\AKANTH~1.ADO\AppData\Local\Temp\ccYXyN0g.o:helloworld.cpp:(.text+0x74): <span style=" background-color: #ff0000;">undefined reference to `_imp__CoUninitialize@0'<br>
</span>collect2: ld returned 1 exit status<br>
<br>
It seems that the colored red are related to COM/RPC. And colored blue are realted to VBOX<br>
<br>
For ref: the following is the cpp I'm using<br>
-----------------------------------------------------------------------------------------------------------------------------------------<br>
#include "VirtualBox.h"<br>
#include <stdio.h><br>
<br>
int main(int argc, char *argv[])<br>
{<br>
     HRESULT rc;<br>
      IVirtualBox *virtualBox;<br>
<br>
      do<br>
         {<br>
             /* Initialize the COM subsystem. */<br>
             CoInitialize(NULL);<br>
     <br>
            /* Instantiate the VirtualBox root object. */<br>
             rc = CoCreateInstance(CLSID_VirtualBox,       /* the VirtualBox base object */<br>
                                  NULL,                   /* no aggregation */<br>
                                   CLSCTX_LOCAL_SERVER,    /* the object lives in a server process on this machine */<br>
                                   IID_IVirtualBox,        /* IID of the interface */<br>
                                   (void**)&virtualBox);<br>
     <br>
             if (!SUCCEEDED(rc))<br>
             {<br>
                 printf("Error creating VirtualBox instance! rc = 0x%x\n", rc);<br>
                 break;<br>
             }<br>
     <br>
           <br>
         } while (0);<br>
     <br>
         CoUninitialize();<br>
         return 0;<br>
    printf("Hello, world\n");<br>
    <br>
    return 0;<br>
}<br>
-------------------------------------------------------------------------------------------------------------------------------------------------<br>
<br>
Thanks<br>
Arun  <br>
<br>
On Thu, Jul 14, 2011 at 10:34 PM, Klaus Espenlaub <<a href="mailto:klaus.espenlaub@oracle.com">klaus.espenlaub@oracle.com</a>> wrote:<br>
On 14.07.2011 13:07, aru wrote:<br>
Hi,<br>
<br>
Some one please send me a mscom example to start VM or access VM.<br>
<a href="http://www.virtualbox.org/browser/trunk/src/VBox/Main/testcase/tstVBoxAPIWin.cpp">http://www.virtualbox.org/browser/trunk/src/VBox/Main/testcase/tstVBoxAPIWin.cpp</a><br>
<br>
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.<br>
<br>
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.<br>
<br>
Klaus<br>
<br>
<br>
Thanks<br>
Arun</td>
</tr>
</table>
<br><br>
<br>
<br>
<span style=" font-family:'arial'; color: #c0c0c0;"><i>-- <br>
Bye.                                    With best regards,<br>
                                        Konstantin Vlasov.</body>