请问在VB程序中怎样引入一回调函数,好象在VBSCRIPT中可以可以用到getref,
在VB中不行,请高手指教,谢谢!!

解决方案 »

  1.   

    使用回调函数需要借助API函数.(SetWindowLong)
    回调有很多种,看你需要什么样的回调函数了
    一个简单的消息回调
    OldWindowProc = SetWindowLong(Frm_Show.hwnd, GWL_WNDPROC, AddressOf WindowProc)Public Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    '系统运用函数判断鼠标动作,进行处理
        If Msg = TRAY_CALLBACK Then
            If lParam = WM_LBUTTONUP Then
                If Frm_Show.WindowState = vbMinimized Then _
                    Frm_Show.WindowState = LastState
                Frm_Show.Show
                Exit Function
            End If
            If lParam = WM_RBUTTONUP Then
                Frm_Show.PopupMenu Frm_Menu
                Exit Function
            End If
        End If    ' window proc
        WindowProc = CallWindowProc(OldWindowProc, hwnd, Msg, wParam, lParam)
        '恢复窗口原来的句柄设置
    End Function
      

  2.   

    CallByName Function
          Executes a method of an object, or sets or returns a property of an object.SyntaxCallByName(object, procname, calltype,[args()])The CallByName function syntax has these named arguments:Part Description 
    object Required; Variant (Object). The name of the object on which the function will be executed. 
    procname Required; Variant (String). A string expression containing the name of a property or method of the object. 
    calltype Required; Constant. A constant of type vbCallType representing the type of procedure being called. 
    args() Optional: Variant (Array). 
    ResThe CallByName function is used to get or set a property, or invoke a method at run time using a string name.In the following example, the first line uses CallByName to set the MousePointer property of a text box, the second line gets the value of the MousePointer property, and the third line invokes the Move method to move the text box:CallByName Text1, "MousePointer", vbLet, vbCrosshair
    Result = CallByName (Text1, "MousePointer", vbGet)
    CallByName Text1, "Move", vbMethod, 100, 100
      

  3.   

    先谢谢各
    位啦
       不好意思,我没说清楚。我想在DLL中定义一公共变量,然后在程序的
    某一函数调用该变量。在外部程序中(EXE或VBS)中把DLL类中定义的公共
    变量指向一自定义函数。当外部程序执行DLL函数时,自动回调自定义函数。
    该方法在VBS中是可行的,但在EXE中不行,我找过MSDN,里面好象说要引用
    两个类,但我找不到那些类。请帮忙!!
    我的程序如下:dll:
    '----------------------------------------------------
    CBTest.cls
    '----------------------------------------------------
    Public CBFunction As Variant
    Public Function Test() As Boolean
         Dim bolRet As Boolean
         bolRet = Module1.FCallback
         Test = bolRet
    End Function'-----------------------------------------------------------
     module1.bas
    '-----------------------------------------------------------
    Private CBT As New CBTest
    Public Function FCallback() As Boolean
        Dim vRet As Variant
        
        vRet = CBT.CBFunction
        FCallback = True
    End Function
    VBS
    dim objTCB ,bolRet
    set objTCB=createobject("PCallbackT.CBTest")
    objTCB.CBFunction=getref("testcb")
    bolRet=objTCB.Test
    function  testcb() 
       msgbox  "already calback"
    end function  
      

  4.   

    http://expert.csdn.net/Expert/topic/1490/1490576.xml?temp=.8387567
      

  5.   

    to :wxy_xiaoyu(☆然也☆ => .NET 努力ing)
     谢谢:
     好象文中的情况和我这里的有所不同,文中是调用了API 函数的,我这里
    是在DLL的类中加入一变量,然后通过变量引入回调函数的。