Exception while accessing IMachine attributes

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

Exception while accessing IMachine attributes

Post by AdityaM »

Hello,
I want to read the attributes of IMachine (as specified in SDK for ver. 5.1.8 ) such as name, parent, SessionState etc. and there are well defined functions to get those attributes, such as get_name () to get the name attribute, get_Parent () to get the parent attribute etc. But when I am using some of them I am getting exceptions and for some of them it is working fine. Is there any reason behind this behaviour? Or any input which I am missing, such as machine should be in running state, maybe.
To be more specific, for example I have following piece of code -

Code: Select all

SAFEARRAY *machinesArray = NULL;
HRESULT rc;
SessionState *sstate;
MachineState *mstate;

rc = virtualBox->get_Machines(&machinesArray);
if (SUCCEEDED(rc))
{
    IMachine **machines;
    rc = SafeArrayAccessData (machinesArray, (void **) &machines);
    if (SUCCEEDED(rc))
    {
        for (ULONG i = 0; i < machinesArray->rgsabound[0].cElements; ++i)
        {
          rc = machines[i]->get_Name(&str);   //works fine
          if (SUCCEEDED(rc))
          {
            machines[i]->get_FirmwareType(ftype);   //gives exception
            machines[i]->get_Parent(parent);    //gives exception
            machines[i]->get_SessionState(sstate);   //works fine
            machines[i]->get_State(mstate);    //gives exception
            SysFreeString(str);
          }  //endof if
        }  //endof for
     }  //endof if
     SafeArrayUnaccessData (machinesArray);
}  //endof if
Thanks in advance
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: Exception while accessing IMachine attributes

Post by noteirak »

Those functions don't require specific code. Can you give the exact exception code and message please?
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
AdityaM
Posts: 31
Joined: 8. Nov 2016, 06:12

Re: Exception while accessing IMachine attributes

Post by AdityaM »

Hello,
I think there were some building issues earlier when I was trying to access these attributes, I just rebuilt the code and now I don't see any exceptions. Thanks for your response.
Regards
Post Reply