HResult

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

    #1

    HResult

    Hi
    We are rewriting a COM object in C#. The COM object
    returns HRESULT for invalid arguments, null values etc.
    The HRESULT is created using the MAKE_HRESULT macro in C++.
    1.What is the C# equivalent of MAKE_HRESULT?
    2.How do I return a HRESULT or an exception from my C#
    program that would indicate a FAILURE.
    Any help is appreciated.
    Thanks.



  • Mickey Williams

    #2
    Re: HResult

    The general .NET pattern is to indicate failure with an exception rather
    than return value.

    --
    Mickey Williams
    Author, "Microsoft Visual C# .NET Core Reference", MS Press



    "lakshmi" <lm@nospam.ne t> wrote in message
    news:106d01c372 46$2b3533d0$a40 1280a@phx.gbl.. .[color=blue]
    > Hi
    > We are rewriting a COM object in C#. The COM object
    > returns HRESULT for invalid arguments, null values etc.
    > The HRESULT is created using the MAKE_HRESULT macro in C++.
    > 1.What is the C# equivalent of MAKE_HRESULT?
    > 2.How do I return a HRESULT or an exception from my C#
    > program that would indicate a FAILURE.
    > Any help is appreciated.
    > Thanks.
    >
    >
    >[/color]


    Comment

    • lakshmi

      #3
      Re: HResult

      thanks Mickey, I'm actually reading your Visual C#.NET
      core reference book.[color=blue]
      >-----Original Message-----
      >The general .NET pattern is to indicate failure with an[/color]
      exception rather[color=blue]
      >than return value.
      >
      >--
      >Mickey Williams
      >Author, "Microsoft Visual C# .NET Core Reference", MS[/color]
      Press[color=blue]
      >www.servergeek.com
      >
      >
      >"lakshmi" <lm@nospam.ne t> wrote in message
      >news:106d01c37 246$2b3533d0$a4 01280a@phx.gbl. ..[color=green]
      >> Hi
      >> We are rewriting a COM object in C#. The COM object
      >> returns HRESULT for invalid arguments, null values etc.
      >> The HRESULT is created using the MAKE_HRESULT macro in[/color][/color]
      C++.[color=blue][color=green]
      >> 1.What is the C# equivalent of MAKE_HRESULT?
      >> 2.How do I return a HRESULT or an exception from my C#
      >> program that would indicate a FAILURE.
      >> Any help is appreciated.
      >> Thanks.
      >>
      >>
      >>[/color]
      >
      >
      >.
      >[/color]

      Comment

      • lakshmi

        #4
        Re: HResult

        The client checks for failed HRESULTS. When I throw an
        exception from my C# dll for example, when an invalid
        argument is passed, now the client acts as if it received
        a success HRESULT. Thanks for your help.[color=blue]
        >-----Original Message-----
        >The general .NET pattern is to indicate failure with an[/color]
        exception rather[color=blue]
        >than return value.
        >
        >--
        >Mickey Williams
        >Author, "Microsoft Visual C# .NET Core Reference", MS[/color]
        Press[color=blue]
        >www.servergeek.com
        >
        >
        >"lakshmi" <lm@nospam.ne t> wrote in message
        >news:106d01c37 246$2b3533d0$a4 01280a@phx.gbl. ..[color=green]
        >> Hi
        >> We are rewriting a COM object in C#. The COM object
        >> returns HRESULT for invalid arguments, null values etc.
        >> The HRESULT is created using the MAKE_HRESULT macro in[/color][/color]
        C++.[color=blue][color=green]
        >> 1.What is the C# equivalent of MAKE_HRESULT?
        >> 2.How do I return a HRESULT or an exception from my C#
        >> program that would indicate a FAILURE.
        >> Any help is appreciated.
        >> Thanks.
        >>
        >>
        >>[/color]
        >
        >
        >.
        >[/color]

        Comment

        • lakshmi

          #5
          Re: HResult

          thanks again.
          Yes, the client checks for FAILED(hr).
          I'm throwing ArgumentExcepti on,
          ArgumentOutOfRa ngeException etc. from my C# code.[color=blue]
          >-----Original Message-----
          >"lakshmi" <lm@nospam.ne t> wrote in message
          >news:041201c37 253$9527a040$a3 01280a@phx.gbl. ..[color=green]
          >> The client checks for failed HRESULTS. When I throw an
          >> exception from my C# dll for example, when an invalid
          >> argument is passed, now the client acts as if it[/color][/color]
          received[color=blue][color=green]
          >> a success HRESULT. Thanks for your help.[/color]
          >
          >What kind of exception are you throwing? Are you using[/color]
          FAILED(hr)?[color=blue]
          >
          >--
          >Mickey Williams
          >Author, "Microsoft Visual C# .NET Core Reference", MS[/color]
          Press[color=blue]
          >www.servergeek.com
          >
          >
          >[color=green][color=darkred]
          >> >-----Original Message-----
          >> >The general .NET pattern is to indicate failure with an[/color]
          >> exception rather[color=darkred]
          >> >than return value.
          >> >
          >> >--
          >> >Mickey Williams
          >> >Author, "Microsoft Visual C# .NET Core Reference", MS[/color]
          >> Press[color=darkred]
          >> >www.servergeek.com
          >> >
          >> >
          >> >"lakshmi" <lm@nospam.ne t> wrote in message
          >> >news:106d01c37 246$2b3533d0$a4 01280a@phx.gbl. ..
          >> >> Hi
          >> >> We are rewriting a COM object in C#. The COM object
          >> >> returns HRESULT for invalid arguments, null values[/color][/color][/color]
          etc.[color=blue][color=green][color=darkred]
          >> >> The HRESULT is created using the MAKE_HRESULT macro[/color][/color][/color]
          in[color=blue][color=green]
          >> C++.[color=darkred]
          >> >> 1.What is the C# equivalent of MAKE_HRESULT?
          >> >> 2.How do I return a HRESULT or an exception from my[/color][/color][/color]
          C#[color=blue][color=green][color=darkred]
          >> >> program that would indicate a FAILURE.
          >> >> Any help is appreciated.
          >> >> Thanks.
          >> >>
          >> >>
          >> >>
          >> >
          >> >
          >> >.
          >> >[/color][/color]
          >
          >
          >.
          >[/color]

          Comment

          Working...