Results 1 to 9 of 9

Thread: SendMessage problem...

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    SendMessage problem...

    I have created my own ActiveX EXE now...I have subclassed a form in this...
    And I have the following in a standard EXE:
    VB Code:
    1. Public Function SendByteArray(ByVal hWnd As Long, ByVal ByteArray As String) As Long
    2. Dim lngRet      As Long
    3.     marBuffer = ByteArray
    4.     With mudtStruct
    5.         .Length = UBound(marBuffer) + 1
    6.         .Pointer = VarPtr(marBuffer(0))
    7.     End With
    8.     SendByteArray = SendMessage(hWnd, CUSTOM_MESSAGE, GetCurrentProcessId, mudtStruct)
    9.     Erase marBuffer
    10. End Function
    11.  
    12. Public Sub PostByteArray(ByVal hWnd As Long, ByVal ByteArray As String)
    13.     marBuffer = ByteArray
    14.     With mudtStruct
    15.         .Length = UBound(marBuffer) + 1
    16.         .Pointer = VarPtr(marBuffer(0))
    17.     End With
    18.     Call PostMessage(hWnd, CUSTOM_MESSAGE, GetCurrentProcessId, VarPtr(mudtStruct))
    19. End Sub
    Now...while in design mode and running the active x exe app from the IDE I can SendByte Array to the activeX...this isn't a problem...however...if I compile the ActiveX EXE then run the above code the SendByte array function fails...the ActiveX doesn't even pick up the custom message, and so ALWAYS returns a 0 for the pointer value, however, the POSTMessage does work...but I need SendMessage...
    Why is this?

    Woka

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    The API Guide say this:
    VB Code:
    1. The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message. The PostMessage function, in contrast, posts a message to a thread’s message queue and returns immediately.
    So maybe you need a DoEvents or some other way of waiting a few milliseconds.

  3. #3

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Yea, I know...that's the problem...
    In my SubClassing of the Active X EXE I have:
    VB Code:
    1. If uMsg = CUSTOM_MESSAGE Then
    2.    Beep
    3.    Beep
    4.    'Plus other stuff...
    5. End IF
    Now when I SEND message the message is not picked up, the SendMessage API does not wait for the message to be processed and just returns to my thread with a value of 0. When I use PostMessage I get a few beeps...but I need my client UI to wait for a return value...when the Active X EXE is running in a VB IDE then it works perfectly for both Send and Post Message...

    I am very confused

    Woka

  4. #4
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    You could try SendMessageTimeout intead?
    e.g.
    VB Code:
    1. Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long

    Also - check Err.LastDllError = 0 after each API call just to be safe.

  5. #5

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    How would that help???
    The app doesn't hang on SendMessage, it returns instantly, with a value of 0 for the return value...the actual message is not picked up by my subclassing

    This happens on XP...I am about to test it on NT...

    Well, it works on NT if I have the Subclassing code and WinProc function in my ActiveX EXE...

    BUT I have developed a DLL like your EventVB DLL, that has many functions that I use everywhere...one thing is a Msghooking class...which I use to replace the Subclassing code
    Now, on my XP box at home I am using this DLL instead of the code inside the ActiveX, which works in the VB IDE...but not when compiled...
    Am just about to change the code on my NT box to use this subclassing DLL and class and see if that works. If it works then it's something to do with XP...

    Woka

  6. #6
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    From MSDN:
    The system only does marshalling for system messages (those in the range 0 to WM_USER). To send other messages (those above WM_USER) to another process, you must do custom marshalling.

    If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, the system switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. For more information on nonqueued messages, see Nonqueued Messages.

  7. #7

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    The system only does marshalling for system messages (those in the range 0 to WM_USER). To send other messages (those above WM_USER) to another process, you must do custom marshalling.
    That may as well be in french

    Woof

  8. #8

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Right...If I use my MsgHook class from my DLL then it doesnt work on NT either!!! But it works if the project, the active X one that references my MsgHook DLL, is being run in the IDE...

    If the Subclassing code is INSIDE the project, the ActiveX EXE, and not from my MsgHook class then it works when compiled!!!
    I don't understand...works in IDE, but not when compiled when using my MsgHook class...

    Woka

  9. #9

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    When I remove the subclassing from the ActiveX and use my DLL and MsgHook class I am also remove the CreateWindow function from the ActiveX EXE too and have that in a class in my DLL called NewWindow

    I do:
    VB Code:
    1. Private mobjMsgWindow As NewWindow
    2.    
    3. 'then in my sub I have
    4.     Set objMsgWindow = New NewWindow
    5.     objMsgWindow.CreateWindow("ClientTitle") 'I pass in the title of my window...
    The code for CreateWindow (in my DLL) is:
    VB Code:
    1. mlnghWnd = CreateWindowEx(0, "STATIC", pstrTitle, 0, 0, 0, 0, 0, 0, 0, App.hInstance, ByVal 0&)
    Is that line correct?
    Insstance???
    ParenthWnd???

    Woka

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width