Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. PInvoke with 32 bit native Dll in windows 7 64 bit

PInvoke with 32 bit native Dll in windows 7 64 bit

Scheduled Pinned Locked Moved C#
csharpc++helpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chesnokov Yuriy
    wrote on last edited by
    #1

    What is the problem to run in windows 7 64 bit C# application (compiled on Vista 32 bit VS2008 .NET 3.5) which uses PInvoke to run native function from 32 bit Dll. Exception is System.BadImageFormatException Attempt to load application having bad format (HRESULT: 0x8007000B)

    Чесноков

    C M P 3 Replies Last reply
    0
    • C Chesnokov Yuriy

      What is the problem to run in windows 7 64 bit C# application (compiled on Vista 32 bit VS2008 .NET 3.5) which uses PInvoke to run native function from 32 bit Dll. Exception is System.BadImageFormatException Attempt to load application having bad format (HRESULT: 0x8007000B)

      Чесноков

      C Offline
      C Offline
      Covean
      wrote on last edited by
      #2

      You can't use a 32 bit dll in an 64 bit application (and vice versa). I'm not sure about native dlls but I think they behave the same.

      Greetings Covean

      1 Reply Last reply
      0
      • C Chesnokov Yuriy

        What is the problem to run in windows 7 64 bit C# application (compiled on Vista 32 bit VS2008 .NET 3.5) which uses PInvoke to run native function from 32 bit Dll. Exception is System.BadImageFormatException Attempt to load application having bad format (HRESULT: 0x8007000B)

        Чесноков

        M Offline
        M Offline
        Mirko1980
        wrote on last edited by
        #3

        As Covean said, you can't use a 32bit dll form a 64bit application. By default, a .NET application run according to the O.S. (so, in a 64bit systems run as 64bit application). You have to force your application to run as 32bit by changing the "Platfor Target" value in the Build properties of your Visual Studio Project.

        1 Reply Last reply
        0
        • C Chesnokov Yuriy

          What is the problem to run in windows 7 64 bit C# application (compiled on Vista 32 bit VS2008 .NET 3.5) which uses PInvoke to run native function from 32 bit Dll. Exception is System.BadImageFormatException Attempt to load application having bad format (HRESULT: 0x8007000B)

          Чесноков

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          If you have a 64 bit .NET application attempting to run a 32 bit DLL, you can change it to run in 32 bit mode by using the corflags command. It's detailed here[^], but basically you need to run

          corflags myassembly.exe /32bit+

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

          My blog | My articles | MoXAML PowerToys | Onyx

          C 1 Reply Last reply
          0
          • P Pete OHanlon

            If you have a 64 bit .NET application attempting to run a 32 bit DLL, you can change it to run in 32 bit mode by using the corflags command. It's detailed here[^], but basically you need to run

            corflags myassembly.exe /32bit+

            "WPF has many lovers. It's a veritable porn star!" - Josh Smith

            As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

            My blog | My articles | MoXAML PowerToys | Onyx

            C Offline
            C Offline
            Chesnokov Yuriy
            wrote on last edited by
            #5

            that seems to be the only solution to avoid recompilation, many thanks!

            Чесноков

            P 1 Reply Last reply
            0
            • C Chesnokov Yuriy

              that seems to be the only solution to avoid recompilation, many thanks!

              Чесноков

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              You are welcome.

              "WPF has many lovers. It's a veritable porn star!" - Josh Smith

              As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

              My blog | My articles | MoXAML PowerToys | Onyx

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups