Results 1 to 12 of 12

Thread: function

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207

    function

    Hi,

    I have a function contained in a dll file that was written in vb.net. I can invoke methods in this dll ex. mydll.write(data). The problem I am having is that this dll also raises an event but I can't seem to figure out how to get this event trigged in c#.

    Any help would be appreciated.

    Jeremy

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    yourdll.EventName += new System.EventHandler(this.A_routinename);

    then just add your event

    void A_routinename(parameters)
    {

    }
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    still can't seem to get it. Here is the code that I am working with and the attatched dll.

    PHP Code:
            static void Main(string[] args)
            {
                
    System.Windows.Forms.Form holder = new hold();
                
    JWM.Net.UDP network  = new JWM.Net.UDP();
            
                
    network.Listen(514);
                
                
    network.DataArrival += new System.EventHandler(this.iData);
                
    //yourdll.EventName += new System.EventHandler(this.A_routinename);

                
    nsender.Send("127.0.0.1",514,Console.ReadLine());            
            }

            static 
    void iData(string data)
            {
                
    Console.WriteLine(data);        
            } 

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    opps forgot the file.
    Attached Files Attached Files

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you need to do some debugging to see if the event is being raised by the dll.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  6. #6
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    To add to what cander said. What is the criteria for this event being fired? There should be some type of test to fire the event base on the results. Then when you subscribe to that event, it should fire based on the criteria.
    Dont gain the world and lose your soul

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    Actually the event is fired, in this case when data comes in on port 514. The class is one that I use is vb to listen for UDP data comming in.

    In this example I set it to listen on port 514 with the "network.listen(514)" and send data to the localhost, from its self with the statement "network.send("127.0.0.1",514,Console.Readline());" just say that i used nsender instead of network (but is correct in my tyring-to-work example) but I think my problem is this.

    I am trying to make a console application (am sending data to its self just so I can figure out this "event" thing in c#) and when I try to use "this" i won't let me.

    Jeremy

  8. #8
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Lets see the code for the dll. That might be where the problem lies. BTW whats on port 514?
    Dont gain the world and lose your soul

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    Here is some of the class, I removed some of it for simplicity sake, but this is the part where the events are raised, I just took out the stuff the seperates the data recieved and stuff like that.

    This is from a thread
    VB Code:
    1. Class UDPListener                       'The UDPListener Thread
    2.     Public Port As Integer              'Port to listen on
    3.     Public Enabled As Boolean = False  
    4.     Public TEnable As Boolean = False  
    5.  
    6.     Public Event RecieveFailed(ByVal Message As String)
    7.     Public Event DataArrival(ByVal Data As String)
    8.  
    9.     Public Sub Listen()
    10.                recieve the data
    11.                RaiseEvent DataArrival(datastring)
    12.     End Sub
    13. End Class

    This is from the part that sets up the thread
    VB Code:
    1. Public Class UDP                                        'The UDP class that listens and sends data
    2.     Public Event Paused()                               'Invokes a event when the listener has been paused
    3.     Public Event Restarted()                            'Invokes a event when the listener has been restarted
    4.     Public Event Distroyed()                            'Invokes a event when the listener has been perminently disabled
    5.     Public Event DataSent(ByVal Data As String)         'Invokes a event when the data has been sent
    6.     Public Event DataArrival(ByVal Data As String)      'Invokes a event when data has been recieved
    7.     Public Event SendFailed(ByVal Message As String)    'Invokes a event when data could not be send to remote host
    8.     Public Event RecieveFailed(ByVal Message As String) 'Invokes a event when an error occured during data retrival
    9.     Public Event ErrorEvent(ByVal Message As String)    'Invokes a event when a subroutine encouters and error
    10.    
    11.     Dim ListenerDistroyed As Boolean = False
    12.     Private WithEvents Listener As New UDPListener
    13.     Private Listenerthread As New System.Threading.Thread(AddressOf Listener.Listen)
    14.  
    15.     Public Sub Listen(ByVal Port As Integer)
    16.         'Set up the listener thread
    17.     End Sub
    18.  
    19.     Public Sub Pause()
    20.         'Pause the listener thread
    21.     End Sub
    22.  
    23.     Public Sub Restart()
    24.         'Restart the listener thread
    25.     End Sub
    26.  
    27.     Public Sub Distroy()
    28.         'Kill the listener thread
    29.     End Sub
    30.  
    31.     Public Sub Send(ByVal Host As String, ByVal Port As Integer, ByVal Data As String)
    32.         'Send the data to the remote host
    33.     End Sub
    34.  
    35.     Private Sub DataArived(ByVal Data As String) Handles Listener.DataArrival
    36.         RaiseEvent DataArrival(Data)
    37.     End Sub
    38.  
    39.     Private Sub DataArrivalError(ByVal Message As String) Handles Listener.RecieveFailed
    40.         RaiseEvent RecieveFailed(Message)
    41.     End Sub
    42. End Class

  10. #10
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Try and see if this helps;

    Code:
    static void Main(string[] args)
    {
    	try
    	{
    		JWM.Net.UDP network = new JWM.Net.UDP();
    		network.Listen(514);
    		network.DataArrival += new JWM.Net.UDP.DataArrivalEventHandler(OnArrival);
    		network.Send("127.0.0.1", 514,Console.ReadLine());
    	}
    	catch(Exception ex)
    	{
    		Console.WriteLine(ex.Message);
    	}
    }
    			
    static void OnArrival(string data)
    {
    	Console.WriteLine(data);
    }
    Dont gain the world and lose your soul

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    Ah,

    I see where I went wrong.

    By the way, port 514 is the one used for logging, basically I am recreating a small logging server that is used to write data to a sql server (rather than the standard text file) from a firewall.

    Thanks

    Jeremy

  12. #12
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    No prob
    Dont gain the world and lose your soul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width