如题

解决方案 »

  1.   

    VB只支持返回值[out, retval]
      

  2.   

    不会吧 那out是干什么用的 不是作为参数然后带回返回值么?
    我知道[out,retval]可以作为函数返回值
    [out]是何用?
      

  3.   

    out的意思是输出参数
    有out属性的参数必须是指针[id(1), helpstring("method TestMethod")] HRESULT TestMethod([out] BSTR* outstr, [out] double* outdbl, [out] IDispatch** outobj);STDMETHODIMP CTestClass::TestMethod(BSTR *outstr, double *outdbl, IDispatch **outobj)
    {
    *outstr = _bstr_t("你好!").copy();
    *outdbl = 3.1415926;
    _COM_SMARTPTR_TYPEDEF(IDispatch, __uuidof(IDispatch));
    IDispatchPtr p;
    p.CreateInstance("scripting.dictionary");
    *outobj = p;
    p.AddRef();
    return S_OK;
    }Private Sub Form_Load()
        Dim outstr As String
        Dim outdbl As Double
        Dim outobj As Object
        
        Dim tc As New TestClass
        Call tc.TestMethod(outstr, outdbl, outobj)
        
        MsgBox outstr
        MsgBox outdbl
        MsgBox TypeName(outobj)
    End Sub
      

  4.   

    指针参数在VB中就是标记为引用(ByRef)的参数.
      

  5.   

    4楼 非常好 知道我要问什么 呵呵 多谢
    那再麻烦下 
    Dim eee As New DDDLib.GetFile
    Dim file_count As Long
    Dim right_file_count As Long
    file_count = 0
    right_file_count = 0
    Call eee.GetFilePath(App.Path & "\winstd\1", App.Path & "\06204073", file_count, right_file_count)
    MsgBox file_count
    MsgBox right_file_count
    这样调用是没问题的
    我后来自己试  GetFilePath 他后面不带括号也可以调用 为什么要用call 呢
    还有如果是返回两个带参数的 定义却不可以这样写
    Dim file_count,right_file_count  As Long
      

  6.   

    用call的话,可读性比较好,很清楚表明这是一个函数/过程调用.
    以后要增加接收返回值的功能也比较容易,直接把"Call"替换为"x="即可函数定义:
    function Function(byval a as long) as long
    end function不接收返回值的写法:
    Func a
    Call Func(a) 
    =>
    接收返回值的写法:
    x = Func(a)如果直接写过程式调用的话,还要补括号
    用Call的话,是否接收返回值,切换很方便.
      

  7.   

    Dim file_count,right_file_count As Long
    如果某个变量后边没有直接跟类型,会被定义为Variant类型,其效果就像这样:
    Dim file_count As Variant, right_file_count As Long正确的声明方式为:
    Dim file_count As Long, right_file_count As Long建议不要在一行声明多个变量.
    一行一个,这样比较清楚,也便于阅读和维护.返回参数是ByRef的时候,要求类型严格一致,参数声明的是什么类型,传递的变量就必须是什么类型.
    如果声明的是Long类型,而传递的是Variant类型,在编译时则会提示类型不匹配的错误.
      

  8.   

    好的 非常感谢! sonic_andy
      

  9.   

    好的 非常感谢! sonic_andy