VBA 如何替换函数中的 "As Any"
VBA how to replace "As Any" in function
我有一个使用此签名的 dll:
SFetch(cursor As Integer, pstruct As Any, size As Integer) As Integer
我可以使用像 Integer
这样的简单变量来调用它,也可以使用自定义类型来调用更复杂的变量。
我想创建一个接收参数并将其发送到 dll 的函数,我尝试了不同的解决方案但总是出错。
在所有情况下,我都是这样称呼它的:
Dim val As Integer
...
.ExecuteRead val, LenB(val)
Public Sub ExecuteRead(ByVal pstruct, structSize As Integer)
SFetch1 c, pstruct, structSize
返回 Null
而不是值
Public Sub ExecuteRead(pstruct, structSize As Integer)
SFetch1 c, pstruct, structSize
返回Variable uses an Automation type not supported in Visual Basic
Public Sub ExecuteRead(pstruct As Variant, structSize As Integer)
SFetch1 c, pstruct, structSize
返回Variable uses an Automation type not supported in Visual Basic
Public Sub ExecuteRead(pstruct As Object, structSize As Integer)
SFetch1 c, pstruct, structSize
无法调用函数ByRef argument type mismatch
Public Sub ExecuteRead(pstruct As Any, structSize As Integer)
甚至无法编译,Syntax error
刚刚意识到我没有正式的答案所以就这样了。
这是函数声明,包括对我的外部函数的调用:
Public Sub ExecuteRead(ByVal pstruct As LongPtr, structSize As Integer)
SFetch1 dataCur, ByVal pstruct, structSize
这是我在主程序中调用它的方式:
obj.ExecuteRead VarPtr(returnGrp), LenB(returnGrp)
我有一个使用此签名的 dll:
SFetch(cursor As Integer, pstruct As Any, size As Integer) As Integer
我可以使用像 Integer
这样的简单变量来调用它,也可以使用自定义类型来调用更复杂的变量。
我想创建一个接收参数并将其发送到 dll 的函数,我尝试了不同的解决方案但总是出错。
在所有情况下,我都是这样称呼它的:
Dim val As Integer
...
.ExecuteRead val, LenB(val)
Public Sub ExecuteRead(ByVal pstruct, structSize As Integer)
SFetch1 c, pstruct, structSize
返回 Null
而不是值
Public Sub ExecuteRead(pstruct, structSize As Integer)
SFetch1 c, pstruct, structSize
返回Variable uses an Automation type not supported in Visual Basic
Public Sub ExecuteRead(pstruct As Variant, structSize As Integer)
SFetch1 c, pstruct, structSize
返回Variable uses an Automation type not supported in Visual Basic
Public Sub ExecuteRead(pstruct As Object, structSize As Integer)
SFetch1 c, pstruct, structSize
无法调用函数ByRef argument type mismatch
Public Sub ExecuteRead(pstruct As Any, structSize As Integer)
甚至无法编译,Syntax error
刚刚意识到我没有正式的答案所以就这样了。
这是函数声明,包括对我的外部函数的调用:
Public Sub ExecuteRead(ByVal pstruct As LongPtr, structSize As Integer)
SFetch1 dataCur, ByVal pstruct, structSize
这是我在主程序中调用它的方式:
obj.ExecuteRead VarPtr(returnGrp), LenB(returnGrp)