{"id":1147,"date":"2011-10-19T09:26:43","date_gmt":"2011-10-19T07:26:43","guid":{"rendered":"http:\/\/mariusbancila.ro\/blog\/?p=1147"},"modified":"2012-11-23T12:57:34","modified_gmt":"2012-11-23T10:57:34","slug":"accessing-64-bit-native-com-server-from-a-managed-client","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/","title":{"rendered":"Accessing 64-bit Native COM Server From a Managed Client"},"content":{"rendered":"<p>Not long ago I ran into a COM interop problem that was a bit tricky to fix. So I&#8217;m sharing the problem and the solution here in case others encounter the same problem.<\/p>\n<p>I had this native in-proc COM server that initially was built only for x86. It was used in a native MFC application as well as a C# Windows Forms application, where it was added as a COM reference. Both worked nicely. But then I needed to port the MFC app to the x64 platform, so I had to do the same with the in-proc COM server. They both worked correctly, but the managed app, which had to be available also both as 64-bit and 32-bit (even on 64-bit machines), was broken. Eventually I traced the problem to some COM method calls which were a bit atypical, because the arguments to the methods were not COM &#8220;native&#8221; types, but custom structures.<\/p>\n<p>These structures looked like this:<\/p>\n<pre class=\"cpp\" name=\"code\">\r\n[uuid(6F13C84D-0E01-48cd-BFD4-F7071A32B49F)] struct S\r\n{\r\n      long a;\r\n      BSTR b;\r\n      long c;\r\n      BSTR d;\r\n      long e;\r\n      BSTR f;\r\n      BSTR g;\r\n      BSTR h;\r\n      BSTR i;\r\n      long j;\r\n      BSTR k;\r\n      long l;\r\n      BSTR m;\r\n      long n;\r\n};\r\n<\/pre>\n<p>and the COM method signature:<\/p>\n<pre class=\"cpp\" name=\"code\">\r\n[id(42)] HRESULT GetListOfStructs(SAFEARRAY(struct S)* arrRes);\r\n<\/pre>\n<p>When you add a COM reference to a .NET assembly, Visual Studio runs <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/tt0cf3sx.aspx\">tlbimp.exe<\/a> to generate a .NET assembly with equivalent definitions to the type definitions found in the COM type library. This interop assembly is used to access the COM server. It contains Runtime Callable Wrappers that bridge the two worlds together. By default, the interop assembly, generated in the project&#8217;s output folder, is called <strong>Interop.&lt;comname&gt;Lib.dll<\/strong>. For instance if the COM server is called NativeCOMServer, the interop assembly is called Interop.NativeCOMServerLib.dll.<\/p>\n<p>The wrapper that was generated in the interop assembly had the following signature for the aforementioned method:<\/p>\n<pre class=\"cpp\" name=\"code\">\r\n[DispId(42)]\r\nvoid GetListOfStructs(ref Array arrRes);\r\n<\/pre>\n<p>and therefore used like this:<\/p>\n<pre class=\"cpp\" name=\"code\">\r\nSystem.Array result = null;\r\nobj.GetListOfStructs(ref result);\r\n<\/pre>\n<p>The call was performed correctly, the native code was executing, but as soon as it was returning an access violation exception was occurring. Thanks to <a href=\"http:\/\/stackoverflow.com\/questions\/7517474\/accessing-64-bit-com-server-from-managed-assembly-fails\">Hans Passant<\/a> I figured the problem was rooted in the way Visual Studio generates the interop assembly. The generated RCW didn&#8217;t know how to handle the custom structure correctly. Probably different padding on the two sides generated the access violation. <\/p>\n<p>The trick was to generate the interop assembly directly, as a custom build step in the COM server project, and include it as an assembly reference in the managed project. Here are the commands for the custom build (must to make sure you have the correct path to the 32-bit and the 64-bit version of tlbimp.exe):<\/p>\n<pre>\r\n<pathto32bittool>\\TlbImp.exe $(TargetPath) \/out:$(TargetDir)\\NativeCOMLib.Interop.dll \/primary  \/keyfile:mykey.snk \/machine:x86\r\n\r\n<pathto64bittool>\\TlbImp.exe $(TargetPath) \/out:$(TargetDir)\\NativeCOMLib.Interop.dll \/primary  \/keyfile:mykey.snk \/machine:x64\r\n<\/pre>\n<p>The result was a wrapper with methods like this:<\/p>\n<pre class=\"cpp\" name=\"code\">\r\n[DispId(42)]\r\nvoid GetListOfStructs(ref S[] arrRes);\r\n<\/pre>\n<p>which of course had to be called like this:<\/p>\n<pre class=\"cpp\" name=\"code\">\r\nS[] result = null;\r\nobj.GetListOfStructs(ref result);\r\n<\/pre>\n<p>To include either one or the other in the C# project I had to manually change the project file, since Visual Studio does not know conditional references, a feature available in MSBuild. I didn&#8217;t build the managed app for Any CPU because it had to be able to run as 32-bit on 64-bit machines, so I had two configurations, one for x86 and one fore x64.<\/p>\n<pre class=\"xml\" name=\"code\">\r\n    &lt;Reference Condition=\" '$(Platform)' == 'x86' \" Include=\"NativeCOMServer.Interop, \r\n               Version=1.0.0.0, Culture=neutral, PublicKeyToken=f5b9312191a42d52, processorArchitecture=x86\">\r\n      &lt;SpecificVersion>False&lt;\/SpecificVersion>\r\n      &lt;HintPath>..\\Bin\\NativeCOMServer.Interop.dll&lt;\/HintPath>\r\n    &lt;\/Reference>\r\n    &lt;Reference Condition=\" '$(Platform)' == 'x64' \" Include=\"NativeCOMServer.Interop, \r\n               Version=1.0.0.0, Culture=neutral, PublicKeyToken=f5b9312191a42d52, processorArchitecture=x64\">\r\n      &lt;SpecificVersion>False&lt;\/SpecificVersion>\r\n      &lt;HintPath>..\\Bin64\\NativeCOMServer.Interop.dll&lt;\/HintPath>\r\n    &lt;\/Reference>\r\n<\/pre>\n<p>But this time the wrappers were able to bridge the call and everything worked smoothly. <\/p>\n<p>The lesson learned is that when you have COM custom structures you should not rely on the way Visual Studio generates the interop assembly. You should build the interop explicitly (maybe as a custom build step, like I did) and include it as an assembly reference to your managed project.<\/p>\n<p><a href=\"http:\/\/www.codeproject.com\/script\/Articles\/BlogArticleList.aspx?amid=562357\" rel=\"tag\" style=\"display:none\">CodeProject<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Not long ago I ran into a COM interop problem that was a bit tricky to fix. So I&#8217;m sharing the problem and the solution here in case others encounter the same problem. I had this native in-proc COM server that initially was built only for x86. It was used in a native MFC application &#8230; <a title=\"Accessing 64-bit Native COM Server From a Managed Client\" class=\"read-more\" href=\"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/\" aria-label=\"Read more about Accessing 64-bit Native COM Server From a Managed Client\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[13,237,11,7,211],"tags":[451,461,301,300,299,302,55],"class_list":["post-1147","post","type-post","status-publish","format-standard","hentry","category-net","category-64bit","category-csharp","category-c","category-com","tag-c","tag-com","tag-interop","tag-managed","tag-native","tag-tlbimp","tag-visualstudio"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Lessons learned from interoping a COM server in a managed assembly when targeting x64 platform.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"com,c++,c#,native,managed,interop,tlbimp,visualstudio\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Accessing 64-bit Native COM Server From a Managed Client\" \/>\n\t\t<meta property=\"og:description\" content=\"Lessons learned from interoping a COM server in a managed assembly when targeting x64 platform.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2011-10-19T07:26:43+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2012-11-23T10:57:34+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Accessing 64-bit Native COM Server From a Managed Client\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Lessons learned from interoping a COM server in a managed assembly when targeting x64 platform.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2011\\\/10\\\/19\\\/accessing-64-bit-native-com-server-from-a-managed-client\\\/#article\",\"name\":\"Accessing 64-bit Native COM Server From a Managed Client\",\"headline\":\"Accessing 64-bit Native COM Server From a Managed Client\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"datePublished\":\"2011-10-19T09:26:43+02:00\",\"dateModified\":\"2012-11-23T12:57:34+02:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2011\\\/10\\\/19\\\/accessing-64-bit-native-com-server-from-a-managed-client\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2011\\\/10\\\/19\\\/accessing-64-bit-native-com-server-from-a-managed-client\\\/#webpage\"},\"articleSection\":\".NET, 64bit, C#, C++, COM, C++, COM, interop, managed, native, tlbimp, VisualStudio\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2011\\\/10\\\/19\\\/accessing-64-bit-native-com-server-from-a-managed-client\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/#listItem\",\"name\":\".NET\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/#listItem\",\"position\":4,\"name\":\".NET\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/csharp\\\/#listItem\",\"name\":\"C#\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/csharp\\\/#listItem\",\"position\":5,\"name\":\"C#\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/csharp\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2011\\\/10\\\/19\\\/accessing-64-bit-native-com-server-from-a-managed-client\\\/#listItem\",\"name\":\"Accessing 64-bit Native COM Server From a Managed Client\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/#listItem\",\"name\":\".NET\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2011\\\/10\\\/19\\\/accessing-64-bit-native-com-server-from-a-managed-client\\\/#listItem\",\"position\":6,\"name\":\"Accessing 64-bit Native COM Server From a Managed Client\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/csharp\\\/#listItem\",\"name\":\"C#\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2011\\\/10\\\/19\\\/accessing-64-bit-native-com-server-from-a-managed-client\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2011\\\/10\\\/19\\\/accessing-64-bit-native-com-server-from-a-managed-client\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2011\\\/10\\\/19\\\/accessing-64-bit-native-com-server-from-a-managed-client\\\/\",\"name\":\"Accessing 64-bit Native COM Server From a Managed Client\",\"description\":\"Lessons learned from interoping a COM server in a managed assembly when targeting x64 platform.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2011\\\/10\\\/19\\\/accessing-64-bit-native-com-server-from-a-managed-client\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2011-10-19T09:26:43+02:00\",\"dateModified\":\"2012-11-23T12:57:34+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Accessing 64-bit Native COM Server From a Managed Client","description":"Lessons learned from interoping a COM server in a managed assembly when targeting x64 platform.","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/","robots":"max-image-preview:large","keywords":"com,c++,c#,native,managed,interop,tlbimp,visualstudio","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/#article","name":"Accessing 64-bit Native COM Server From a Managed Client","headline":"Accessing 64-bit Native COM Server From a Managed Client","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"datePublished":"2011-10-19T09:26:43+02:00","dateModified":"2012-11-23T12:57:34+02:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/#webpage"},"articleSection":".NET, 64bit, C#, C++, COM, C++, COM, interop, managed, native, tlbimp, VisualStudio"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/#listItem","name":".NET"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/#listItem","position":4,"name":".NET","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/csharp\/#listItem","name":"C#"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/csharp\/#listItem","position":5,"name":"C#","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/csharp\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/#listItem","name":"Accessing 64-bit Native COM Server From a Managed Client"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/#listItem","name":".NET"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/#listItem","position":6,"name":"Accessing 64-bit Native COM Server From a Managed Client","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/csharp\/#listItem","name":"C#"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/","name":"Accessing 64-bit Native COM Server From a Managed Client","description":"Lessons learned from interoping a COM server in a managed assembly when targeting x64 platform.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2011-10-19T09:26:43+02:00","dateModified":"2012-11-23T12:57:34+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"Accessing 64-bit Native COM Server From a Managed Client","og:description":"Lessons learned from interoping a COM server in a managed assembly when targeting x64 platform.","og:url":"https:\/\/mariusbancila.ro\/blog\/2011\/10\/19\/accessing-64-bit-native-com-server-from-a-managed-client\/","article:published_time":"2011-10-19T07:26:43+00:00","article:modified_time":"2012-11-23T10:57:34+00:00","twitter:card":"summary","twitter:title":"Accessing 64-bit Native COM Server From a Managed Client","twitter:description":"Lessons learned from interoping a COM server in a managed assembly when targeting x64 platform."},"aioseo_meta_data":{"post_id":"1147","title":"Accessing 64-bit Native COM Server From a Managed Client","description":"Lessons learned from interoping a COM server in a managed assembly when targeting x64 platform.","keywords":[{"label":"COM","value":"COM"},{"label":"C++","value":"C++"},{"label":"C#","value":"C#"},{"label":"native","value":"native"},{"label":"managed","value":"managed"},{"label":"interop","value":"interop"},{"label":"tlbimp","value":"tlbimp"},{"label":"VisualStudio","value":"VisualStudio"}],"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:13:02","updated":"2025-12-12 07:37:23","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"Not long ago I ran into a COM interop problem that was a bit tricky to fix. So I&#8217;m sharing the problem and the solution here in case others encounter the same problem. I had this native in-proc COM server that initially was built only for x86. It was used in a native MFC application&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/\" class=\"advgb-post-tax-term\">.NET<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/64bit\/\" class=\"advgb-post-tax-term\">64bit<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/csharp\/\" class=\"advgb-post-tax-term\">C#<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/com\/\" class=\"advgb-post-tax-term\">COM<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">.NET<\/span>","<span class=\"advgb-post-tax-term\">64bit<\/span>","<span class=\"advgb-post-tax-term\">C#<\/span>","<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">COM<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/com\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/com\/\" class=\"advgb-post-tax-term\">COM<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/com\/\" class=\"advgb-post-tax-term\">interop<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/com\/\" class=\"advgb-post-tax-term\">managed<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/com\/\" class=\"advgb-post-tax-term\">native<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/com\/\" class=\"advgb-post-tax-term\">tlbimp<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/com\/\" class=\"advgb-post-tax-term\">VisualStudio<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">COM<\/span>","<span class=\"advgb-post-tax-term\">interop<\/span>","<span class=\"advgb-post-tax-term\">managed<\/span>","<span class=\"advgb-post-tax-term\">native<\/span>","<span class=\"advgb-post-tax-term\">tlbimp<\/span>","<span class=\"advgb-post-tax-term\">VisualStudio<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 15 years ago","modified":"Updated 14 years ago"},"absolute_dates":{"created":"Posted on October 19, 2011","modified":"Updated on November 23, 2012"},"absolute_dates_time":{"created":"Posted on October 19, 2011 9:26 am","modified":"Updated on November 23, 2012 12:57 pm"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-iv","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/1147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=1147"}],"version-history":[{"count":15,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/1147\/revisions"}],"predecessor-version":[{"id":1409,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/1147\/revisions\/1409"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=1147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=1147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=1147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}