Using MSCOM API in C#

Discussions related to using VirtualBox on Windows hosts.

Using MSCOM API in C#

Postby animus » 4. Nov 2010, 20:19

I've been trying to compile a simple app to pause/unpause a VM based on my Laptop's accelerometer. My laptop parks the HDD when the acceleration exceeds a threshold, and if it stays parked for some time, VBox tends to make the VHD controller stop responding, wreaking havoc. So, I'm making an app that monitors this acceleration and pauses the VM when the HDD is parked.

However, when I try to get it to actually interact with a VM, I get an error on launch:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: Retrieving the COM class factory for component with CLSID {3C02F46D-C9D2-4F11-A384-53F0CF917214} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).


This occurs at this portion of the code:

Code: Select all   Expand viewCollapse view
Session Sess = new Session();


I've tried using an ISESSION instead, but I have no way to initialize it (and the function refuses to take it uninitialized), and casting is useless as well. Any Idea what to do?
animus
 
Posts: 1
Joined: 4. Nov 2010, 19:55
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Linux

Re: Using MSCOM API in C#

Postby Duke » 7. Nov 2010, 23:21

I'm having the same problem here.
i suppose the issue is caused by some sort of impatibility or misconfiguration as i'm running Virtualbox on a 64 bit system while the tpl seems to be 32 bit.

i'm not sure this is the cause and anyway i have not ofund a solution yet :(
any progress from you?
Duke
 
Posts: 9
Joined: 7. Nov 2010, 23:16
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Windows server 2008 R2

Re: Using MSCOM API in C#

Postby Duke » 8. Nov 2010, 11:36

I confirm that on Windows XP (32 Bit of course) the exact same code works perfectly

Session s = new Session();

or

Session s = new Session();

doesn't thows any exception and instead creates a valid session i can inspect and use normally.

this enforce my supposition that there is something wrong in the registration of the VBoxC.dll that's apparently is the one that contains the factory for the Session object, or in the TPL defintion when the host system is 64 bit.

that's two times strange if you consider that the code

var vbox = new VirtualBoxClass();

works well both on 64 and 32 bit windows OS... and it is exposed by the same TPL.

In fact it's factory appears to be contained in a different file (VBoxsvc.exe), so this may be the difference...

Unfortunately i'm not a great expert in .NET-COM interaction and at the moment i don't know how to solve this issue.

I'm also considering that the otehr frontends works well on my Windows 7 64 bits, so there should be a way to make this work... obviously the other frontends are not .NET so it is probably all the marshalling-unmarshalling things that becomes brokens somewhere :(

that's very frustrating :(
Duke
 
Posts: 9
Joined: 7. Nov 2010, 23:16
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Windows server 2008 R2

Re: Using MSCOM API in C#

Postby amirt » 8. Nov 2010, 21:38

Hi,

this issue is related to 64/32 bit.

compile your code for X64 to solve this.

this happens because on 64bit platform vbox fails to register the 32bit version of the Session object(i dont know why)
however the VirtualBox object exists under both 32/64 bit.

comfirmed fixing this issue today with Win7 64bit / VS2010.

Amir.
amirt
 
Posts: 1
Joined: 8. Nov 2010, 21:34
Primary OS: MS Windows 7
VBox Version: OSE self-compiled
Guest OSses: Linux

Re: Using MSCOM API in C#

Postby Duke » 9. Nov 2010, 01:43

Amirt: THANKS A LOT!
that's really solved the issue!

i had another little fight with the test project (i had to set in the host tab of the test setting to run the test in 64 bit too) but that was a lot easier knowing how to solve the other issue for wich you have provided the solution!

thanks again!!!
now i'm again happy :)
Duke
 
Posts: 9
Joined: 7. Nov 2010, 23:16
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Windows server 2008 R2


Return to VirtualBox on Windows Hosts

Who is online

Users browsing this forum: Google [Bot], socratis and 24 guests