Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB.Net
#1
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. Big Grin
Reply
#2
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!
Reply
#3
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))
Reply
#4
Sweet. Two people who kinda know wtf they're talkin' about. Big Grin

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. Big Grin
Reply
#5
and i will make it 3d!
Reply
#6
Labmonkey Wrote:and i will make it 3d!
and i will use it
Reply
#7
Wow, Doomy made me chuckle o.0
Reply
#8
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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)