Winsock active-x requires object reference?

  • Thread starter Thread starter Richy
  • Start date Start date
R

Richy

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.SendData( buffer);

But to receive isn't as easy.

The prototype is show below:

axWinsock1.GetData( ref object data, object type, object
MaxLen)

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

axWinsock1.GetData( 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.SendData( object data )

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

Richy.
 
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
 
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?
-----Original Message-----
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 said:
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.SendData( buffer);

But to receive isn't as easy.

The prototype is show below:

axWinsock1.GetData( ref object data, object type, object
MaxLen)

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

axWinsock1.GetData( 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.SendData( object data )

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

Richy.


.
 
Richy said:
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.SendData( buffer);

But to receive isn't as easy.

The prototype is show below:

axWinsock1.GetData( ref object data, object type, object
MaxLen)

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

axWinsock1.GetData( ref buffer, buffer.GetType(), 10 );

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.GetData(ref o,buffer.GetType(),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.
 
Richy said:
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?

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.
-----Original Message-----
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 said:
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.SendData( buffer);

But to receive isn't as easy.

The prototype is show below:

axWinsock1.GetData( ref object data, object type, object
MaxLen)

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

axWinsock1.GetData( 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.SendData( object data )

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

Richy.


.
 
thanks Kieran & Daniel for the input - guess it's time to
move onto the framework classes ;-)
 
Richy said:
thanks Kieran & Daniel for the input - guess it's time to
move onto the framework classes ;-)

np, hope I didn't sound to harsh, I'm really rather tired, -_-
-----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.SendData( buffer);

But to receive isn't as easy.

The prototype is show below:

axWinsock1.GetData( ref object data, object type, object
MaxLen)

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

axWinsock1.GetData( 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.SendData( object data )

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

Richy.

.
 
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 said:
thanks Kieran & Daniel for the input - guess it's time to
move onto the framework classes ;-)
-----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.SendData( buffer);

But to receive isn't as easy.

The prototype is show below:

axWinsock1.GetData( ref object data, object type, object
MaxLen)

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

axWinsock1.GetData( 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.SendData( object data )

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

Richy.

.
 
Back
Top