zoukankan      html  css  js  c++  java
  • An attempt was made to load a program with an incorrect format

     

    用.net调用一个C++ 32位的DLL, 编译的时候选择x86, 在部署到一个64位的机器上的时候报错:"An attempt was made to load a program with an incorrect format"

    解决方法:

    在出错的机器上,用VS命令行工具定位到.net exe所在的目录,然后运行

    corflags <.net exe文件名> /32Bit+

     

    参考文章如下:

     

     

    Tip of the day: "An attempt was made to load a program with an incorrect format" .NET P/INVOKE issue

    The other day I was using a 3rd party utility which was built on the .NET platform. My primary work computer happens to be a x64 installation. So on this computer when I fired the utility up, and tried to perform some tasks it would error with a .NET Exception which basically had the following characteristics:

    – Message: "An attempt was made to load a program with an incorrect format"

    – Exception: System.BadImageFormatException

    After some troubleshooting it turned out that this utility was trying to load a plain-old DLL (which exported some functions) presumably using P/Invoke. The DLL was built for 32-bit platforms. Now it turns out that by design a 64-bit process (the 3rd party utility would run as a 64-bit process owing to the 64-bit .NET runtime) would be prevented from loading a non-COM 32-bit DLL (32-bit COM DLLs are loaded in a DLLHOST.EXE surrogate when invoked from a 64-bit client process, BTW…) with the above exception.

    To configure the utility to run as a 32-bit .NET process, it turns out you can use the CORFLAGS utility. You run it as follows to switch the 32-bit execution mode ON:

    corflags utility.exe /32Bit+

    To turn it off, just use /32Bit- in the above command line.

  • 相关阅读:
    自动映射失效的解决办法
    D方法 自动完成
    怎样处理包含的动态模板
    后台登陆功能的实现 SESSION
    输入框 最简单的样式
    php 添加数据库的几种方法
    php 连接数据库
    array、isset、三元运算符、find()
    foreach、count、explode(对无限级分类的语法注释-显示无限级效果)
    两种常用的启动和关闭MySQL服务
  • 原文地址:https://www.cnblogs.com/time-is-life/p/5937908.html
Copyright © 2011-2022 走看看