使用别名关键字来声明在VBA函数 [英] Using Alias keyword to declare a function in VBA

查看:411
本文介绍了使用别名关键字来声明在VBA函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有VBA的MS Access表code,其中I型下面的函数声明:

I have VBA MS Access form code, where I type the following function declaration:

Public Declare Function GetUserName Lib "advapi32.dll" () Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

但是我收到的别名错误。我一定要添加,才能使用这个一些参考?

However I'm getting an error on Alias. Do I have to add some references in order to use this?

推荐答案

没有,有没有特殊的库都必须使用别名;这是所有语言内置的。

No, there are no special libraries are required to use Alias; this is all built into the language.

但你的声明是错误的。你有一组额外之前别名括号中易混淆的编译器。

But your declaration is wrong. You have an extra set of parentheses placed just before Alias that are confusing the compiler.

除了纯粹的语法,第二个参数( n大小)实际上是一个的指针的到,这意味着你需要通过它的ByRef 在VBA。

Beyond pure syntax, the second parameter (nSize) is actually a pointer to a Long, which means that you need to pass it ByRef in VBA.

因此​​,修订后的声明是这样的,而不是:

So the revised declaration would look like this, instead:

Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
        (ByVal lpBuffer As String, ByRef nSize As Long) As Long

返回值将是1,如果函数成功,或者0,如果它失败。

The return value will be 1 if the function succeeds, or 0 if it fails.

这篇关于使用别名关键字来声明在VBA函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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