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. using DLL in Vista 64bit, Bad Image Format Exception

using DLL in Vista 64bit, Bad Image Format Exception

Scheduled Pinned Locked Moved C#
helpquestionannouncement
9 Posts 2 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.
  • S Offline
    S Offline
    sharp_k
    wrote on last edited by
    #1

    I am trying to use this DLL in Vista 64 bit version. It give me error (exception) "BadImageFormatException was unhandled". The same DLL works fine with 32 bit version (Vista). Anyone has come across it, is there a way to resolve it?

    J 1 Reply Last reply
    0
    • S sharp_k

      I am trying to use this DLL in Vista 64 bit version. It give me error (exception) "BadImageFormatException was unhandled". The same DLL works fine with 32 bit version (Vista). Anyone has come across it, is there a way to resolve it?

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Assuming this dll you're using is one you've built, When you built the dll, was it built using the AnyCPU platform? If so, you must ensure there are not 32-bit specific references to your code. (Many COM objects, native dlls, 3rd party libs are all 32-bit specific. You may need to obtain 64-bit specific versions of those components.) Another thing to try is build the dll using x64 as the platform.

      Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      S 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        Assuming this dll you're using is one you've built, When you built the dll, was it built using the AnyCPU platform? If so, you must ensure there are not 32-bit specific references to your code. (Many COM objects, native dlls, 3rd party libs are all 32-bit specific. You may need to obtain 64-bit specific versions of those components.) Another thing to try is build the dll using x64 as the platform.

        Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        S Offline
        S Offline
        sharp_k
        wrote on last edited by
        #3

        Yes it is my own dll and it was built using 'any cpu' option. Also I tried the x64bit but it gave the same error. Sometime it give NotValidEntryPointException, othertimes it gives BadImageException. It work fine on 32bit wondows though. I am not deep into COM so i do not know what can go wrong there.

        J 1 Reply Last reply
        0
        • S sharp_k

          Yes it is my own dll and it was built using 'any cpu' option. Also I tried the x64bit but it gave the same error. Sometime it give NotValidEntryPointException, othertimes it gives BadImageException. It work fine on 32bit wondows though. I am not deep into COM so i do not know what can go wrong there.

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #4

          Does your dll use any 3rd party libraries? COM objects? Does it make P/Invoke calls into native dlls?

          Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

          S 1 Reply Last reply
          0
          • J Judah Gabriel Himango

            Does your dll use any 3rd party libraries? COM objects? Does it make P/Invoke calls into native dlls?

            Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

            S Offline
            S Offline
            sharp_k
            wrote on last edited by
            #5

            Yes it does use third party libraries. I am new to c# so I do not know much about p/invoke but yes it uses p/invoke as well. I do not think it uses COM objects. Again it is working on on 64bit machine (not a vista one).

            J 1 Reply Last reply
            0
            • S sharp_k

              Yes it does use third party libraries. I am new to c# so I do not know much about p/invoke but yes it uses p/invoke as well. I do not think it uses COM objects. Again it is working on on 64bit machine (not a vista one).

              J Offline
              J Offline
              Judah Gabriel Himango
              wrote on last edited by
              #6

              Can you post some of your P/Invoke calls? Most likely it's an issue with those.

              Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

              S 1 Reply Last reply
              0
              • J Judah Gabriel Himango

                Can you post some of your P/Invoke calls? Most likely it's an issue with those.

                Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                S Offline
                S Offline
                sharp_k
                wrote on last edited by
                #7

                Here is the format of one such call. [DllImport(dllName, ExactSpelling=true, SetLastError=false, CallingConvention=CallingConvention.Cdecl)] internal static extern float a_function(int n, [In] float[] x, int incX); Thanks.

                J 1 Reply Last reply
                0
                • S sharp_k

                  Here is the format of one such call. [DllImport(dllName, ExactSpelling=true, SetLastError=false, CallingConvention=CallingConvention.Cdecl)] internal static extern float a_function(int n, [In] float[] x, int incX); Thanks.

                  J Offline
                  J Offline
                  Judah Gabriel Himango
                  wrote on last edited by
                  #8

                  Yep, that looks problematic: the first value is an integer. In .NET, this will always be 4 bytes. In native code, however, this will be either 4 bytes on a 32-bit system, or 8 bytes on a 64 bit system (IIRC). Instead of an integer, pass in an IntPtr. Your function would look something like this:

                  [DllImport(dllName, ExactSpelling=true, SetLastError=false, CallingConvention=CallingConvention.Cdecl)]
                  internal static extern float a_function(IntPtr n, [In] float[] x, IntPtr incX);

                  Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                  S 1 Reply Last reply
                  0
                  • J Judah Gabriel Himango

                    Yep, that looks problematic: the first value is an integer. In .NET, this will always be 4 bytes. In native code, however, this will be either 4 bytes on a 32-bit system, or 8 bytes on a 64 bit system (IIRC). Instead of an integer, pass in an IntPtr. Your function would look something like this:

                    [DllImport(dllName, ExactSpelling=true, SetLastError=false, CallingConvention=CallingConvention.Cdecl)]
                    internal static extern float a_function(IntPtr n, [In] float[] x, IntPtr incX);

                    Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                    S Offline
                    S Offline
                    sharp_k
                    wrote on last edited by
                    #9

                    I will try it with a new test program to see if it works. Now apparentely the code should work because i am getting error from DLL not from native code. The client program basically does not find the necessary signature or entry point inside DLL. It does not reach the native code part at all. The DLL is just a wrapper of the native code. I will give it a try though and will let you know what happens.

                    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