|
-
Sep 9th, 2002, 01:43 PM
#1
Thread Starter
Frenzied Member
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:
Module x
Private xx As New Magiaus.IO.JoyStick()
Sub Main()
xx.__Delegate_ButtonPress.CreateDelegate(Type.GetType("Magiaus.IO.JoyStick"), xx, "Msg", True)
xx.RaiseButtonPress()
End Sub
Sub Msg()
MsgBox("Test")
End Sub
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.
-
Sep 9th, 2002, 01:44 PM
#2
Thread Starter
Frenzied Member
oh RaiseButtonPress is for testing the event and nothing more
Magiaus
If I helped give me some points.
-
Sep 10th, 2002, 03:02 AM
#3
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.
-
Sep 10th, 2002, 04:33 AM
#4
Thread Starter
Frenzied Member
is it somwhere i could look at it.?
Magiaus
If I helped give me some points.
-
Sep 10th, 2002, 06:59 AM
#5
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.
-
Sep 10th, 2002, 10:21 AM
#6
Thread Starter
Frenzied Member
sure does seem to be down. thanks bee man
Magiaus
If I helped give me some points.
-
Sep 10th, 2002, 10:51 AM
#7
Junior Member
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!
-
Sep 10th, 2002, 02:19 PM
#8
Thread Starter
Frenzied Member
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.
-
Sep 10th, 2002, 07:21 PM
#9
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|