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. Question... loading unmanaged dll in x64 system

Question... loading unmanaged dll in x64 system

Scheduled Pinned Locked Moved C#
questionhelp
3 Posts 3 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.
  • B Offline
    B Offline
    Blubbo
    wrote on last edited by
    #1

    is this possible to load unmanaged dll? When changing "target platform" to x86. It does work ok. But we prefer to keep it AnyCPU state. We keep getting "BadImageException" error on this when using ANYCPU state.

    I L 2 Replies Last reply
    0
    • B Blubbo

      is this possible to load unmanaged dll? When changing "target platform" to x86. It does work ok. But we prefer to keep it AnyCPU state. We keep getting "BadImageException" error on this when using ANYCPU state.

      I Offline
      I Offline
      Ian Shlasko
      wrote on last edited by
      #2

      As far as I know, you can't mix 32-bit and 64-bit in the same process. A 32-bit EXE can't load a 64-bit DLL, and vice-versa. So if your unmanaged DLL is only available as 32-bit, you need to build your process as 32-bit (x86)... The "AnyCPU" setting is probably defaulting to 64-bit, because it doesn't detect any managed 32-bit assemblies in the project.

      Proud to have finally moved to the A-Ark. Which one are you in?
      Author of the Guardians Saga (Sci-Fi/Fantasy novels)

      1 Reply Last reply
      0
      • B Blubbo

        is this possible to load unmanaged dll? When changing "target platform" to x86. It does work ok. But we prefer to keep it AnyCPU state. We keep getting "BadImageException" error on this when using ANYCPU state.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        As Ian said, Windows only deals with homogeneous processes, so all the code must be 32-bit or all of it 64-bit. A managed app targetting "AnyCPU" gets launched as 64-bit on a 64-bit OS, and will refuse to load 32-bit code. If you have unmanaged dependencies, the practical way is NOT to use "AnyCPU" and therefore it is a pitty that (1) it is the default, and (2) Visual Studio Express doesn't really give you direct access to any other setting. :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        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