Using Winerror.h in C#

  • Thread starter Thread starter Lady_A
  • Start date Start date
L

Lady_A

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 ?
 
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 ?

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_CODE.

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
 
Lady_A said:
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...

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
 
Back
Top