{"id":391,"date":"2013-03-11T16:31:26","date_gmt":"2013-03-11T21:31:26","guid":{"rendered":"http:\/\/www.virtualroadside.com\/blog\/?p=391"},"modified":"2013-03-11T16:31:58","modified_gmt":"2013-03-11T21:31:58","slug":"virtualkd-2-8-with-virtualbox-4-2","status":"publish","type":"post","link":"http:\/\/www.virtualroadside.com\/blog\/index.php\/2013\/03\/11\/virtualkd-2-8-with-virtualbox-4-2\/","title":{"rendered":"VirtualKD 2.8 with VirtualBox 4.2"},"content":{"rendered":"<p>If you try to install VirtualKD 2.8 on VirtualBox 4.2.x, you get an error similar to this:<\/p>\n<blockquote><p>\nUnable to cast COM object of type &#8216;VirtualBox.VirtualBoxClass&#8217; to interface type &#8216;VirtualBox.IVirtualBox&#8217;. This operation failed because the QueryInterface call on the COM component for the interface with IID &#8216;{&#8230;}&#8217; failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).\n<\/p><\/blockquote>\n<p>It turns out it&#8217;s a pretty easy thing to fix. The Interop.VirtualBox.dll distributed with VirtualKD is built for the 4.1 VirtualBox interface, so you just have to rebuild it for your version of VirtualBox. Create a C# project, and paste the following code into the Program.cs file to build a new Interop.VirtualBox.dll for 4.2.x. <\/p>\n<pre>\r\nusing System;\r\nusing System.Reflection;\r\nusing System.Reflection.Emit;\r\nusing System.Runtime.InteropServices;\r\n\r\nnamespace ConvertTypeLibToAssembly\r\n{\r\n    public class App\r\n    {\r\n        private enum RegKind\r\n        {\r\n            RegKind_Default = 0,\r\n            RegKind_Register = 1,\r\n            RegKind_None = 2\r\n        }\r\n    \r\n        [ DllImport( \"oleaut32.dll\", CharSet = CharSet.Unicode, PreserveSig = false )]\r\n        private static extern void LoadTypeLibEx( String strTypeLibName, RegKind regKind, \r\n            [ MarshalAs( UnmanagedType.Interface )] out Object typeLib );\r\n        \r\n        public static void Main()\r\n        {\r\n            Object typeLib;\r\n            LoadTypeLibEx( @\"C:\\Program Files\\Oracle\\VirtualBox\\VBoxC.dll\", RegKind.RegKind_None, out typeLib ); \r\n            \r\n            if( typeLib == null )\r\n            {\r\n                Console.WriteLine( \"LoadTypeLibEx failed.\" );\r\n                return;\r\n            }\r\n                \r\n            TypeLibConverter converter = new TypeLibConverter();\r\n            ConversionEventHandler eventHandler = new ConversionEventHandler();\r\n            \/\/AssemblyBuilder asm = converter.ConvertTypeLibToAssembly( typeLib, \"Interop.Virtualbox.dll\", 0, eventHandler, null, null, null, null );\r\n            AssemblyBuilder asm = converter.ConvertTypeLibToAssembly(typeLib, \"Interop.VirtualBox.dll\", TypeLibImporterFlags.SafeArrayAsSystemArray, eventHandler, null, null, \"VirtualBox\", null); \/\/using assembly name \"VirtualBox\" and SafeArrayAsSystemArray to be compatible to VisualStudio-Generated Interop-Assembly\r\n\r\n            asm.Save(\"Interop.Virtualbox.dll\");\r\n        }\r\n    }\r\n\r\n    public class ConversionEventHandler : ITypeLibImporterNotifySink\r\n    {\r\n        public void ReportEvent( ImporterEventKind eventKind, int eventCode, string eventMsg )\r\n        {\r\n            \/\/ handle warning event here...\r\n        }\r\n        \r\n        public Assembly ResolveRef( object typeLib )\r\n        {\r\n            \/\/ resolve reference here and return a correct assembly...\r\n            return null; \r\n        }    \r\n    }\r\n}\r\n\r\n<\/pre>\n<p>Some of this code was grabbed from <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.runtime.interopservices.typelibconverter.converttypelibtoassembly%28v=vs.71%29.aspx\">MSDN<\/a>, and a single line was grabbed from <a href=\"http:\/\/code.google.com\/p\/virtualboxservice\/source\/browse\/VirtualBoxService\/InstallGui\/VirtualBoxComInteropAssemblyBuilder.cs?r=3bcc65343bcc6f1919b228dd52b257899d9bd5c2\">VirtualBoxService<\/a>. As the latter is GPL, this code may be GPL. I don&#8217;t claim any rights to it. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you try to install VirtualKD 2.8 on VirtualBox 4.2.x, you get an error similar to this: Unable to cast COM object of type &#8216;VirtualBox.VirtualBoxClass&#8217; to interface type &#8216;VirtualBox.IVirtualBox&#8217;. This operation failed because the QueryInterface call on the COM component for the interface with IID &#8216;{&#8230;}&#8217; failed due to the following error: No such interface [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,47,52,37],"tags":[],"_links":{"self":[{"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/391"}],"collection":[{"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=391"}],"version-history":[{"count":3,"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/391\/revisions"}],"predecessor-version":[{"id":394,"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/391\/revisions\/394"}],"wp:attachment":[{"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=391"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}