DllImportAttribute CallingConvention

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

    #1

    DllImportAttribute CallingConvention

    I am calling an unmanaged DLL like follows in a Class wrapper.

    namespace blah
    {
    [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
    CallingConventi on=CallingConve ntion.ThisCall]
    public static extern void blahFn(out long blah, out long blah2);

    class sealed ClassBlah
    {
    private ClassBlah()
    {
    }

    }
    }

    Why have I to call this with the CallingConventi on of ThisCall, its just
    normal "C" functions in a DLL. Why wont StdCall work?

    What happens with other calling conventions is that the out parameters are
    NOT set, yet with ThisCall, they are set ok, or appear to be. I find it odd.



    Thanks


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: DllImportAttrib ute CallingConventi on

    Mr. Tickle,

    What is the declaration of the original function? If it takes a
    pointer, then you should be using "ref" for the parameters, and not out.
    Also, does the function take a 64-bit integer? Long in C is a 32-bit
    integer, where in .NET it is a 64-bit integer.

    The STDCALL mechanism should work if you are using it.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - nicholas.paldin o@exisconsultin g.com

    "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
    news:OoNKkNsfDH A.2328@TK2MSFTN GP09.phx.gbl...[color=blue]
    > I am calling an unmanaged DLL like follows in a Class wrapper.
    >
    > namespace blah
    > {
    > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
    > CallingConventi on=CallingConve ntion.ThisCall]
    > public static extern void blahFn(out long blah, out long blah2);
    >
    > class sealed ClassBlah
    > {
    > private ClassBlah()
    > {
    > }
    >
    > }
    > }
    >
    > Why have I to call this with the CallingConventi on of ThisCall, its just
    > normal "C" functions in a DLL. Why wont StdCall work?
    >
    > What happens with other calling conventions is that the out parameters are
    > NOT set, yet with ThisCall, they are set ok, or appear to be. I find it[/color]
    odd.[color=blue]
    >
    >
    >
    > Thanks
    >
    >[/color]


    Comment

    • Mr.Tickle

      #3
      Re: DllImportAttrib ute CallingConventi on

      Nop, I tried ref and it doesnt help, the only way i can get it to return
      values is with thiscall.



      "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote
      in message news:#pDVIzsfDH A.3324@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Mr. Tickle,
      >
      > What is the declaration of the original function? If it takes a
      > pointer, then you should be using "ref" for the parameters, and not out.
      > Also, does the function take a 64-bit integer? Long in C is a 32-bit
      > integer, where in .NET it is a 64-bit integer.
      >
      > The STDCALL mechanism should work if you are using it.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - nicholas.paldin o@exisconsultin g.com
      >
      > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
      > news:OoNKkNsfDH A.2328@TK2MSFTN GP09.phx.gbl...[color=green]
      > > I am calling an unmanaged DLL like follows in a Class wrapper.
      > >
      > > namespace blah
      > > {
      > > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
      > > CallingConventi on=CallingConve ntion.ThisCall]
      > > public static extern void blahFn(out long blah, out long blah2);
      > >
      > > class sealed ClassBlah
      > > {
      > > private ClassBlah()
      > > {
      > > }
      > >
      > > }
      > > }
      > >
      > > Why have I to call this with the CallingConventi on of ThisCall, its[/color][/color]
      just[color=blue][color=green]
      > > normal "C" functions in a DLL. Why wont StdCall work?
      > >
      > > What happens with other calling conventions is that the out parameters[/color][/color]
      are[color=blue][color=green]
      > > NOT set, yet with ThisCall, they are set ok, or appear to be. I find it[/color]
      > odd.[color=green]
      > >
      > >
      > >
      > > Thanks
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Mr.Tickle

        #4
        Re: DllImportAttrib ute CallingConventi on

        So i should use Int32 for the parameters instead of long?


        "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote
        in message news:#pDVIzsfDH A.3324@TK2MSFTN GP11.phx.gbl...[color=blue]
        > Mr. Tickle,
        >
        > What is the declaration of the original function? If it takes a
        > pointer, then you should be using "ref" for the parameters, and not out.
        > Also, does the function take a 64-bit integer? Long in C is a 32-bit
        > integer, where in .NET it is a 64-bit integer.
        >
        > The STDCALL mechanism should work if you are using it.
        >
        > Hope this helps.
        >
        >
        > --
        > - Nicholas Paldino [.NET/C# MVP]
        > - nicholas.paldin o@exisconsultin g.com
        >
        > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
        > news:OoNKkNsfDH A.2328@TK2MSFTN GP09.phx.gbl...[color=green]
        > > I am calling an unmanaged DLL like follows in a Class wrapper.
        > >
        > > namespace blah
        > > {
        > > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
        > > CallingConventi on=CallingConve ntion.ThisCall]
        > > public static extern void blahFn(out long blah, out long blah2);
        > >
        > > class sealed ClassBlah
        > > {
        > > private ClassBlah()
        > > {
        > > }
        > >
        > > }
        > > }
        > >
        > > Why have I to call this with the CallingConventi on of ThisCall, its[/color][/color]
        just[color=blue][color=green]
        > > normal "C" functions in a DLL. Why wont StdCall work?
        > >
        > > What happens with other calling conventions is that the out parameters[/color][/color]
        are[color=blue][color=green]
        > > NOT set, yet with ThisCall, they are set ok, or appear to be. I find it[/color]
        > odd.[color=green]
        > >
        > >
        > >
        > > Thanks
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Mr.Tickle

          #5
          Re: DllImportAttrib ute CallingConventi on

          I also have a problem with "ref" paramaters, it says they need to be
          assigned to before used

          Yet i have them used as "ref" in dll extern calls and checked for non NULL
          after yet it complains for non assignment so i use a local copy.

          Isnt it smart enough to detect that its being assinged in an extern dll call
          as declared in DllImport?




          "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote
          in message news:#pDVIzsfDH A.3324@TK2MSFTN GP11.phx.gbl...[color=blue]
          > Mr. Tickle,
          >
          > What is the declaration of the original function? If it takes a
          > pointer, then you should be using "ref" for the parameters, and not out.
          > Also, does the function take a 64-bit integer? Long in C is a 32-bit
          > integer, where in .NET it is a 64-bit integer.
          >
          > The STDCALL mechanism should work if you are using it.
          >
          > Hope this helps.
          >
          >
          > --
          > - Nicholas Paldino [.NET/C# MVP]
          > - nicholas.paldin o@exisconsultin g.com
          >
          > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
          > news:OoNKkNsfDH A.2328@TK2MSFTN GP09.phx.gbl...[color=green]
          > > I am calling an unmanaged DLL like follows in a Class wrapper.
          > >
          > > namespace blah
          > > {
          > > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
          > > CallingConventi on=CallingConve ntion.ThisCall]
          > > public static extern void blahFn(out long blah, out long blah2);
          > >
          > > class sealed ClassBlah
          > > {
          > > private ClassBlah()
          > > {
          > > }
          > >
          > > }
          > > }
          > >
          > > Why have I to call this with the CallingConventi on of ThisCall, its[/color][/color]
          just[color=blue][color=green]
          > > normal "C" functions in a DLL. Why wont StdCall work?
          > >
          > > What happens with other calling conventions is that the out parameters[/color][/color]
          are[color=blue][color=green]
          > > NOT set, yet with ThisCall, they are set ok, or appear to be. I find it[/color]
          > odd.[color=green]
          > >
          > >
          > >
          > > Thanks
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Mr.Tickle

            #6
            Re: DllImportAttrib ute CallingConventi on

            i mean "out" oops.

            ref in the same dll wrapper still gets the output but only with thiscall
            convention.


            "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
            news:OQwh$RtfDH A.2364@TK2MSFTN GP09.phx.gbl...[color=blue]
            > I also have a problem with "ref" paramaters, it says they need to be
            > assigned to before used
            >
            > Yet i have them used as "ref" in dll extern calls and checked for non NULL
            > after yet it complains for non assignment so i use a local copy.
            >
            > Isnt it smart enough to detect that its being assinged in an extern dll[/color]
            call[color=blue]
            > as declared in DllImport?
            >
            >
            >
            >
            > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com>[/color]
            wrote[color=blue]
            > in message news:#pDVIzsfDH A.3324@TK2MSFTN GP11.phx.gbl...[color=green]
            > > Mr. Tickle,
            > >
            > > What is the declaration of the original function? If it takes a
            > > pointer, then you should be using "ref" for the parameters, and not out.
            > > Also, does the function take a 64-bit integer? Long in C is a 32-bit
            > > integer, where in .NET it is a 64-bit integer.
            > >
            > > The STDCALL mechanism should work if you are using it.
            > >
            > > Hope this helps.
            > >
            > >
            > > --
            > > - Nicholas Paldino [.NET/C# MVP]
            > > - nicholas.paldin o@exisconsultin g.com
            > >
            > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
            > > news:OoNKkNsfDH A.2328@TK2MSFTN GP09.phx.gbl...[color=darkred]
            > > > I am calling an unmanaged DLL like follows in a Class wrapper.
            > > >
            > > > namespace blah
            > > > {
            > > > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
            > > > CallingConventi on=CallingConve ntion.ThisCall]
            > > > public static extern void blahFn(out long blah, out long blah2);
            > > >
            > > > class sealed ClassBlah
            > > > {
            > > > private ClassBlah()
            > > > {
            > > > }
            > > >
            > > > }
            > > > }
            > > >
            > > > Why have I to call this with the CallingConventi on of ThisCall, its[/color][/color]
            > just[color=green][color=darkred]
            > > > normal "C" functions in a DLL. Why wont StdCall work?
            > > >
            > > > What happens with other calling conventions is that the out parameters[/color][/color]
            > are[color=green][color=darkred]
            > > > NOT set, yet with ThisCall, they are set ok, or appear to be. I find[/color][/color][/color]
            it[color=blue][color=green]
            > > odd.[color=darkred]
            > > >
            > > >
            > > >
            > > > Thanks
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Nicholas Paldino [.NET/C# MVP]

              #7
              Re: DllImportAttrib ute CallingConventi on

              If you could post the original function declaration, it would help
              tremendously.


              --
              - Nicholas Paldino [.NET/C# MVP]
              - nicholas.paldin o@exisconsultin g.com

              "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
              news:e6NNRUtfDH A.2364@TK2MSFTN GP09.phx.gbl...[color=blue]
              > i mean "out" oops.
              >
              > ref in the same dll wrapper still gets the output but only with thiscall
              > convention.
              >
              >
              > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
              > news:OQwh$RtfDH A.2364@TK2MSFTN GP09.phx.gbl...[color=green]
              > > I also have a problem with "ref" paramaters, it says they need to be
              > > assigned to before used
              > >
              > > Yet i have them used as "ref" in dll extern calls and checked for non[/color][/color]
              NULL[color=blue][color=green]
              > > after yet it complains for non assignment so i use a local copy.
              > >
              > > Isnt it smart enough to detect that its being assinged in an extern dll[/color]
              > call[color=green]
              > > as declared in DllImport?
              > >
              > >
              > >
              > >
              > > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com>[/color]
              > wrote[color=green]
              > > in message news:#pDVIzsfDH A.3324@TK2MSFTN GP11.phx.gbl...[color=darkred]
              > > > Mr. Tickle,
              > > >
              > > > What is the declaration of the original function? If it takes a
              > > > pointer, then you should be using "ref" for the parameters, and not[/color][/color][/color]
              out.[color=blue][color=green][color=darkred]
              > > > Also, does the function take a 64-bit integer? Long in C is a 32-bit
              > > > integer, where in .NET it is a 64-bit integer.
              > > >
              > > > The STDCALL mechanism should work if you are using it.
              > > >
              > > > Hope this helps.
              > > >
              > > >
              > > > --
              > > > - Nicholas Paldino [.NET/C# MVP]
              > > > - nicholas.paldin o@exisconsultin g.com
              > > >
              > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
              > > > news:OoNKkNsfDH A.2328@TK2MSFTN GP09.phx.gbl...
              > > > > I am calling an unmanaged DLL like follows in a Class wrapper.
              > > > >
              > > > > namespace blah
              > > > > {
              > > > > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
              > > > > CallingConventi on=CallingConve ntion.ThisCall]
              > > > > public static extern void blahFn(out long blah, out long blah2);
              > > > >
              > > > > class sealed ClassBlah
              > > > > {
              > > > > private ClassBlah()
              > > > > {
              > > > > }
              > > > >
              > > > > }
              > > > > }
              > > > >
              > > > > Why have I to call this with the CallingConventi on of ThisCall, its[/color]
              > > just[color=darkred]
              > > > > normal "C" functions in a DLL. Why wont StdCall work?
              > > > >
              > > > > What happens with other calling conventions is that the out[/color][/color][/color]
              parameters[color=blue][color=green]
              > > are[color=darkred]
              > > > > NOT set, yet with ThisCall, they are set ok, or appear to be. I find[/color][/color]
              > it[color=green][color=darkred]
              > > > odd.
              > > > >
              > > > >
              > > > >
              > > > > Thanks
              > > > >
              > > > >
              > > >
              > > >[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Mr.Tickle

                #8
                Re: DllImportAttrib ute CallingConventi on

                It would but I dont have it, its in a dll i have to call into. Not mine.




                "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote
                in message news:OBqOTptfDH A.2748@TK2MSFTN GP11.phx.gbl...[color=blue]
                > If you could post the original function declaration, it would help
                > tremendously.
                >
                >
                > --
                > - Nicholas Paldino [.NET/C# MVP]
                > - nicholas.paldin o@exisconsultin g.com
                >
                > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                > news:e6NNRUtfDH A.2364@TK2MSFTN GP09.phx.gbl...[color=green]
                > > i mean "out" oops.
                > >
                > > ref in the same dll wrapper still gets the output but only with thiscall
                > > convention.
                > >
                > >
                > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                > > news:OQwh$RtfDH A.2364@TK2MSFTN GP09.phx.gbl...[color=darkred]
                > > > I also have a problem with "ref" paramaters, it says they need to be
                > > > assigned to before used
                > > >
                > > > Yet i have them used as "ref" in dll extern calls and checked for non[/color][/color]
                > NULL[color=green][color=darkred]
                > > > after yet it complains for non assignment so i use a local copy.
                > > >
                > > > Isnt it smart enough to detect that its being assinged in an extern[/color][/color][/color]
                dll[color=blue][color=green]
                > > call[color=darkred]
                > > > as declared in DllImport?
                > > >
                > > >
                > > >
                > > >
                > > > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com>[/color]
                > > wrote[color=darkred]
                > > > in message news:#pDVIzsfDH A.3324@TK2MSFTN GP11.phx.gbl...
                > > > > Mr. Tickle,
                > > > >
                > > > > What is the declaration of the original function? If it takes a
                > > > > pointer, then you should be using "ref" for the parameters, and not[/color][/color]
                > out.[color=green][color=darkred]
                > > > > Also, does the function take a 64-bit integer? Long in C is a[/color][/color][/color]
                32-bit[color=blue][color=green][color=darkred]
                > > > > integer, where in .NET it is a 64-bit integer.
                > > > >
                > > > > The STDCALL mechanism should work if you are using it.
                > > > >
                > > > > Hope this helps.
                > > > >
                > > > >
                > > > > --
                > > > > - Nicholas Paldino [.NET/C# MVP]
                > > > > - nicholas.paldin o@exisconsultin g.com
                > > > >
                > > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                > > > > news:OoNKkNsfDH A.2328@TK2MSFTN GP09.phx.gbl...
                > > > > > I am calling an unmanaged DLL like follows in a Class wrapper.
                > > > > >
                > > > > > namespace blah
                > > > > > {
                > > > > > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
                > > > > > CallingConventi on=CallingConve ntion.ThisCall]
                > > > > > public static extern void blahFn(out long blah, out long blah2);
                > > > > >
                > > > > > class sealed ClassBlah
                > > > > > {
                > > > > > private ClassBlah()
                > > > > > {
                > > > > > }
                > > > > >
                > > > > > }
                > > > > > }
                > > > > >
                > > > > > Why have I to call this with the CallingConventi on of ThisCall,[/color][/color][/color]
                its[color=blue][color=green][color=darkred]
                > > > just
                > > > > > normal "C" functions in a DLL. Why wont StdCall work?
                > > > > >
                > > > > > What happens with other calling conventions is that the out[/color][/color]
                > parameters[color=green][color=darkred]
                > > > are
                > > > > > NOT set, yet with ThisCall, they are set ok, or appear to be. I[/color][/color][/color]
                find[color=blue][color=green]
                > > it[color=darkred]
                > > > > odd.
                > > > > >
                > > > > >
                > > > > >
                > > > > > Thanks
                > > > > >
                > > > > >
                > > > >
                > > > >
                > > >
                > > >[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • Mr.Tickle

                  #9
                  Re: DllImportAttrib ute CallingConventi on

                  typedef SOME_ID long

                  SOME_ID someFn(SOME_ID* someIDhere, SOME_ID* someIDhere2, SOME_ID*
                  someIDhere3);

                  something like that.


                  "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote
                  in message news:OBqOTptfDH A.2748@TK2MSFTN GP11.phx.gbl...[color=blue]
                  > If you could post the original function declaration, it would help
                  > tremendously.
                  >
                  >
                  > --
                  > - Nicholas Paldino [.NET/C# MVP]
                  > - nicholas.paldin o@exisconsultin g.com
                  >
                  > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                  > news:e6NNRUtfDH A.2364@TK2MSFTN GP09.phx.gbl...[color=green]
                  > > i mean "out" oops.
                  > >
                  > > ref in the same dll wrapper still gets the output but only with thiscall
                  > > convention.
                  > >
                  > >
                  > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                  > > news:OQwh$RtfDH A.2364@TK2MSFTN GP09.phx.gbl...[color=darkred]
                  > > > I also have a problem with "ref" paramaters, it says they need to be
                  > > > assigned to before used
                  > > >
                  > > > Yet i have them used as "ref" in dll extern calls and checked for non[/color][/color]
                  > NULL[color=green][color=darkred]
                  > > > after yet it complains for non assignment so i use a local copy.
                  > > >
                  > > > Isnt it smart enough to detect that its being assinged in an extern[/color][/color][/color]
                  dll[color=blue][color=green]
                  > > call[color=darkred]
                  > > > as declared in DllImport?
                  > > >
                  > > >
                  > > >
                  > > >
                  > > > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com>[/color]
                  > > wrote[color=darkred]
                  > > > in message news:#pDVIzsfDH A.3324@TK2MSFTN GP11.phx.gbl...
                  > > > > Mr. Tickle,
                  > > > >
                  > > > > What is the declaration of the original function? If it takes a
                  > > > > pointer, then you should be using "ref" for the parameters, and not[/color][/color]
                  > out.[color=green][color=darkred]
                  > > > > Also, does the function take a 64-bit integer? Long in C is a[/color][/color][/color]
                  32-bit[color=blue][color=green][color=darkred]
                  > > > > integer, where in .NET it is a 64-bit integer.
                  > > > >
                  > > > > The STDCALL mechanism should work if you are using it.
                  > > > >
                  > > > > Hope this helps.
                  > > > >
                  > > > >
                  > > > > --
                  > > > > - Nicholas Paldino [.NET/C# MVP]
                  > > > > - nicholas.paldin o@exisconsultin g.com
                  > > > >
                  > > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                  > > > > news:OoNKkNsfDH A.2328@TK2MSFTN GP09.phx.gbl...
                  > > > > > I am calling an unmanaged DLL like follows in a Class wrapper.
                  > > > > >
                  > > > > > namespace blah
                  > > > > > {
                  > > > > > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
                  > > > > > CallingConventi on=CallingConve ntion.ThisCall]
                  > > > > > public static extern void blahFn(out long blah, out long blah2);
                  > > > > >
                  > > > > > class sealed ClassBlah
                  > > > > > {
                  > > > > > private ClassBlah()
                  > > > > > {
                  > > > > > }
                  > > > > >
                  > > > > > }
                  > > > > > }
                  > > > > >
                  > > > > > Why have I to call this with the CallingConventi on of ThisCall,[/color][/color][/color]
                  its[color=blue][color=green][color=darkred]
                  > > > just
                  > > > > > normal "C" functions in a DLL. Why wont StdCall work?
                  > > > > >
                  > > > > > What happens with other calling conventions is that the out[/color][/color]
                  > parameters[color=green][color=darkred]
                  > > > are
                  > > > > > NOT set, yet with ThisCall, they are set ok, or appear to be. I[/color][/color][/color]
                  find[color=blue][color=green]
                  > > it[color=darkred]
                  > > > > odd.
                  > > > > >
                  > > > > >
                  > > > > >
                  > > > > > Thanks
                  > > > > >
                  > > > > >
                  > > > >
                  > > > >
                  > > >
                  > > >[/color]
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • Nicholas Paldino [.NET/C# MVP]

                    #10
                    Re: DllImportAttrib ute CallingConventi on

                    Mr.Tickle,

                    In this case, you definitely want to use the int type, and pass it by
                    reference. Your declaration should look like this:

                    [DllImport("some dll.dll")]
                    public static extern int someFn(ref int someIDhere, ref int someIDhere2, ref
                    int someIDhere3);


                    --
                    - Nicholas Paldino [.NET/C# MVP]
                    - nicholas.paldin o@exisconsultin g.com

                    "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                    news:%23h9E8Nuf DHA.3896@tk2msf tngp13.phx.gbl. ..[color=blue]
                    > typedef SOME_ID long
                    >
                    > SOME_ID someFn(SOME_ID* someIDhere, SOME_ID* someIDhere2, SOME_ID*
                    > someIDhere3);
                    >
                    > something like that.
                    >
                    >
                    > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com>[/color]
                    wrote[color=blue]
                    > in message news:OBqOTptfDH A.2748@TK2MSFTN GP11.phx.gbl...[color=green]
                    > > If you could post the original function declaration, it would help
                    > > tremendously.
                    > >
                    > >
                    > > --
                    > > - Nicholas Paldino [.NET/C# MVP]
                    > > - nicholas.paldin o@exisconsultin g.com
                    > >
                    > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                    > > news:e6NNRUtfDH A.2364@TK2MSFTN GP09.phx.gbl...[color=darkred]
                    > > > i mean "out" oops.
                    > > >
                    > > > ref in the same dll wrapper still gets the output but only with[/color][/color][/color]
                    thiscall[color=blue][color=green][color=darkred]
                    > > > convention.
                    > > >
                    > > >
                    > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                    > > > news:OQwh$RtfDH A.2364@TK2MSFTN GP09.phx.gbl...
                    > > > > I also have a problem with "ref" paramaters, it says they need to be
                    > > > > assigned to before used
                    > > > >
                    > > > > Yet i have them used as "ref" in dll extern calls and checked for[/color][/color][/color]
                    non[color=blue][color=green]
                    > > NULL[color=darkred]
                    > > > > after yet it complains for non assignment so i use a local copy.
                    > > > >
                    > > > > Isnt it smart enough to detect that its being assinged in an extern[/color][/color]
                    > dll[color=green][color=darkred]
                    > > > call
                    > > > > as declared in DllImport?
                    > > > >
                    > > > >
                    > > > >
                    > > > >
                    > > > > "Nicholas Paldino [.NET/C# MVP]"[/color][/color][/color]
                    <nicholas.paldi no@exisconsulti ng.com>[color=blue][color=green][color=darkred]
                    > > > wrote
                    > > > > in message news:#pDVIzsfDH A.3324@TK2MSFTN GP11.phx.gbl...
                    > > > > > Mr. Tickle,
                    > > > > >
                    > > > > > What is the declaration of the original function? If it takes[/color][/color][/color]
                    a[color=blue][color=green][color=darkred]
                    > > > > > pointer, then you should be using "ref" for the parameters, and[/color][/color][/color]
                    not[color=blue][color=green]
                    > > out.[color=darkred]
                    > > > > > Also, does the function take a 64-bit integer? Long in C is a[/color][/color]
                    > 32-bit[color=green][color=darkred]
                    > > > > > integer, where in .NET it is a 64-bit integer.
                    > > > > >
                    > > > > > The STDCALL mechanism should work if you are using it.
                    > > > > >
                    > > > > > Hope this helps.
                    > > > > >
                    > > > > >
                    > > > > > --
                    > > > > > - Nicholas Paldino [.NET/C# MVP]
                    > > > > > - nicholas.paldin o@exisconsultin g.com
                    > > > > >
                    > > > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                    > > > > > news:OoNKkNsfDH A.2328@TK2MSFTN GP09.phx.gbl...
                    > > > > > > I am calling an unmanaged DLL like follows in a Class wrapper.
                    > > > > > >
                    > > > > > > namespace blah
                    > > > > > > {
                    > > > > > > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
                    > > > > > > CallingConventi on=CallingConve ntion.ThisCall]
                    > > > > > > public static extern void blahFn(out long blah, out long[/color][/color][/color]
                    blah2);[color=blue][color=green][color=darkred]
                    > > > > > >
                    > > > > > > class sealed ClassBlah
                    > > > > > > {
                    > > > > > > private ClassBlah()
                    > > > > > > {
                    > > > > > > }
                    > > > > > >
                    > > > > > > }
                    > > > > > > }
                    > > > > > >
                    > > > > > > Why have I to call this with the CallingConventi on of ThisCall,[/color][/color]
                    > its[color=green][color=darkred]
                    > > > > just
                    > > > > > > normal "C" functions in a DLL. Why wont StdCall work?
                    > > > > > >
                    > > > > > > What happens with other calling conventions is that the out[/color]
                    > > parameters[color=darkred]
                    > > > > are
                    > > > > > > NOT set, yet with ThisCall, they are set ok, or appear to be. I[/color][/color]
                    > find[color=green][color=darkred]
                    > > > it
                    > > > > > odd.
                    > > > > > >
                    > > > > > >
                    > > > > > >
                    > > > > > > Thanks
                    > > > > > >
                    > > > > > >
                    > > > > >
                    > > > > >
                    > > > >
                    > > > >
                    > > >
                    > > >[/color]
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • Mr.Tickle

                      #11
                      Re: DllImportAttrib ute CallingConventi on

                      But I still dont understand why Thiscall works and the others dont.


                      "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote
                      in message news:uvPKO3ufDH A.1828@TK2MSFTN GP10.phx.gbl...[color=blue]
                      > Mr.Tickle,
                      >
                      > In this case, you definitely want to use the int type, and pass it by
                      > reference. Your declaration should look like this:
                      >
                      > [DllImport("some dll.dll")]
                      > public static extern int someFn(ref int someIDhere, ref int someIDhere2,[/color]
                      ref[color=blue]
                      > int someIDhere3);
                      >
                      >
                      > --
                      > - Nicholas Paldino [.NET/C# MVP]
                      > - nicholas.paldin o@exisconsultin g.com
                      >
                      > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                      > news:%23h9E8Nuf DHA.3896@tk2msf tngp13.phx.gbl. ..[color=green]
                      > > typedef SOME_ID long
                      > >
                      > > SOME_ID someFn(SOME_ID* someIDhere, SOME_ID* someIDhere2, SOME_ID*
                      > > someIDhere3);
                      > >
                      > > something like that.
                      > >
                      > >
                      > > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com>[/color]
                      > wrote[color=green]
                      > > in message news:OBqOTptfDH A.2748@TK2MSFTN GP11.phx.gbl...[color=darkred]
                      > > > If you could post the original function declaration, it would help
                      > > > tremendously.
                      > > >
                      > > >
                      > > > --
                      > > > - Nicholas Paldino [.NET/C# MVP]
                      > > > - nicholas.paldin o@exisconsultin g.com
                      > > >
                      > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                      > > > news:e6NNRUtfDH A.2364@TK2MSFTN GP09.phx.gbl...
                      > > > > i mean "out" oops.
                      > > > >
                      > > > > ref in the same dll wrapper still gets the output but only with[/color][/color]
                      > thiscall[color=green][color=darkred]
                      > > > > convention.
                      > > > >
                      > > > >
                      > > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                      > > > > news:OQwh$RtfDH A.2364@TK2MSFTN GP09.phx.gbl...
                      > > > > > I also have a problem with "ref" paramaters, it says they need to[/color][/color][/color]
                      be[color=blue][color=green][color=darkred]
                      > > > > > assigned to before used
                      > > > > >
                      > > > > > Yet i have them used as "ref" in dll extern calls and checked for[/color][/color]
                      > non[color=green][color=darkred]
                      > > > NULL
                      > > > > > after yet it complains for non assignment so i use a local copy.
                      > > > > >
                      > > > > > Isnt it smart enough to detect that its being assinged in an exter[/color][/color][/color]
                      n[color=blue][color=green]
                      > > dll[color=darkred]
                      > > > > call
                      > > > > > as declared in DllImport?
                      > > > > >
                      > > > > >
                      > > > > >
                      > > > > >
                      > > > > > "Nicholas Paldino [.NET/C# MVP]"[/color][/color]
                      > <nicholas.paldi no@exisconsulti ng.com>[color=green][color=darkred]
                      > > > > wrote
                      > > > > > in message news:#pDVIzsfDH A.3324@TK2MSFTN GP11.phx.gbl...
                      > > > > > > Mr. Tickle,
                      > > > > > >
                      > > > > > > What is the declaration of the original function? If it[/color][/color][/color]
                      takes[color=blue]
                      > a[color=green][color=darkred]
                      > > > > > > pointer, then you should be using "ref" for the parameters, and[/color][/color]
                      > not[color=green][color=darkred]
                      > > > out.
                      > > > > > > Also, does the function take a 64-bit integer? Long in C is a[/color]
                      > > 32-bit[color=darkred]
                      > > > > > > integer, where in .NET it is a 64-bit integer.
                      > > > > > >
                      > > > > > > The STDCALL mechanism should work if you are using it.
                      > > > > > >
                      > > > > > > Hope this helps.
                      > > > > > >
                      > > > > > >
                      > > > > > > --
                      > > > > > > - Nicholas Paldino [.NET/C# MVP]
                      > > > > > > - nicholas.paldin o@exisconsultin g.com
                      > > > > > >
                      > > > > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                      > > > > > > news:OoNKkNsfDH A.2328@TK2MSFTN GP09.phx.gbl...
                      > > > > > > > I am calling an unmanaged DLL like follows in a Class wrapper.
                      > > > > > > >
                      > > > > > > > namespace blah
                      > > > > > > > {
                      > > > > > > > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
                      > > > > > > > CallingConventi on=CallingConve ntion.ThisCall]
                      > > > > > > > public static extern void blahFn(out long blah, out long[/color][/color]
                      > blah2);[color=green][color=darkred]
                      > > > > > > >
                      > > > > > > > class sealed ClassBlah
                      > > > > > > > {
                      > > > > > > > private ClassBlah()
                      > > > > > > > {
                      > > > > > > > }
                      > > > > > > >
                      > > > > > > > }
                      > > > > > > > }
                      > > > > > > >
                      > > > > > > > Why have I to call this with the CallingConventi on of[/color][/color][/color]
                      ThisCall,[color=blue][color=green]
                      > > its[color=darkred]
                      > > > > > just
                      > > > > > > > normal "C" functions in a DLL. Why wont StdCall work?
                      > > > > > > >
                      > > > > > > > What happens with other calling conventions is that the out
                      > > > parameters
                      > > > > > are
                      > > > > > > > NOT set, yet with ThisCall, they are set ok, or appear to be.[/color][/color][/color]
                      I[color=blue][color=green]
                      > > find[color=darkred]
                      > > > > it
                      > > > > > > odd.
                      > > > > > > >
                      > > > > > > >
                      > > > > > > >
                      > > > > > > > Thanks
                      > > > > > > >
                      > > > > > > >
                      > > > > > >
                      > > > > > >
                      > > > > >
                      > > > > >
                      > > > >
                      > > > >
                      > > >
                      > > >[/color]
                      > >
                      > >[/color]
                      >
                      >[/color]


                      Comment

                      • Willy Denoyette [MVP]

                        #12
                        Re: DllImportAttrib ute CallingConventi on

                        Because in you definition you only pass two arguments, while you need tree (an int, and to poiters).
                        It works while using the thiscall calling convention, because the interop layer passes as first argument an int for the this pointer
                        (three int's are reserved on the stack).

                        Willy.

                        "Mr.Tickle" <MrTickle@mrmen .com> wrote in message news:%238biaOvf DHA.3248@tk2msf tngp13.phx.gbl. ..[color=blue]
                        > But I still dont understand why Thiscall works and the others dont.
                        >
                        >
                        > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote
                        > in message news:uvPKO3ufDH A.1828@TK2MSFTN GP10.phx.gbl...[color=green]
                        > > Mr.Tickle,
                        > >
                        > > In this case, you definitely want to use the int type, and pass it by
                        > > reference. Your declaration should look like this:
                        > >
                        > > [DllImport("some dll.dll")]
                        > > public static extern int someFn(ref int someIDhere, ref int someIDhere2,[/color]
                        > ref[color=green]
                        > > int someIDhere3);
                        > >
                        > >
                        > > --
                        > > - Nicholas Paldino [.NET/C# MVP]
                        > > - nicholas.paldin o@exisconsultin g.com
                        > >
                        > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                        > > news:%23h9E8Nuf DHA.3896@tk2msf tngp13.phx.gbl. ..[color=darkred]
                        > > > typedef SOME_ID long
                        > > >
                        > > > SOME_ID someFn(SOME_ID* someIDhere, SOME_ID* someIDhere2, SOME_ID*
                        > > > someIDhere3);
                        > > >
                        > > > something like that.
                        > > >
                        > > >
                        > > > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com>[/color]
                        > > wrote[color=darkred]
                        > > > in message news:OBqOTptfDH A.2748@TK2MSFTN GP11.phx.gbl...
                        > > > > If you could post the original function declaration, it would help
                        > > > > tremendously.
                        > > > >
                        > > > >
                        > > > > --
                        > > > > - Nicholas Paldino [.NET/C# MVP]
                        > > > > - nicholas.paldin o@exisconsultin g.com
                        > > > >
                        > > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                        > > > > news:e6NNRUtfDH A.2364@TK2MSFTN GP09.phx.gbl...
                        > > > > > i mean "out" oops.
                        > > > > >
                        > > > > > ref in the same dll wrapper still gets the output but only with[/color]
                        > > thiscall[color=darkred]
                        > > > > > convention.
                        > > > > >
                        > > > > >
                        > > > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                        > > > > > news:OQwh$RtfDH A.2364@TK2MSFTN GP09.phx.gbl...
                        > > > > > > I also have a problem with "ref" paramaters, it says they need to[/color][/color]
                        > be[color=green][color=darkred]
                        > > > > > > assigned to before used
                        > > > > > >
                        > > > > > > Yet i have them used as "ref" in dll extern calls and checked for[/color]
                        > > non[color=darkred]
                        > > > > NULL
                        > > > > > > after yet it complains for non assignment so i use a local copy.
                        > > > > > >
                        > > > > > > Isnt it smart enough to detect that its being assinged in an exter[/color][/color]
                        > n[color=green][color=darkred]
                        > > > dll
                        > > > > > call
                        > > > > > > as declared in DllImport?
                        > > > > > >
                        > > > > > >
                        > > > > > >
                        > > > > > >
                        > > > > > > "Nicholas Paldino [.NET/C# MVP]"[/color]
                        > > <nicholas.paldi no@exisconsulti ng.com>[color=darkred]
                        > > > > > wrote
                        > > > > > > in message news:#pDVIzsfDH A.3324@TK2MSFTN GP11.phx.gbl...
                        > > > > > > > Mr. Tickle,
                        > > > > > > >
                        > > > > > > > What is the declaration of the original function? If it[/color][/color]
                        > takes[color=green]
                        > > a[color=darkred]
                        > > > > > > > pointer, then you should be using "ref" for the parameters, and[/color]
                        > > not[color=darkred]
                        > > > > out.
                        > > > > > > > Also, does the function take a 64-bit integer? Long in C is a
                        > > > 32-bit
                        > > > > > > > integer, where in .NET it is a 64-bit integer.
                        > > > > > > >
                        > > > > > > > The STDCALL mechanism should work if you are using it.
                        > > > > > > >
                        > > > > > > > Hope this helps.
                        > > > > > > >
                        > > > > > > >
                        > > > > > > > --
                        > > > > > > > - Nicholas Paldino [.NET/C# MVP]
                        > > > > > > > - nicholas.paldin o@exisconsultin g.com
                        > > > > > > >
                        > > > > > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                        > > > > > > > news:OoNKkNsfDH A.2328@TK2MSFTN GP09.phx.gbl...
                        > > > > > > > > I am calling an unmanaged DLL like follows in a Class wrapper.
                        > > > > > > > >
                        > > > > > > > > namespace blah
                        > > > > > > > > {
                        > > > > > > > > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
                        > > > > > > > > CallingConventi on=CallingConve ntion.ThisCall]
                        > > > > > > > > public static extern void blahFn(out long blah, out long[/color]
                        > > blah2);[color=darkred]
                        > > > > > > > >
                        > > > > > > > > class sealed ClassBlah
                        > > > > > > > > {
                        > > > > > > > > private ClassBlah()
                        > > > > > > > > {
                        > > > > > > > > }
                        > > > > > > > >
                        > > > > > > > > }
                        > > > > > > > > }
                        > > > > > > > >
                        > > > > > > > > Why have I to call this with the CallingConventi on of[/color][/color]
                        > ThisCall,[color=green][color=darkred]
                        > > > its
                        > > > > > > just
                        > > > > > > > > normal "C" functions in a DLL. Why wont StdCall work?
                        > > > > > > > >
                        > > > > > > > > What happens with other calling conventions is that the out
                        > > > > parameters
                        > > > > > > are
                        > > > > > > > > NOT set, yet with ThisCall, they are set ok, or appear to be.[/color][/color]
                        > I[color=green][color=darkred]
                        > > > find
                        > > > > > it
                        > > > > > > > odd.
                        > > > > > > > >
                        > > > > > > > >
                        > > > > > > > >
                        > > > > > > > > Thanks
                        > > > > > > > >
                        > > > > > > > >
                        > > > > > > >
                        > > > > > > >
                        > > > > > >
                        > > > > > >
                        > > > > >
                        > > > > >
                        > > > >
                        > > > >
                        > > >
                        > > >[/color]
                        > >
                        > >[/color]
                        >
                        >[/color]


                        Comment

                        • Mr.Tickle

                          #13
                          Re: DllImportAttrib ute CallingConventi on

                          Well its suppost to match up, its just something i typed in a hurry but it
                          is the same number of arguments in the definition and call. on teh real
                          code.


                          the dll definition would be

                          typedef SOMEVAL long
                          typedef SOME_ID long

                          SOME_ID someFn(SOMEVAL someVal, SOME_ID* someIDhere, SOME_ID* someIDhere2,
                          SOME_ID* someIDhere3);


                          so im calling with for example out of my memory

                          DllImport("some dll.dll", EntryPoint="bla hFn",
                          CallingConventi on=CallingConve ntion.ThisCall)]
                          public static extern int someFn(long someVal, ref someIDhere, ref long
                          someIDhere2, ref long someIDhere3);
                          // i know this should be int instead of long but curious why the long works
                          with thiscall and not the others or just not work at all.

                          long someVal;
                          long ID someID,
                          anotherID,
                          yetAnohterID,
                          andAnotherID;

                          someID = blahFn(someVal, ref anotherID, ref yetAnotherID, ref andAnotherID);

                          Only thiscall works, others dont, so if i understand it right I change the
                          definition from long to int for 32bit instead of the 64bit on the .net side,
                          and then i can use stdcall as normal.




                          "Willy Denoyette [MVP]" <willy.denoyett e@pandora.be> wrote in message
                          news:OEKHFc2fDH A.3216@tk2msftn gp13.phx.gbl...[color=blue]
                          > Because in you definition you only pass two arguments, while you need tree[/color]
                          (an int, and to poiters).[color=blue]
                          > It works while using the thiscall calling convention, because the interop[/color]
                          layer passes as first argument an int for the this pointer[color=blue]
                          > (three int's are reserved on the stack).
                          >
                          > Willy.
                          >
                          > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message[/color]
                          news:%238biaOvf DHA.3248@tk2msf tngp13.phx.gbl. ..[color=blue][color=green]
                          > > But I still dont understand why Thiscall works and the others dont.
                          > >
                          > >
                          > > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com>[/color][/color]
                          wrote[color=blue][color=green]
                          > > in message news:uvPKO3ufDH A.1828@TK2MSFTN GP10.phx.gbl...[color=darkred]
                          > > > Mr.Tickle,
                          > > >
                          > > > In this case, you definitely want to use the int type, and pass it[/color][/color][/color]
                          by[color=blue][color=green][color=darkred]
                          > > > reference. Your declaration should look like this:
                          > > >
                          > > > [DllImport("some dll.dll")]
                          > > > public static extern int someFn(ref int someIDhere, ref int[/color][/color][/color]
                          someIDhere2,[color=blue][color=green]
                          > > ref[color=darkred]
                          > > > int someIDhere3);
                          > > >
                          > > >
                          > > > --
                          > > > - Nicholas Paldino [.NET/C# MVP]
                          > > > - nicholas.paldin o@exisconsultin g.com
                          > > >
                          > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                          > > > news:%23h9E8Nuf DHA.3896@tk2msf tngp13.phx.gbl. ..
                          > > > > typedef SOME_ID long
                          > > > >
                          > > > > SOME_ID someFn(SOME_ID* someIDhere, SOME_ID* someIDhere2, SOME_ID*
                          > > > > someIDhere3);
                          > > > >
                          > > > > something like that.
                          > > > >
                          > > > >
                          > > > > "Nicholas Paldino [.NET/C# MVP]"[/color][/color][/color]
                          <nicholas.paldi no@exisconsulti ng.com>[color=blue][color=green][color=darkred]
                          > > > wrote
                          > > > > in message news:OBqOTptfDH A.2748@TK2MSFTN GP11.phx.gbl...
                          > > > > > If you could post the original function declaration, it would[/color][/color][/color]
                          help[color=blue][color=green][color=darkred]
                          > > > > > tremendously.
                          > > > > >
                          > > > > >
                          > > > > > --
                          > > > > > - Nicholas Paldino [.NET/C# MVP]
                          > > > > > - nicholas.paldin o@exisconsultin g.com
                          > > > > >
                          > > > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                          > > > > > news:e6NNRUtfDH A.2364@TK2MSFTN GP09.phx.gbl...
                          > > > > > > i mean "out" oops.
                          > > > > > >
                          > > > > > > ref in the same dll wrapper still gets the output but only with
                          > > > thiscall
                          > > > > > > convention.
                          > > > > > >
                          > > > > > >
                          > > > > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                          > > > > > > news:OQwh$RtfDH A.2364@TK2MSFTN GP09.phx.gbl...
                          > > > > > > > I also have a problem with "ref" paramaters, it says they need[/color][/color][/color]
                          to[color=blue][color=green]
                          > > be[color=darkred]
                          > > > > > > > assigned to before used
                          > > > > > > >
                          > > > > > > > Yet i have them used as "ref" in dll extern calls and checked[/color][/color][/color]
                          for[color=blue][color=green][color=darkred]
                          > > > non
                          > > > > > NULL
                          > > > > > > > after yet it complains for non assignment so i use a local[/color][/color][/color]
                          copy.[color=blue][color=green][color=darkred]
                          > > > > > > >
                          > > > > > > > Isnt it smart enough to detect that its being assinged in an[/color][/color][/color]
                          exter[color=blue][color=green]
                          > > n[color=darkred]
                          > > > > dll
                          > > > > > > call
                          > > > > > > > as declared in DllImport?
                          > > > > > > >
                          > > > > > > >
                          > > > > > > >
                          > > > > > > >
                          > > > > > > > "Nicholas Paldino [.NET/C# MVP]"
                          > > > <nicholas.paldi no@exisconsulti ng.com>
                          > > > > > > wrote
                          > > > > > > > in message news:#pDVIzsfDH A.3324@TK2MSFTN GP11.phx.gbl...
                          > > > > > > > > Mr. Tickle,
                          > > > > > > > >
                          > > > > > > > > What is the declaration of the original function? If it[/color]
                          > > takes[color=darkred]
                          > > > a
                          > > > > > > > > pointer, then you should be using "ref" for the parameters,[/color][/color][/color]
                          and[color=blue][color=green][color=darkred]
                          > > > not
                          > > > > > out.
                          > > > > > > > > Also, does the function take a 64-bit integer? Long in C is[/color][/color][/color]
                          a[color=blue][color=green][color=darkred]
                          > > > > 32-bit
                          > > > > > > > > integer, where in .NET it is a 64-bit integer.
                          > > > > > > > >
                          > > > > > > > > The STDCALL mechanism should work if you are using it.
                          > > > > > > > >
                          > > > > > > > > Hope this helps.
                          > > > > > > > >
                          > > > > > > > >
                          > > > > > > > > --
                          > > > > > > > > - Nicholas Paldino [.NET/C# MVP]
                          > > > > > > > > - nicholas.paldin o@exisconsultin g.com
                          > > > > > > > >
                          > > > > > > > > "Mr.Tickle" <MrTickle@mrmen .com> wrote in message
                          > > > > > > > > news:OoNKkNsfDH A.2328@TK2MSFTN GP09.phx.gbl...
                          > > > > > > > > > I am calling an unmanaged DLL like follows in a Class[/color][/color][/color]
                          wrapper.[color=blue][color=green][color=darkred]
                          > > > > > > > > >
                          > > > > > > > > > namespace blah
                          > > > > > > > > > {
                          > > > > > > > > > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
                          > > > > > > > > > CallingConventi on=CallingConve ntion.ThisCall]
                          > > > > > > > > > public static extern void blahFn(out long blah, out long
                          > > > blah2);
                          > > > > > > > > >
                          > > > > > > > > > class sealed ClassBlah
                          > > > > > > > > > {
                          > > > > > > > > > private ClassBlah()
                          > > > > > > > > > {
                          > > > > > > > > > }
                          > > > > > > > > >
                          > > > > > > > > > }
                          > > > > > > > > > }
                          > > > > > > > > >
                          > > > > > > > > > Why have I to call this with the CallingConventi on of[/color]
                          > > ThisCall,[color=darkred]
                          > > > > its
                          > > > > > > > just
                          > > > > > > > > > normal "C" functions in a DLL. Why wont StdCall work?
                          > > > > > > > > >
                          > > > > > > > > > What happens with other calling conventions is that the[/color][/color][/color]
                          out[color=blue][color=green][color=darkred]
                          > > > > > parameters
                          > > > > > > > are
                          > > > > > > > > > NOT set, yet with ThisCall, they are set ok, or appear to[/color][/color][/color]
                          be.[color=blue][color=green]
                          > > I[color=darkred]
                          > > > > find
                          > > > > > > it
                          > > > > > > > > odd.
                          > > > > > > > > >
                          > > > > > > > > >
                          > > > > > > > > >
                          > > > > > > > > > Thanks
                          > > > > > > > > >
                          > > > > > > > > >
                          > > > > > > > >
                          > > > > > > > >
                          > > > > > > >
                          > > > > > > >
                          > > > > > >
                          > > > > > >
                          > > > > >
                          > > > > >
                          > > > >
                          > > > >
                          > > >
                          > > >[/color]
                          > >
                          > >[/color]
                          >
                          >[/color]


                          Comment

                          Working...