delegate calling convention

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

    delegate calling convention

    Is there a way to change the calling convention of a delegate to Cdecl? Is
    it possible to define a callback function in C# that used the Cdecl
    convention?

    Thanks in advance.


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: delegate calling convention

    apm,

    You can only do this in .NET 2.0. You can apply the
    UnmanagedFuncti onPointer attribute to the delegate.

    In .NET 1.1 and before, you would have to pass your delegate to an
    unmanaged piece of code which has the signature of the delegate, and pass
    that to your function.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "apm" <Contributor@Ad sorptionProcess Modeling.com> wrote in message
    news:wCgUe.3641 $nq.3584@lakere ad05...[color=blue]
    > Is there a way to change the calling convention of a delegate to Cdecl?
    > Is it possible to define a callback function in C# that used the Cdecl
    > convention?
    >
    > Thanks in advance.
    >[/color]


    Comment

    • apm

      #3
      Re: delegate calling convention


      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
      message news:eNxDNjUtFH A.3720@TK2MSFTN GP14.phx.gbl...[color=blue]
      > apm,
      >
      > You can only do this in .NET 2.0. You can apply the
      > UnmanagedFuncti onPointer attribute to the delegate.
      >
      > In .NET 1.1 and before, you would have to pass your delegate to an
      > unmanaged piece of code which has the signature of the delegate, and pass
      > that to your function.
      >
      > Hope this helps.[/color]

      Thank you. This is what I have done in the past using C++. Can it be done
      with C#?
      [color=blue]
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "apm" <Contributor@Ad sorptionProcess Modeling.com> wrote in message
      > news:wCgUe.3641 $nq.3584@lakere ad05...[color=green]
      >> Is there a way to change the calling convention of a delegate to Cdecl?
      >> Is it possible to define a callback function in C# that used the Cdecl
      >> convention?
      >>
      >> Thanks in advance.
      >>[/color]
      >
      >[/color]


      Comment

      • Willy Denoyette [MVP]

        #4
        Re: delegate calling convention

        No, not in v1.x. All you can do is change your C++ code's calling convention
        to _stdcall (WINAPI), which is the default for callbacks in Win32. Another
        option is to change and reassemble the IL in a post-build step.

        Willy.


        "apm" <Contributor@Ad sorptionProcess Modeling.com> wrote in message
        news:u7kUe.3653 $nq.1829@lakere ad05...[color=blue]
        >
        > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
        > in message news:eNxDNjUtFH A.3720@TK2MSFTN GP14.phx.gbl...[color=green]
        >> apm,
        >>
        >> You can only do this in .NET 2.0. You can apply the
        >> UnmanagedFuncti onPointer attribute to the delegate.
        >>
        >> In .NET 1.1 and before, you would have to pass your delegate to an
        >> unmanaged piece of code which has the signature of the delegate, and pass
        >> that to your function.
        >>
        >> Hope this helps.[/color]
        >
        > Thank you. This is what I have done in the past using C++. Can it be
        > done with C#?
        >[color=green]
        >>
        >>
        >> --
        >> - Nicholas Paldino [.NET/C# MVP]
        >> - mvp@spam.guard. caspershouse.co m
        >>
        >> "apm" <Contributor@Ad sorptionProcess Modeling.com> wrote in message
        >> news:wCgUe.3641 $nq.3584@lakere ad05...[color=darkred]
        >>> Is there a way to change the calling convention of a delegate to Cdecl?
        >>> Is it possible to define a callback function in C# that used the Cdecl
        >>> convention?
        >>>
        >>> Thanks in advance.
        >>>[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • apm

          #5
          Re: delegate calling convention


          "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
          news:OL75CJXtFH A.2472@TK2MSFTN GP14.phx.gbl...[color=blue]
          > No, not in v1.x. All you can do is change your C++ code's calling
          > convention to _stdcall (WINAPI), which is the default for callbacks in
          > Win32.[/color]

          I don't have the source.
          [color=blue]
          > Another option is to change and reassemble the IL in a post-build step.[/color]

          Interesting.
          [color=blue]
          >
          > Willy.[/color]

          Thank you so much.
          [color=blue]
          >
          >
          > "apm" <Contributor@Ad sorptionProcess Modeling.com> wrote in message
          > news:u7kUe.3653 $nq.1829@lakere ad05...[color=green]
          >>
          >> "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
          >> in message news:eNxDNjUtFH A.3720@TK2MSFTN GP14.phx.gbl...[color=darkred]
          >>> apm,
          >>>
          >>> You can only do this in .NET 2.0. You can apply the
          >>> UnmanagedFuncti onPointer attribute to the delegate.
          >>>
          >>> In .NET 1.1 and before, you would have to pass your delegate to an
          >>> unmanaged piece of code which has the signature of the delegate, and
          >>> pass that to your function.
          >>>
          >>> Hope this helps.[/color]
          >>
          >> Thank you. This is what I have done in the past using C++. Can it be
          >> done with C#?
          >>[color=darkred]
          >>>
          >>>
          >>> --
          >>> - Nicholas Paldino [.NET/C# MVP]
          >>> - mvp@spam.guard. caspershouse.co m
          >>>
          >>> "apm" <Contributor@Ad sorptionProcess Modeling.com> wrote in message
          >>> news:wCgUe.3641 $nq.3584@lakere ad05...
          >>>> Is there a way to change the calling convention of a delegate to Cdecl?
          >>>> Is it possible to define a callback function in C# that used the Cdecl
          >>>> convention?
          >>>>
          >>>> Thanks in advance.
          >>>>
          >>>
          >>>[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          Working...