|
-
Jun 25th, 2003, 07:25 PM
#1
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:
Public Function SendByteArray(ByVal hWnd As Long, ByVal ByteArray As String) As Long
Dim lngRet As Long
marBuffer = ByteArray
With mudtStruct
.Length = UBound(marBuffer) + 1
.Pointer = VarPtr(marBuffer(0))
End With
SendByteArray = SendMessage(hWnd, CUSTOM_MESSAGE, GetCurrentProcessId, mudtStruct)
Erase marBuffer
End Function
Public Sub PostByteArray(ByVal hWnd As Long, ByVal ByteArray As String)
marBuffer = ByteArray
With mudtStruct
.Length = UBound(marBuffer) + 1
.Pointer = VarPtr(marBuffer(0))
End With
Call PostMessage(hWnd, CUSTOM_MESSAGE, GetCurrentProcessId, VarPtr(mudtStruct))
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
-
Jun 25th, 2003, 08:17 PM
#2
The API Guide say this:
VB Code:
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.
-
Jun 26th, 2003, 02:27 AM
#3
Yea, I know...that's the problem...
In my SubClassing of the Active X EXE I have:
VB Code:
If uMsg = CUSTOM_MESSAGE Then
Beep
Beep
'Plus other stuff...
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
-
Jun 26th, 2003, 04:19 AM
#4
You could try SendMessageTimeout intead?
e.g.
VB Code:
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.
-
Jun 26th, 2003, 04:38 AM
#5
-
Jun 26th, 2003, 04:54 AM
#6
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.
-
Jun 26th, 2003, 04:57 AM
#7
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
-
Jun 26th, 2003, 05:15 AM
#8
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
-
Jun 26th, 2003, 05:37 AM
#9
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:
Private mobjMsgWindow As NewWindow
'then in my sub I have
Set objMsgWindow = New NewWindow
objMsgWindow.CreateWindow("ClientTitle") 'I pass in the title of my window...
The code for CreateWindow (in my DLL) is:
VB Code:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|