I'm pretty new to C#, but I've used winsock in VB a lot in the past, anyways, the problem is, I can't get .GetData to work.

private void axWinsock1_DataArrival(object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e)
        {
            string R_DATA;
            axWinsock1.GetData(R_DATA);
        }

Gives error: 'Cannot convert string to ref object'

Or

private void axWinsock1_DataArrival(object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e)
        {
            string RSS_DATA;
            int bt;
            bt = e.bytesTotal;
            axWinsock1.GetData (RSS_DATA, String, bt);
            
        }

Gives error: 'String is a type but used like a variable'

What am I doing wrong???

I'm pretty new to C#, but I've used winsock in VB a lot in the past, anyways, the problem is, I can't get .GetData to work.

private void axWinsock1_DataArrival(object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e)
        {
            string R_DATA;
            axWinsock1.GetData(R_DATA);
        }

Gives error: 'Cannot convert string to ref object'

Or

private void axWinsock1_DataArrival(object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e)
        {
            string RSS_DATA;
            int bt;
            bt = e.bytesTotal;
            axWinsock1.GetData (RSS_DATA, String, bt);
            
        }

Gives error: 'String is a type but used like a variable'

What am I doing wrong???

Hi, this way:

private void axWinsock1_DataArrival(object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e)
{
    object objdata;
    axWinsock1.GetData(ref objdata); // i'm not sure of "ref",
      // if doesn't work, cut off
    // then process:
    processData((string)objdata); // void processData(string data)
}

I hope it helps you..

C# is less forgiving than VB in terms of lazy programming. In C# if a method signature has a parameter designated as 'ref' or 'out' then when you call that method (as in you call the winsock.GetData then you have to declare your parameter as 'ref' or 'out' also. This is telling everyone you understand what you are doing (allegedly hahaha) and know what params are being passed and what you expect out. Also any method you call has to have () after it if there are no params whereas vb adds them for you i think (or doesnt insist on it). Like i said, VB allows lazy programming which in turn allows for some unexpected results. For instance, you dont have to have Option Explicit and Options Strict on (I think strict is off by default which is bad but i think you can change it on your ide options). C# doesnt even give you those options - and quite right too.

Hi, this way:

private void axWinsock1_DataArrival(object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e)
{
    object objdata;
    axWinsock1.GetData(ref objdata); // i'm not sure of "ref",
      // if doesn't work, cut off
    // then process:
    processData((string)objdata); // void processData(string data)
}

I hope it helps you..

Thank you for your help,but no other code is processed after GetData method. Also "object objdata;" doesn't work, I get error "Use of unassigned local variable 'objData'"...I solved it this way (don't know if it's OK): "Object objData = new System.Object();"
So the code looks like thit:

private void DataLink_DataArrival(object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e) {
  Object objData = new System.Object();
  /* This doesn't work as well :-/
    DataLink.GetData(ref objData, DataLink.GetType, e.bytesTotal);
  */
  DataLink.GetData(ref objData);
  string strData = (string)objData;
  txtDataLink.Text = strData;
}

The lines below "DataLink.GetData(ref objData);" are ignored. Any suggestions how to solve this? Thanx for answer ;-)

Hi,

If you aren't porting old code (actually even if you do so), or has a valid reason to use that ActiveX control, you would be much better off using System.Net classes performance and debug wise.

Loren Soth

Thank you for your help,but no other code is processed after GetData method. Also "object objdata;" doesn't work, I get error "Use of unassigned local variable 'objData'"...I solved it this way (don't know if it's OK): "Object objData = new System.Object();"
So the code looks like thit:

private void DataLink_DataArrival(object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e) {
  Object objData = new System.Object();
  /* This doesn't work as well :-/
    DataLink.GetData(ref objData, DataLink.GetType, e.bytesTotal);
  */
  DataLink.GetData(ref objData);
  string strData = (string)objData;
  txtDataLink.Text = strData;
}

The lines below "DataLink.GetData(ref objData);" are ignored. Any suggestions how to solve this? Thanx for answer ;-)

DataLink.GetData(ref objData);
Fix this line to
DataLink.GetData(ref objData , 8 , e.bytesTotal);

string strData = (string)objData;
txtDataLink.Text = strData;


because , Winsock is work for VB 6.0 then datatype is base on VB 6 data type
in this case i want to try datatype in "String" for VB 6 use vbString constant
and vbString = 8
if you want to change to other datatype , find information about vb 6 datatype again.

truebot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.