Results 1 to 9 of 9

Thread: help..!

  1. #1

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Exclamation help..!

    I am playing with vc++.net and wrapping the joy* api into a class. The method I want to use is to have a msgloop and event structure in the class so that when it is used in vb.net or C# the user won't need to worry about a callback function.

    the C++ Concept is very simple.
    Code:
    #using <mscorlib.dll>
    
    using namespace System;
    
    namespace IO{
    	
    	[event_source(managed)]
    	public __gc class JoyStick{
    	public:
    		__event void ButtonPress();
    
    		void RaiseButtonPress(){
    			ButtonPress();
    		}
    
    	};
    }
    compiles fine...

    left this out before
    VB Code:
    1. Module x
    2.     Private xx As New Magiaus.IO.JoyStick()
    3.     Sub Main()
    4.  
    5.         xx.__Delegate_ButtonPress.CreateDelegate(Type.GetType("Magiaus.IO.JoyStick"), xx, "Msg", True)
    6.         xx.RaiseButtonPress()
    7.  
    8.     End Sub
    9.  
    10.     Sub Msg()
    11.         MsgBox("Test")
    12.     End Sub
    13. End Module

    But, when I get into VB.Net and I try to setup a delegate using the __Delegate_ButtonPressed method that is shown in my intelsense I get a can't be null error. It just ccued to me that it could be because its void but I don't think so.

    If any of you guys have done anything like this let me know. personally i was hopeing that i could just use AddHandler somehow... i have exmple of useing this c++ to c++ but nothing on doing it in vb.net or c#... I know it should work. But if it proves to hard I will just change the design i have and make a QueryState method or something.

    Any sugestions on the object structure appriciated.
    Magiaus

    If I helped give me some points.

  2. #2

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    oh RaiseButtonPress is for testing the event and nothing more
    Magiaus

    If I helped give me some points.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I think an event must have two parameters:
    1) the sender:
    VB.NET: Sender As Object
    C#: Object Sender
    C++: Object *Sender

    2) the event arguments
    VB.NET: e As EventArgs
    C#: EventArgs e
    C++: EventArgs *e
    May also be a class derived from EventArgs.

    But I admit that I don't know if the event declaration needs this too.

    I recently saw a page that explained adding events to your own classes...
    It was an article on the Code Project, but I can't reach the server at the moment.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    is it somwhere i could look at it.?
    Magiaus

    If I helped give me some points.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I'm sorry, it should be here, but the server seems to be down.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    sure does seem to be down. thanks bee man
    Magiaus

    If I helped give me some points.

  7. #7
    Junior Member
    Join Date
    Sep 2002
    Location
    Belgium
    Posts
    16
    Hi,

    I'm not sure if this is what you're asking because I don't really understande the C++ code. Anyway, you can add events to an Event Handler in Visual Basic .Net with the following code.

    (In the example I have a windows forms button on a form and want to invoke the GUIEventHandler when it is clicked.)

    1) In the form_load event, instantiate the event handler and give him a reference to the form (Me):

    Code:
            Dim MyEH As New GUIEventHandler(Me)
            AddHandler Button1.Click, AddressOf MyEH.MyClick
    2) The event handler looks like this:

    Code:
    Public Class GUIEventHandler
        Private m_GUIForm As fclsPictureViewer
    
        Public Sub New(ByRef AttachedGUIForm As Form)
            m_GUIForm = AttachedGUIForm
        End Sub
    
        Protected Overrides Sub Finalize()
            m_GUIForm = Nothing
            MyBase.Finalize()
        End Sub
    
        Public Sub MyClick(ByVal sender As Object, ByVal e As EventArgs)
            MsgBox("The Eventhandler was triggered! " & sender.GetType.ToString)
            m_GUIForm.Button1.Enabled = False
        End Sub
    
    End Class
    I'm sure you will be able to apply this to your problem.

    Success!

  8. #8

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Exclamation great

    i knew it was going to be something like that its just the whole __delegate_ButtonPress that threw me for a loop.

    Thanks
    Magiaus

    If I helped give me some points.

  9. #9
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I posted some code in the codebank of http://www.vb-world.com in the C# section on how to add events with custom event arguments. If you want to implement it in C#, you might want to take a look at it.

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