Page 1 of 1

Basic question about using the API

Posted: 8. Aug 2013, 15:56
by bobby4078
Hello,

I would like to use the API to do simple progaming things like an executable that start a machine for exemple. I would like to do that in C++. The problem is that I don't know how to set it up.

I've download the sources from svn :

Code: Select all

svn co http://www.virtualbox.org/svn/vbox/trunk vbox
But now what should I do ?

I don't even know if what I downloaded from SVN is the API actually...

So what I would like to be able is to write a simple program of just a few lines like :

Code: Select all

IMachine machine = ...;
String name = machine.getName();
But how do I compile it in a simply way ?

Thanks !

Re: Basic question about using the API

Posted: 8. Aug 2013, 16:14
by mpack
Download the SDK from the downloads area. What you downloaded from SVN was the application source code, which is probably not what you want (that's like downloading the source code of the gcc compiler because you want to learn how to write C++).

Re: Basic question about using the API

Posted: 8. Aug 2013, 16:35
by bobby4078
Oh I didn't see that link :D

Ok now, how I use that ? I see in the samples folder tstVBoxAPIWin.cpp. I would like to compile it to test it. But before I suppose that I have to install the SKD right ? In the installer folder I see python script. Do I just have to run the python script ?

Re: Basic question about using the API

Posted: 8. Aug 2013, 17:22
by mpack
Sorry, I don't use the SDK. You asked if the source codes you downloaded were what you needed, and I'm afraid my answer to that question pretty much exhausted my knowledge of the subject.

Re: Basic question about using the API

Posted: 8. Aug 2013, 17:44
by noteirak
Under the folder <SKD_ROOT>\bindings\xpcom\include, you'll normally find every include you need. The main headers you're interested into are the VBoxCAPI_vX_X.h files.
You should also read in its entierty the SDKRef.pdf file located in the docs dir of the SDK

Re: Basic question about using the API

Posted: 9. Aug 2013, 13:00
by bobby4078
Thanks. I still can't compile. I try to compile with g++. I created a test.cpp file, with this simple code :

Code: Select all

#include <iostream>
#include "VirtualBox_XPCOM.h"

using namespace std;

int main(){
	
	cout << "Test";
	
	return 0;
	
}
I just include a header. I did a make file so I can include all the .h :

Code: Select all

INC = 	-I../include/ \
		-I../include/ipcd \
		-I../include/nsprub \
		-I../include/string \
		-I../include/xpcom

Test:
	g++ $(INC) test.cpp -o TesT
But I still have a lot of error messages. What is wrong with it ?

Re: Basic question about using the API

Posted: 9. Aug 2013, 13:47
by bobby4078
Ok I found the problem, I was trying to use XPCom instead of MSCom. Now compilation seems to be better if I try to compile the sample file tstVBoxAPIWin.cpp. But I still have errors :

Code: Select all

D:\DOCUME~1\BOBBY\LOCALS~1\Temp\ccrUxk1M.o:tstVBoxAPIWin.cpp:(.text+0x42a): undefined reference to `_imp__SafeArrayAccessData@8'
D:\DOCUME~1\BOBBY\LOCALS~1\Temp\ccrUxk1M.o:tstVBoxAPIWin.cpp:(.text+0x42a): udefined reference to `_imp__SysFreeString@4'
D:\DOCUME~1\BOBBY\LOCALS~1\Temp\ccrUxk1M.o:tstVBoxAPIWin.cpp:(.text+0x42a): undefined reference to `_imp__SafeArrayUnaccessData@4'
D:\DOCUME~1\BOBBY\LOCALS~1\Temp\ccrUxk1M.o:tstVBoxAPIWin.cpp:(.text+0x42a): undefined reference to `_imp__SafeArrayDestroy@4'
D:\DOCUME~1\BOBBY\LOCALS~1\Temp\ccrUxk1M.o:tstVBoxAPIWin.cpp:(.text+0x42a): undefined reference to `_imp__SysAllocString@4'
D:\DOCUME~1\BOBBY\LOCALS~1\Temp\ccrUxk1M.o:tstVBoxAPIWin.cpp:(.text+0x42a): undefined reference to `_imp__GetErrorInfo@8'
D:\DOCUME~1\BOBBY\LOCALS~1\Temp\ccrUxk1M.o:tstVBoxAPIWin.cpp:(.text+0x42a): undefined reference to `_imp__SysFreeString@4'.

...etc...
I got these errors when I run that compilation command :

Code: Select all

g++ -I../include/ tstVBoxAPIWin.cpp
So It seems that the problem is comming from the Win32 API in functions like SafeArrayAccessData(), SysFreeString(), SafeArrayUnaccessData() etc. But I don't know what to do to solve it ?

Thanks

Re: Basic question about using the API

Posted: 9. Aug 2013, 13:55
by mpack
SafeArrayXXXXX etc are not strictly part of the Win32 API. Trying linking in OleAut32.lib. Google for any remaining missing functions, note which library is required.

Re: Basic question about using the API

Posted: 9. Aug 2013, 17:00
by bobby4078
Yes I add this to my makefile :

Code: Select all

-loleaut32 -lOle32
and it's a lot better.
Now I just miss some lib that I don't find, here are the functions :
  • IID_ISession
  • CLSID_Session
  • IID_IVirtualBox
  • CLSID_VirtualBox
Where can I find the lib for these functions ?

Re: Basic question about using the API

Posted: 9. Aug 2013, 17:12
by mpack
Some of those look like VirtualBox SDK specifics, (VirtualBox GUIDs) so you'll need to consult the SDK docs on that. I expect they'll be declared in a header file.

Re: Basic question about using the API

Posted: 24. Oct 2013, 04:52
by rousseauhk
>>bobby4078

If you are trying to build on windows, by far the easiest way to get started is to download the free Visual Studio Express/Desktop:

* Download/install VSE Desktop 2012
* Create a new empty C++ project (remove any auto-generated files)
* Copy the following into your project
sdk\bindings\mscom\samples\tstVBoxAPIWin.cpp
sdk\bindings\mscom\lib\VirtualBox_i.c
sdk\bindings\mscom\include\VirtualBox.h
* Compile & Run

This should work for you out of the box (just make sure that the SDK version is the same as the VirtualBox version you have installed e.g. don't mix 4.2 SDK with 4.3 VirtualBox).