VBA如何替换;如任何人所说;在功能上

VBA如何替换;如任何人所说;在功能上,vba,dynamics-sl,Vba,Dynamics Sl,我有一个使用此签名的dll: SFetch(cursor As Integer, pstruct As Any, size As Integer) As Integer 我可以用简单的变量调用它,比如Integer,或者用更复杂的变量调用自定义类型 我想创建一个函数,它将接收一个参数并将其发送到dll,我尝试了不同的解决方案,但总是有错误 在所有情况下,我都这样称呼它: Dim val As Integer ... .ExecuteRead val, LenB(val) 返回Null而不是

我有一个使用此签名的dll:

SFetch(cursor As Integer, pstruct As Any, size As Integer) As Integer
我可以用简单的变量调用它,比如
Integer
,或者用更复杂的变量调用自定义类型

我想创建一个函数,它将接收一个参数并将其发送到dll,我尝试了不同的解决方案,但总是有错误

在所有情况下,我都这样称呼它:

Dim val As Integer
...
.ExecuteRead val, LenB(val)

返回
Null
而不是值


返回的
变量使用Visual Basic中不支持的自动化类型


返回的
变量使用Visual Basic中不支持的自动化类型


无法调用函数
ByRef参数类型不匹配



甚至不会编译,
语法错误

刚刚意识到我没有正式答案,所以答案就在这里

这是函数声明,包括对我的外部函数的调用:

Public Sub ExecuteRead(ByVal pstruct As LongPtr, structSize As Integer)
    SFetch1 dataCur, ByVal pstruct, structSize
以下是我在主程序中对其的称呼:

obj.ExecuteRead VarPtr(returnGrp), LenB(returnGrp)

VBA
中,对VB中的
Integer
使用
Long
Integer和VB中的code>SFetch(游标为Integer,ByVal pstruct为LongPtr,size为Integer)声明为Integer并用
调用。ExecuteRead VarPtr(val),LenB(val)
@vityta,耶,我知道,但我倾向于忘记我不应该在VBA中使用整数,因为它在幕后被转换为Long。但谢谢你指出;)@AlexDupuis-这不仅是幕后转换(此处不太相关),而且如果在VBA中使用Integer,则VB无法将其解析为自己的整数。不久前,我写了一篇文章,其中dll库中函数的
整数
在VBA中被“转换”为
Long
。@Vityata,谢谢,我不知道;)
Public Sub ExecuteRead(pstruct As Variant, structSize As Integer)
        SFetch1 c, pstruct, structSize
Public Sub ExecuteRead(pstruct As Object, structSize As Integer)
        SFetch1 c, pstruct, structSize
Public Sub ExecuteRead(pstruct As Any, structSize As Integer)
Public Sub ExecuteRead(ByVal pstruct As LongPtr, structSize As Integer)
    SFetch1 dataCur, ByVal pstruct, structSize
obj.ExecuteRead VarPtr(returnGrp), LenB(returnGrp)