函数声明中的别名是否已重载? [英] Alias in Function Declaration overloaded?

查看:21
本文介绍了函数声明中的别名是否已重载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些 VB6 代码,我正在将其转换为 VB.net 并遇到此部分

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.

我需要为 TmSendByLen 函数创建重载,因为 VB.net 不支持As Any",所以我不确定是否应该删除别名或是否应该保留它.

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.

推荐答案

Alias 没有指定函数完全重载,但指定的名称实际上是被调用的 dll 中的其他名称.

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:

Declare Function TmSendByLen Lib "tmctl.dll" Alias "TmSendByLength" (ByVal id As Integer, ByRef msg As Any, ByVal blen As Integer) As Integer)

Function InternalVersion(ByVal id As Integer, ByVal msg As String, ByVal blen As Integer) As Integer
    InternalVersion = TmSendByLen(id, msg, blen)
End Function

因此在此修改版本中,TmSendByLength 名称是在tmctl.dll 中真正调用引用函数的入口点的名称.TmSendByLen 是我们在代码中所指的内容,InternalVersion 是包装函数的名称.

So in this modified version, the TmSendByLength name is the one that the referenced function's entrypoint is really called in tmctl.dll. TmSendByLen is what we're referring to it as in our code, and InternalVersion is the name of the wrapper function.

我认为这是为了让 InternalVersion 可以跨模块/类调用,而 TmSendByLen 版本旨在是私有的.

I would imagine that this is so that InternalVersion can be called across modules/classes, while the TmSendByLen version was intended to be private.

为了回答您问题的第二部分,Alias 在 VB.NET 中仍然可用,尽管 As Any 不是.(您可以在此处找到有关它的信息.)是否删除别名完全取决于您,但无论哪种方式,我怀疑您将需要使用 As IntPtr(或 SafeHandle)而不是 As Any.

To answer the second part of your question, Alias is still available in VB.NET, although As Any isn'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 use As IntPtr (or SafeHandle) instead of As Any.

这篇关于函数声明中的别名是否已重载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆