Mirage Source
http://web.miragesource.net/forums/

VB.Net
http://web.miragesource.net/forums/viewtopic.php?f=158&t=5490
Page 1 of 1

Author:  Matt [ Mon Apr 13, 2009 10:49 pm ]
Post subject:  VB.Net

I've started to convert my source to VB.Net and I've hit a snag.

With the byte array packet system Dugor designed, he uses a function called "GetAddress" and then calls it with the addressof for each sub that handles a packet.

In VB6, this is a perfect method to use. In VB.Net, it bitches, saying:

Code:
'AddressOf' expression cannot be converted to 'Long' because 'Long' is not a delegate type.


Here's an example of how AddressOf is used:
Code:
HandleDataSub(modEnumerations.ClientPackets.CGetClasses) = GetAddress(AddressOf HandleGetClasses)


And here's the GetAddress function:

Code:
    Public Function GetAddress(ByVal FunAddr As Long) As Long
        GetAddress = FunAddr
    End Function


Anyone here know anything about VB.Net? I'm using VB2008..

Once I figure this out, I can keep moving, but I'm at a loss.

Thanks guys. :D

Author:  Dragoons Master [ Tue Apr 14, 2009 1:32 am ]
Post subject:  Re: VB.Net

I don't know much VB.Net, but I'm good with C#, so what I can see from this:
'AddressOf' expression cannot be converted to 'Long' because 'Long' is not a delegate type.
is:
Vb.Net does not handle function pointers like VB6, probably it is like it's done in C# (since everything is just .Net). Delegate types are probably needed here.
Create a delegate type: "Delegate Sub MyDelSub()"
Then inside the function create an instance of this type : "Dim del As MyDelSub"
Now you can use the AddressOf function: "del = New MyDelSub(AddressOf YOURFUNCTIONNAME)"
Then to invoke, just use the Invoke function xD: "del.Invoke()"

Good luck!

Author:  Jacob [ Tue Apr 14, 2009 1:42 am ]
Post subject:  Re: VB.Net

You are correct!

I just looked into it for him.

Code:
Public Delegate Sub HandleDataDelegate(ByVal Index As Long, ByRef Data() As Byte)


Code:
Public HandleDataSub(ClientPackets.CMSG_COUNT) As HandleDataDelegate


Code:
HandleDataSub(modEnumerations.ClientPackets.CGetClasses) = AddressOf HandleGetClasses


Code:
HandleDataSub(MsgType).Invoke(Index, Buffer.ReadBytes(Buffer.Length - 3))

Author:  Matt [ Tue Apr 14, 2009 1:49 am ]
Post subject:  Re: VB.Net

Sweet. Two people who kinda know wtf they're talkin' about. :D

Since Jacob is helping me with a lot of this stuff, after I get my source converted to VB.Net, I will be converting whatever version of MS4 is released at that point, as well.

Gotta give back to the community. :D

Author:  Labmonkey [ Tue Apr 14, 2009 2:07 am ]
Post subject:  Re: VB.Net

and i will make it 3d!

Author:  Doomy [ Tue Apr 14, 2009 2:43 am ]
Post subject:  Re: VB.Net

Labmonkey wrote:
and i will make it 3d!

and i will use it

Author:  Coke [ Wed Apr 15, 2009 12:46 am ]
Post subject:  Re: VB.Net

Wow, Doomy made me chuckle o.0

Author:  James [ Wed Apr 15, 2009 7:57 am ]
Post subject:  Re: VB.Net

Can someone explain what the issue was? Why did it have to be delegated? I've used defined functions before as well, so I'm just unsure as to why this one had to be different.

Author:  Jacob [ Wed Apr 15, 2009 11:01 am ]
Post subject:  Re: VB.Net

The VB6 code was using an array of longs that held the memory address of functions. Then it used CallWindowProc to call the function in the array.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/