is there a way to reference a dll and it's events in c#?

dynamic_sysop

Senior Contributor
Joined
Oct 1, 2002
Messages
1,039
Location
Ashby, Leicestershire.
i have a dll which i use in vb.net without a problem , but i want to try it in c#, i've added a reference , then at the top of the form got...
using SOCK; //this is the name of the dll.
then i've tried ...
this.SOCK // but it doesnt do anything
any advice on how i can reference my dll and get it to actually do something would be great ty.
 
i tried this...
Visual Basic:
using SOCK;
///
this.On_Connect += new SOCK.__Socket_OnConnectEventHandler(this.On_Connect);
/// highlights this >>> this.On_Connect <<<
///
		private void On_Connect(object sender, SOCK.__Socket_OnConnectEventHandler e)
		{

		}
i cant get it to do "this.SOCK" etc
 
Did you try it without the "this" referece? To use this you need to create an instance of a class SOCK before you can use it, unless it's members are static. Then you use this to access the instance of the new SOCK object you just created.
Ex:
C#:
TheNamespace
{
    public class TheClass : Form
   {
      SOCK sock; // Member of the class- new SOCK instance
       
      public TheClass() // Constructor
      {
          this.sock = new SOCK(); // Initialize the sock instance
          this.sock.TheListShouldPopUpHere // Now you can use it
      }
   }
}
 
cheers for the reply , i'm nearly there but i get this:
Visual Basic:
			this.socket = new SOCK.SocketClass();
			this.socket.OnConnect += new SOCK.__Socket_OnConnectEventHandler (this.On_Connect);
/// this i have in the designer area
/// this line >> this.On_Connect << gets highlighted still
///
/// this is my code in the form...
		private void On_Connect(object sender, SOCK.__Socket_OnConnectEventHandler e)
		{

		}
no matter how i change it always the same line gets highlighted:-\
 
to elaberate further , this is the error message i'm getting
Visual Basic:
: Method 'WindowsApplication3.Form1.On_Connect(object, SOCK.__Socket_OnConnectEventHandler)' does not match delegate 'void SOCK.__Socket_OnConnectEventHandler()'
 
Private void On_Connect(Object sender, SOCK.__Socket_OnConnectEventHandler e)
{}

The argument in bold is wrong. There should be some kind of EventArgs argument not EventHandler.
 
You can use your object browser to find the delegate type and see exactly what your method signature should be.
 
cheers divil, i found this:

public sealed delegate __Socket_OnConnectEventHandler : System.MulticastDelegate
Member of SOCK

but no matter how i impliment it nothing matters it still throws an error. so i'm not sure if it will run.
 
nope but i did this:
Visual Basic:
this.socket.OnConnect += new SOCK.__Socket_OnConnectEventHandler (this.OnConnect());
///
		private void OnConnect()
		{
        
		}
that stops an error showing, but when i send OnConnect(); from a button and try to connect my socket it says cannot change ref object to string :-\
it should do this:
Visual Basic:
socket.Connect("remote host here" , "remote port here");
 
Apparently, the parameter is a reference to an object, so create a variable and pass that variable by reference to the sub.

C# code for this, I don't know VB syntax well enouph.
string s="Hi";
socket.Connect(ref s, "remote port here");
 
Back
Top