![]() |
VB.Net - Printable Version +- Mirage Source (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: Programming (https://mirage-engine.uk/forums/forumdisplay.php?fid=24) +----- Forum: .NET (https://mirage-engine.uk/forums/forumdisplay.php?fid=35) +----- Thread: VB.Net (/showthread.php?tid=2746) |
VB.Net - Matt - 13-04-2009 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 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. ![]() Re: VB.Net - Dragoons Master - 14-04-2009 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! Re: VB.Net - Jacob - 14-04-2009 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)) Re: VB.Net - Matt - 14-04-2009 Sweet. Two people who kinda know wtf they're talkin' about. ![]() 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. ![]() Re: VB.Net - Labmonkey - 14-04-2009 and i will make it 3d! Re: VB.Net - Doomy - 14-04-2009 Labmonkey Wrote:and i will make it 3d!and i will use it Re: VB.Net - Coke - 15-04-2009 Wow, Doomy made me chuckle o.0 Re: VB.Net - Jacob - 15-04-2009 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. |