Winsock active-x requires object reference?

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

    #1

    Winsock active-x requires object reference?

    Hi,

    I'm using a winsock active-x component in a C# program.

    I can send data using the following:

    byte[] buffer = new byte[10];
    axWinsock1.Send Data( buffer);

    But to receive isn't as easy.

    The prototype is show below:

    axWinsock1.GetD ata( ref object data, object type, object
    MaxLen)

    I cannot pass buffer in as a parameter, see below.

    axWinsock1.GetD ata( ref buffer, buffer.GetType( ), 10 );

    The compiler complains that it is expecting a reference to
    an object as the first parameter. But it doesn't
    complain about the send equivalent which is also of type
    object, see below:

    axWinsock1.Send Data( object data )

    Any one know how I would receive using axWinsock1.GetD ata
    into an array of bytes?

    Richy.

  • Kieran Benton

    #2
    Re: Winsock active-x requires object reference?

    Richy,

    Why are you using an ActiveX control when you could be using the built in
    functionailty of the .NET Framework classes? Look into the classes Socket,
    TcpClient & TcpListener in the help. They will be able to do what you want
    to do without any interop nastiness and the overhead of ActiveX.

    HTH
    Kieran

    "Richy" <richyrich_n200 2@yahoo.co.uk> wrote in message
    news:289101c373 93$65e57870$a50 1280a@phx.gbl.. .[color=blue]
    > Hi,
    >
    > I'm using a winsock active-x component in a C# program.
    >
    > I can send data using the following:
    >
    > byte[] buffer = new byte[10];
    > axWinsock1.Send Data( buffer);
    >
    > But to receive isn't as easy.
    >
    > The prototype is show below:
    >
    > axWinsock1.GetD ata( ref object data, object type, object
    > MaxLen)
    >
    > I cannot pass buffer in as a parameter, see below.
    >
    > axWinsock1.GetD ata( ref buffer, buffer.GetType( ), 10 );
    >
    > The compiler complains that it is expecting a reference to
    > an object as the first parameter. But it doesn't
    > complain about the send equivalent which is also of type
    > object, see below:
    >
    > axWinsock1.Send Data( object data )
    >
    > Any one know how I would receive using axWinsock1.GetD ata
    > into an array of bytes?
    >
    > Richy.
    >[/color]


    Comment

    • Richy.

      #3
      Winsock active-x requires object reference?

      found someone with the same problem.


      exchange.com/Programming/Programming_Lan guages/C_Sharp/Q_20
      697280.html

      problem is, what is the solution.

      [color=blue]
      >-----Original Message-----
      >Hi,
      >
      >I'm using a winsock active-x component in a C# program.
      >
      >I can send data using the following:
      >
      >byte[] buffer = new byte[10];
      >axWinsock1.Sen dData( buffer);
      >
      >But to receive isn't as easy.
      >
      >The prototype is show below:
      >
      >axWinsock1.Get Data( ref object data, object type, object
      >MaxLen)
      >
      >I cannot pass buffer in as a parameter, see below.
      >
      >axWinsock1.Get Data( ref buffer, buffer.GetType( ), 10 );
      >
      >The compiler complains that it is expecting a reference[/color]
      to[color=blue]
      >an object as the first parameter. But it doesn't
      >complain about the send equivalent which is also of type
      >object, see below:
      >
      >axWinsock1.Sen dData( object data )
      >
      >Any one know how I would receive using axWinsock1.GetD ata
      >into an array of bytes?
      >
      >Richy.
      >
      >.
      >[/color]

      Comment

      • Richy

        #4
        Re: Winsock active-x requires object reference?

        I have tried that, but it blocks when it is receiving data.

        The Active-X provides a Data Arrival Event, preventing my
        application from hanging.

        What is the point of having Active-X if you cannot use
        them?
        [color=blue]
        >-----Original Message-----
        >Richy,
        >
        >Why are you using an ActiveX control when you could be[/color]
        using the built in[color=blue]
        >functionailt y of the .NET Framework classes? Look into[/color]
        the classes Socket,[color=blue]
        >TcpClient & TcpListener in the help. They will be able to[/color]
        do what you want[color=blue]
        >to do without any interop nastiness and the overhead of[/color]
        ActiveX.[color=blue]
        >
        >HTH
        >Kieran
        >
        >"Richy" <richyrich_n200 2@yahoo.co.uk> wrote in message
        >news:289101c37 393$65e57870$a5 01280a@phx.gbl. ..[color=green]
        >> Hi,
        >>
        >> I'm using a winsock active-x component in a C# program.
        >>
        >> I can send data using the following:
        >>
        >> byte[] buffer = new byte[10];
        >> axWinsock1.Send Data( buffer);
        >>
        >> But to receive isn't as easy.
        >>
        >> The prototype is show below:
        >>
        >> axWinsock1.GetD ata( ref object data, object type, object
        >> MaxLen)
        >>
        >> I cannot pass buffer in as a parameter, see below.
        >>
        >> axWinsock1.GetD ata( ref buffer, buffer.GetType( ), 10 );
        >>
        >> The compiler complains that it is expecting a reference[/color][/color]
        to[color=blue][color=green]
        >> an object as the first parameter. But it doesn't
        >> complain about the send equivalent which is also of type
        >> object, see below:
        >>
        >> axWinsock1.Send Data( object data )
        >>
        >> Any one know how I would receive using[/color][/color]
        axWinsock1.GetD ata[color=blue][color=green]
        >> into an array of bytes?
        >>
        >> Richy.
        >>[/color]
        >
        >
        >.
        >[/color]

        Comment

        • Daniel O'Connell

          #5
          Re: Winsock active-x requires object reference?


          "Richy" <richyrich_n200 2@yahoo.co.uk> wrote in message
          news:289101c373 93$65e57870$a50 1280a@phx.gbl.. .[color=blue]
          > Hi,
          >
          > I'm using a winsock active-x component in a C# program.
          >
          > I can send data using the following:
          >
          > byte[] buffer = new byte[10];
          > axWinsock1.Send Data( buffer);
          >
          > But to receive isn't as easy.
          >
          > The prototype is show below:
          >
          > axWinsock1.GetD ata( ref object data, object type, object
          > MaxLen)
          >
          > I cannot pass buffer in as a parameter, see below.
          >
          > axWinsock1.GetD ata( ref buffer, buffer.GetType( ), 10 );
          >[/color]

          While I agree with Kieran, you should be using the framework classes, there
          is absolutly no need to interop with the winsock activex control, but here
          is my suggestion anyawy (also, is type really supposed to be the object
          type? doesn't sound right to me):
          object o = (object)buffer;
          axWinsock1.GetD ata(ref o,buffer.GetTyp e(),10);

          I don't know if it will work, don't have time to try, but thats often what
          you have to do in other interop situations.
          [color=blue]
          > The compiler complains that it is expecting a reference to
          > an object as the first parameter. But it doesn't
          > complain about the send equivalent which is also of type
          > object, see below:
          >
          > axWinsock1.Send Data( object data )
          >
          > Any one know how I would receive using axWinsock1.GetD ata
          > into an array of bytes?
          >
          > Richy.
          >[/color]


          Comment

          • Daniel O'Connell

            #6
            Re: Winsock active-x requires object reference?


            "Richy" <richyrich_n200 2@yahoo.co.uk> wrote in message
            news:1e5901c373 a1$3c647010$a10 1280a@phx.gbl.. .[color=blue]
            > I have tried that, but it blocks when it is receiving data.
            >
            > The Active-X provides a Data Arrival Event, preventing my
            > application from hanging.
            >
            > What is the point of having Active-X if you cannot use
            > them?
            >[/color]

            One word, LEGACY. Its not there for any other reason, imho. They are messy
            to use when managed equivilents exist.

            As for blocking IO, thats why various BeginXXX methods exist, they are
            asynchronous and you can provide callbacks that are called when the
            asynchronous method finishes.

            For TcpClient, for example, returns a NetworkStream, NetworkStream has a
            BeginRead method that is asynchronous, most of the other classes should have
            it as well, read up on it.
            [color=blue][color=green]
            > >-----Original Message-----
            > >Richy,
            > >
            > >Why are you using an ActiveX control when you could be[/color]
            > using the built in[color=green]
            > >functionailt y of the .NET Framework classes? Look into[/color]
            > the classes Socket,[color=green]
            > >TcpClient & TcpListener in the help. They will be able to[/color]
            > do what you want[color=green]
            > >to do without any interop nastiness and the overhead of[/color]
            > ActiveX.[color=green]
            > >
            > >HTH
            > >Kieran
            > >
            > >"Richy" <richyrich_n200 2@yahoo.co.uk> wrote in message
            > >news:289101c37 393$65e57870$a5 01280a@phx.gbl. ..[color=darkred]
            > >> Hi,
            > >>
            > >> I'm using a winsock active-x component in a C# program.
            > >>
            > >> I can send data using the following:
            > >>
            > >> byte[] buffer = new byte[10];
            > >> axWinsock1.Send Data( buffer);
            > >>
            > >> But to receive isn't as easy.
            > >>
            > >> The prototype is show below:
            > >>
            > >> axWinsock1.GetD ata( ref object data, object type, object
            > >> MaxLen)
            > >>
            > >> I cannot pass buffer in as a parameter, see below.
            > >>
            > >> axWinsock1.GetD ata( ref buffer, buffer.GetType( ), 10 );
            > >>
            > >> The compiler complains that it is expecting a reference[/color][/color]
            > to[color=green][color=darkred]
            > >> an object as the first parameter. But it doesn't
            > >> complain about the send equivalent which is also of type
            > >> object, see below:
            > >>
            > >> axWinsock1.Send Data( object data )
            > >>
            > >> Any one know how I would receive using[/color][/color]
            > axWinsock1.GetD ata[color=green][color=darkred]
            > >> into an array of bytes?
            > >>
            > >> Richy.
            > >>[/color]
            > >
            > >
            > >.
            > >[/color][/color]


            Comment

            • Richy

              #7
              Winsock active-x requires object reference?


              thanks Kieran & Daniel for the input - guess it's time to
              move onto the framework classes ;-)
              [color=blue]
              >-----Original Message-----
              >Hi,
              >
              >I'm using a winsock active-x component in a C# program.
              >
              >I can send data using the following:
              >
              >byte[] buffer = new byte[10];
              >axWinsock1.Sen dData( buffer);
              >
              >But to receive isn't as easy.
              >
              >The prototype is show below:
              >
              >axWinsock1.Get Data( ref object data, object type, object
              >MaxLen)
              >
              >I cannot pass buffer in as a parameter, see below.
              >
              >axWinsock1.Get Data( ref buffer, buffer.GetType( ), 10 );
              >
              >The compiler complains that it is expecting a reference[/color]
              to[color=blue]
              >an object as the first parameter. But it doesn't
              >complain about the send equivalent which is also of type
              >object, see below:
              >
              >axWinsock1.Sen dData( object data )
              >
              >Any one know how I would receive using axWinsock1.GetD ata
              >into an array of bytes?
              >
              >Richy.
              >
              >.
              >[/color]

              Comment

              • Daniel O'Connell

                #8
                Re: Winsock active-x requires object reference?


                "Richy" <richyrich_n200 2@yahoo.co.uk> wrote in message
                news:2aa201c373 a3$49374bd0$a60 1280a@phx.gbl.. .[color=blue]
                >
                > thanks Kieran & Daniel for the input - guess it's time to
                > move onto the framework classes ;-)
                >[/color]

                np, hope I didn't sound to harsh, I'm really rather tired, -_-
                [color=blue][color=green]
                > >-----Original Message-----
                > >Hi,
                > >
                > >I'm using a winsock active-x component in a C# program.
                > >
                > >I can send data using the following:
                > >
                > >byte[] buffer = new byte[10];
                > >axWinsock1.Sen dData( buffer);
                > >
                > >But to receive isn't as easy.
                > >
                > >The prototype is show below:
                > >
                > >axWinsock1.Get Data( ref object data, object type, object
                > >MaxLen)
                > >
                > >I cannot pass buffer in as a parameter, see below.
                > >
                > >axWinsock1.Get Data( ref buffer, buffer.GetType( ), 10 );
                > >
                > >The compiler complains that it is expecting a reference[/color]
                > to[color=green]
                > >an object as the first parameter. But it doesn't
                > >complain about the send equivalent which is also of type
                > >object, see below:
                > >
                > >axWinsock1.Sen dData( object data )
                > >
                > >Any one know how I would receive using axWinsock1.GetD ata
                > >into an array of bytes?
                > >
                > >Richy.
                > >
                > >.
                > >[/color][/color]


                Comment

                • Kieran Benton

                  #9
                  Re: Winsock active-x requires object reference?

                  Richy,
                  Sounds like a plan to me :) They really are much cleaner to use and probably
                  more efficient.

                  Hope you've got it working now anyway.

                  Kieran

                  "Richy" <richyrich_n200 2@yahoo.co.uk> wrote in message
                  news:2aa201c373 a3$49374bd0$a60 1280a@phx.gbl.. .[color=blue]
                  >
                  > thanks Kieran & Daniel for the input - guess it's time to
                  > move onto the framework classes ;-)
                  >[color=green]
                  > >-----Original Message-----
                  > >Hi,
                  > >
                  > >I'm using a winsock active-x component in a C# program.
                  > >
                  > >I can send data using the following:
                  > >
                  > >byte[] buffer = new byte[10];
                  > >axWinsock1.Sen dData( buffer);
                  > >
                  > >But to receive isn't as easy.
                  > >
                  > >The prototype is show below:
                  > >
                  > >axWinsock1.Get Data( ref object data, object type, object
                  > >MaxLen)
                  > >
                  > >I cannot pass buffer in as a parameter, see below.
                  > >
                  > >axWinsock1.Get Data( ref buffer, buffer.GetType( ), 10 );
                  > >
                  > >The compiler complains that it is expecting a reference[/color]
                  > to[color=green]
                  > >an object as the first parameter. But it doesn't
                  > >complain about the send equivalent which is also of type
                  > >object, see below:
                  > >
                  > >axWinsock1.Sen dData( object data )
                  > >
                  > >Any one know how I would receive using axWinsock1.GetD ata
                  > >into an array of bytes?
                  > >
                  > >Richy.
                  > >
                  > >.
                  > >[/color][/color]


                  Comment

                  Working...