I have some VB6 code that I am converting to VB.net and came across this section
Declare Function TmSendByLen Lib 'tmctl.dll' Alias 'TmSendByLength'(ByVal id As Integer, ByRef msg As Any, ByVal blen As Integer) As Integer 'snip' Function TmSendByLength(ByVal id As Integer, ByVal msg As String, ByVal blen As Integer) As Integer TmSendByLength = TmSendByLen(id, msg, blen) End Function
I have not come across the Alias term before but I can guess what it does. What I am unsure of is the reasoning behind overloading the alias. If that is what is happening.
I need to create overloads for the TmSendByLen function as the ‘As Any’ is not supported in VB.net so I am not sure if I should just remove the alias or if I should leave it in place.
The Alias doesn’t specify that the function is overloaded exactly, but that the name specified is really named something else in the called dll.
Since your example is a bit confusing (because of the repeated names), I’ll use a slightly modified version to explain:
So in this modified version, the
TmSendByLengthname is the one that the referenced function’s entrypoint is really called intmctl.dll.TmSendByLenis what we’re referring to it as in our code, andInternalVersionis the name of the wrapper function.I would imagine that this is so that
InternalVersioncan be called across modules/classes, while theTmSendByLenversion was intended to be private.To answer the second part of your question, Alias is still available in VB.NET, although
As Anyisn’t. (You can find information about it here.) Whether you want to remove the Alias or not is completely up to you, but either way, I suspect you’re going to need to useAs IntPtr(or SafeHandle) instead ofAs Any.