Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Pb.Dll as Master, Vb.Exe as Slave

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pb.Dll as Master, Vb.Exe as Slave

    Because VB is "black box", in my impression it's better to talk with it using documented features.
    For example, callback for main form.

    Imagine that it's necessary to call VB function from main PB module.

    Let's create in VB "Standart Exe". Add module.
    Put in module
    Code:
    Option Explicit
    
    Declare Function PBSTART Lib "Pb" (hWnd As Long) As Long
    
    Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
       ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, _
       ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    
    Public Const GWL_WNDPROC = -4
    Public Const WM_DESTROY = &H2
    Public Const WM_USER = &H400
    Global lpPrevWndProc As Long
    
    Public Sub Hook(hWnd As Long)
       lpPrevWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
    End Sub
    
    Function WindowProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
       Select Case wMsg
          Case WM_USER + 1: MsgBox "wParam = " + Str$(wParam) + "; lParam =" + Str$(lParam)
          Case WM_DESTROY: SetWindowLong hWnd, GWL_WNDPROC, lpPrevWndProc
       End Select
       WindowProc = CallWindowProc(lpPrevWndProc, hWnd, wMsg, wParam, lParam)
    End Function
    For Form1 (w/o controls) add
    Code:
    Private Sub Form_Load()
       Me.Hide
       Hook Me.hWnd
       PBSTART Me.hWnd
    End Sub
    Then in PB let's comple really main module.
    [code]
    #Compile Dll
    #Register None
    #Dim All
    #Include "WIN32API.INC"

    Global hDlg As Long, VBhWnd As Long
    CallBack Function DlgProc
    Select Case CbMsg
    Case %WM_COMMAND: If CbCtl = 101 Then SendMessage VBhWnd, %WM_USER + 1, 20, 30
    Case %WM_DESTROY: PostMessage VBhWnd, %WM_SYSCOMMAND, %SC_CLOSE, 0
    End Select
    End Function

    Function PbStart(VB_hWnd As Long) Export As Long
    Dim hDlg As Long
    VBhWnd = VB_hWnd
    Dialog New 0, "VB as Slave", , , 120, 100, %WS_CAPTION Or %WS_SYSMENU To hDlg
    Control Add Button, hDlg, 101, "Call VB", 10, 10, 100, 15
    Dialog Show Modeless hDlg Call DlgProc
    End Function
    [code]

    Then let's start VB module from VB IDE.
    Form1 will hide itself and will initiate PB.

    During a work PB can send WM_USER messages (with addresses of parameters).
    VB can call it's functions normally and return results.

    ------------------
    E-MAIL: [email protected]
Working...
X