Vb code works in vb not by self

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ht

    #1

    Vb code works in vb not by self

    hi all,

    im kinda new to vb and i have code that unhides a hidden from on a key press

    for some reason though this code only works when running th app through by,
    ie. it wont work in the standalone program. Source code can be downloaded
    from http://www.geocities.com/thecubical/temp.zip

    source code
    ----------------------from form--------------------------
    Private Sub Command1_Click( )
    Dim ip As String
    ip = InputBox("Pleas e enter the ip to send the message to", "Ip to send
    to")


    Winsock1.Close 'must close to stop error
    Winsock1.Connec t ip, 123 'connect to ip and port
    End Sub




    Private Sub Form_Load()
    Winsock2.Close 'must close to stop error
    Winsock2.LocalP ort = 123
    Winsock2.Listen 'listen for incoming messages
    'set a keyboard hook
    hHook = SetWindowsHookE x(WH_KEYBOARD, AddressOf KeyboardProc,
    App.hInstance, App.ThreadID)

    End Sub

    Private Sub Winsock1_Close( )
    On Local Error Resume Next
    Winsock1.Close 'close winsock on error

    End Sub
    Private Sub Winsock1_Connec t()
    Dim message As String

    message = InputBox("Pleas e enter the message to send", "Type your
    message")
    Winsock1.SendDa ta message 'send the message to client

    End Sub
    Private Sub Winsock2_Close( )
    Winsock2.Close 'boof
    Winsock2.Listen 'boof

    End Sub

    Private Sub Winsock2_Connec tionRequest(ByV al requestID As Long)
    'boof
    If Winsock2.State <> sckConnected Then
    Winsock2.Close
    End If
    'end boof

    Winsock2.Accept requestID 'accept connection to server

    End Sub

    Private Sub Winsock2_DataAr rival(ByVal bytesTotal As Long)
    Dim arriving_messag e As String
    Winsock2.GetDat a arriving_messag e 'accept a message from server
    MsgBox arriving_messag e 'print message in msgbox

    End Sub
    Private Sub Winsock1_Error( ByVal Number As Integer, Description As String,
    ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal
    HelpContext As Long, CancelDisplay As Boolean)
    MsgBox "Error " & Description, vbOKOnly + vbExclamation

    End Sub
    Private Sub Winsock1_SendCo mplete()
    Winsock1.Close 'when server finished sending message
    close connection

    End Sub
    Private Sub Winsock2_Error( ByVal Number As Integer, Description As String,
    ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal
    HelpContext As Long, CancelDisplay As Boolean)
    On Local Error Resume Next ' boof
    MsgBox "Error " & Description, vbOKOnly + vbExclamation
    Winsock2.Listen 'boof

    End Sub
    Private Sub Winsock2_SendCo mplete()
    On Local Error Resume Next
    Winsock1.Close 'when client finished getting message
    close connection

    End Sub
    Private Sub Form_Unload(Can cel As Integer)
    'remove the windows-hook
    UnhookWindowsHo okEx hHook
    Winsock1.Close 'close winsocks on exit
    Winsock2.Close

    End Sub

    ------------------------from module---------------------
    'In a module
    Public Const WH_KEYBOARD = 2
    Public Const VK_SHIFT = &H10
    Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal
    ncode As Long, ByVal wParam As Long, lParam As Any) As Long
    Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As
    Integer
    Declare Function SetWindowsHookE x Lib "user32" Alias "SetWindowsHook ExA"
    (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal
    dwThreadId As Long) As Long
    Declare Function UnhookWindowsHo okEx Lib "user32" (ByVal hHook As Long) As
    Long
    Public hHook As Long
    Public Function KeyboardProc(By Val idHook As Long, ByVal wParam As Long,
    ByVal lParam As Long) As Long
    'if idHook is less than zero, no further processing is required
    If idHook < 0 Then
    'call the next hook
    KeyboardProc = CallNextHookEx( hHook, idHook, wParam, ByVal lParam)
    Else
    'check if SHIFT-S is pressed
    If (GetKeyState(VK _SHIFT) And &HF0000000) And wParam = Asc("S") Then
    'show the result
    Form1.Show
    ElseIf (GetKeyState(VK _SHIFT) And &HF0000000) And wParam = Asc("D")
    Then
    Form1.Hide
    End If
    'call the next hook
    KeyboardProc = CallNextHookEx( hHook, idHook, wParam, ByVal lParam)
    End If
    End Function
    ----------------------------------------------------------

    thanks for any help




Working...