C#调C++生成的dll报0x800736B1错误

这个错误看上去好像是 C++ DLL库自己的问题,其实并不尽然。因为使用了混合模式编译托管 DLL ,因此该 DLL 又会用到非托管的 CRT ( C Run-Time )库。若是机器上没有安装这些被使用到的运行时组件,就会产生相似 HRESULT: 0x8007 的错误。

       要注意的是,若是你编译 C++ 托管程序集的时候使用的是 Debug 配置的话,生成的 DLL 须要调用的就是 CRT 对应的 debug 版本( msvcr80d.dll 及 msvcm80d.dll 等 )而不是(msvcm80.dll及 msvcp80.dll等)。了解生成的 DLL 究竟是 Debug 仍是 Release 版本最简单的方法是用文本编辑器打开该 DLL 文件,找到如下相似的内容(通常位于文件末尾处):redis

<assembly xmlns="urn:schemas-microsoft-com:asm.v1"    编辑器

  1.           manifestVersion="1.0">  
  2.   <dependency>  
  3.     <dependentAssembly>  
  4.       <assemblyIdentity type="win32"    
  5.                         name="Microsoft.VC80.DebugCRT"    
  6.                         version="8.0.50608.0"    
  7.                         processorArchitecture="x86"    
  8.                         publicKeyToken="1fc8b3b9a1e18e3b">  
  9.       </assemblyIdentity>  
  10.     </dependentAssembly>  
  11.   </dependency>  
  12. </assembly>  
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"manifestVersion="1.0"><dependency><dependentAssembly><assemblyIdentity type="win32"name="Microsoft.VC80.DebugCRT"version="8.0.50608.0"processorArchitecture="x86"publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity></dependentAssembly></dependency></assembly>

 

若是看到 Microsoft.VC80.DebugCRT ,那说明该 dll Link的目标是 CRT的Debug版本,若是是Microsoft.VC80.CRT 则 link 到再分发版本。当我在 VS.net2005 的 IDE 中经过批生成来生成 C# exe 和 C++ dll 的时候,若是当前的活动解决方案配置是 Debug 的话,在 C# 项目的Release输出目录下拷贝的会是 C++ dll 的 Debug 版本文件而不是 Release 版本!因此在发布生成以后确认对应文件的版本仍是至关有必要的。spa

下面是两种模式须要的文件及目录位置,根据模式将相应的文件拷入安装目录便可解决上述问题.net

状态 : Debug Modedebug

     \Microsoft Visual Studio 8\VC\redist\Debug_NonRedist\x86xml

          |
          -> \Microsoft.VC80.DebugCRT
               |
               -> Microsoft.VC80.DebugCRT.manifest, msvcm80d.dll, msvcp80d.dll, msvcr80d.dll
  状态 : Relsase Mode
     
     \Microsoft Visual Studio 8\VC\redist\x86
         
          |
          -> \Microsoft.VC80.CRT
               |
               -> Microsoft.VC80.CRT.manifest, msvcm80.dll, msvcp80.dll, msvcr80.dllget

如何生成Release 版本:it

     将运行按钮右边的解决方案配置改成Release模式,而后生成便可io

相关文章
相关标签/搜索