PInvoke, System.BadImageFormatException

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cwjacklin

    #1

    PInvoke, System.BadImageFormatException

    I read this article on
    http://msdn.microsoft.com/msdnmag/issues/03/07/NET/
    which describes how to invoke C win32 dll from C#

    But I am running into a weird situation.

    I have an existing C win32 dll which I want to call from C#. When I
    use syntax like this

    [DllImport("User 32.dll")]
    static extern Boolean MessageBeep(UIn t32 beepType);
    on my dll, I get an error 'System.BadImag eFormatExceptio n'

    However, if I just create from scratch a sample win32 dll in Visual
    Studio, I can run the sample function just fine.

    C# is supposed to be able to call a C unmanaged dll, but the error
    seems to tell me otherwise.

    Has anyone seen this before?

    Thanks,

    Jack

  • James Park

    #2
    Re: PInvoke, System.BadImage FormatException

    Are you using Windows x64? If your C# app is running as 64-bit and trying to
    use a 32-bit dll, you'll get that exception.

    "cwjacklin" <cwjacklin@gmai l.com> wrote in message
    news:1136846016 .487591.173210@ g14g2000cwa.goo glegroups.com.. .[color=blue]
    >I read this article on
    > http://msdn.microsoft.com/msdnmag/issues/03/07/NET/
    > which describes how to invoke C win32 dll from C#
    >
    > But I am running into a weird situation.
    >
    > I have an existing C win32 dll which I want to call from C#. When I
    > use syntax like this
    >
    > [DllImport("User 32.dll")]
    > static extern Boolean MessageBeep(UIn t32 beepType);
    > on my dll, I get an error 'System.BadImag eFormatExceptio n'
    >
    > However, if I just create from scratch a sample win32 dll in Visual
    > Studio, I can run the sample function just fine.
    >
    > C# is supposed to be able to call a C unmanaged dll, but the error
    > seems to tell me otherwise.
    >
    > Has anyone seen this before?
    >
    > Thanks,
    >
    > Jack
    >[/color]


    Comment

    Working...