Using Winerror.h in C#

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

    Using Winerror.h in C#

    Hi,

    I would like to use one of the error codes defined in WinError.h.
    There is no iclude anymore.
    I have put in "using System.Runtime. InteropServices " and the compiler
    still doesn't recognize the error code.
    There must be some way, other than defining it by myself...

    Anybody ?


  • Gary K

    #2
    Re: Using Winerror.h in C#

    On Mon, 17 Oct 2005 02:59:53 +0000, "Lady_A" <alevich@wavesy s.com>
    wrote:
    [color=blue]
    >Hi,
    >
    >I would like to use one of the error codes defined in WinError.h.
    >There is no iclude anymore.
    >I have put in "using System.Runtime. InteropServices " and the compiler
    >still doesn't recognize the error code.
    >There must be some way, other than defining it by myself...
    >
    >Anybody ?
    >[/color]

    Greetings & Salutations,

    Sorry but you will have to define it yourself.

    From my understanding, C# (and other .NET languages) are not meant to
    refer to the Windows API in any 'normal' way.

    This isn't too hard though (but still time consuming if you want to do
    all the errors). Just write a sealed class with the error code
    constants in it. Then you can refer to it in code as
    WinError.ERR_CO DE.

    public sealed class WinError {
    public const int ERR_CODE = <errnum>;
    }

    Although if you use the SUCCESS/FAILED macros, you will have to write
    these into code. Maybe as static methods of the sealed class?

    If you're lucky, someone has already done this work and posted it
    somewhere on the net.

    Gary K

    Comment

    • Jason Newell

      #3
      Re: Using Winerror.h in C#

      Download http://www.paulyao.com/pinvoke and save yourself a ton of effort.

      Jason Newell


      Gary K wrote:[color=blue]
      > On Mon, 17 Oct 2005 02:59:53 +0000, "Lady_A" <alevich@wavesy s.com>
      > wrote:
      >
      >[color=green]
      >>Hi,
      >>
      >>I would like to use one of the error codes defined in WinError.h.
      >>There is no iclude anymore.
      >>I have put in "using System.Runtime. InteropServices " and the compiler
      >>still doesn't recognize the error code.
      >>There must be some way, other than defining it by myself...
      >>
      >>Anybody ?
      >>[/color]
      >
      >
      > Greetings & Salutations,
      >
      > Sorry but you will have to define it yourself.
      >
      > From my understanding, C# (and other .NET languages) are not meant to
      > refer to the Windows API in any 'normal' way.
      >
      > This isn't too hard though (but still time consuming if you want to do
      > all the errors). Just write a sealed class with the error code
      > constants in it. Then you can refer to it in code as
      > WinError.ERR_CO DE.
      >
      > public sealed class WinError {
      > public const int ERR_CODE = <errnum>;
      > }
      >
      > Although if you use the SUCCESS/FAILED macros, you will have to write
      > these into code. Maybe as static methods of the sealed class?
      >
      > If you're lucky, someone has already done this work and posted it
      > somewhere on the net.
      >
      > Gary K[/color]

      Comment

      • Richard Grimes

        #4
        Re: Using Winerror.h in C#

        Lady_A wrote:[color=blue]
        > Hi,
        >
        > I would like to use one of the error codes defined in WinError.h.
        > There is no iclude anymore.
        > I have put in "using System.Runtime. InteropServices " and the compiler
        > still doesn't recognize the error code.
        > There must be some way, other than defining it by myself...[/color]

        C# does not use C++ header files. The values in winerror.h are
        *constants* so platform invoke is not relevant (platform invoke is used
        to call *functions*). As Gary K says, you'll just have to copy the
        constants into your own C# code.

        Richard
        --




        Comment

        Working...