I want to send text messages across processes.
I chose this method. https://www.autohotkey.com/docs/v2/lib/OnMessage.htm#ExSendString
When across processes, it can only use 0x4a
If change 0x4a, it will cause error
In same process,the msg number can change and work fine
copy Sender.ahk into Receiver.ahk then change 0x004A
so across processes WM_COPYDATA can only use 0x4a?
[Mod edit: Moved topic from 'Scripts and Functions (v2)' since this is a help request. ]
across processes WM_COPYDATA can only use 0x4a Topic is solved
Re: across processes WM_COPYDATA can only use 0x4a
0x004A is the OS defined numeric identifier of the WM_COPYDATA message.
WinUser.h:
WinUser.h:
Code: Select all
#define WM_COPYDATA 0x004A
Re: across processes WM_COPYDATA can only use 0x4a
@just me
I know that
but same process,the 0x004A can change and work fine
So the WM_COPYDATA maybe not need 0x4a?
why across processes change 0x004A will not work?
I know that
but same process,the 0x004A can change and work fine
So the WM_COPYDATA maybe not need 0x4a?
why across processes change 0x004A will not work?
Re: across processes WM_COPYDATA can only use 0x4a
OnMessage
WM_COPYDATA clearly belongs to the latter category. All processes are designed to use 0x004A for such purposes.
Each process can have only one callback for 0x004A, so if there is a need to distinguish between processes when receiving a callback, consider using wParam appropriately.
In the official example, 0 is being passed, but in reality, you can pass any arbitrary value.
There are areas where users can specify themselves, and there are areas with established agreements between processes.MsgNumber wrote:The number of the message to monitor or query, which should be between 0 and 4294967295 (0xFFFFFFFF). If you do not wish to monitor a system message (that is, one below 0x0400), it is best to choose a number greater than 4096 (0x1000) to the extent you have a choice. This reduces the chance of interfering with messages used internally by current and future versions of AutoHotkey.
WM_COPYDATA clearly belongs to the latter category. All processes are designed to use 0x004A for such purposes.
Each process can have only one callback for 0x004A, so if there is a need to distinguish between processes when receiving a callback, consider using wParam appropriately.
In the official example, 0 is being passed, but in reality, you can pass any arbitrary value.
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: across processes WM_COPYDATA can only use 0x4a Topic is solved
Because any message number other than 0x004A will not be recognized and handled as WM_COPYDATA by the system.
Using WM_COPYDATA to marshal message parameters since the window manager otherwise doesn’t know how
Using WM_COPYDATA to marshal message parameters since the window manager otherwise doesn’t know how
Re: across processes WM_COPYDATA can only use 0x4a
@just me
Thx
I may understand
In across processes, use 0x4a system may process the data for read
In same processe, use other msg number system my not process the date
But it in same processe, so the data can be read
@Seven0528
COPYDATASTRUCT first parameter can also define use for
https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-copydatastruct
Thx
I may understand
In across processes, use 0x4a system may process the data for read
In same processe, use other msg number system my not process the date
But it in same processe, so the data can be read
@Seven0528
COPYDATASTRUCT first parameter can also define use for
https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-copydatastruct
Re: across processes WM_COPYDATA can only use 0x4a
@viv
I was trying to talk about the purpose of SendMessageTimeout's wParam, not the first dwData of COPYDATASTRUCT...
Ok. I had no idea what you were asking. I'm done. Sorry.
I was trying to talk about the purpose of SendMessageTimeout's wParam, not the first dwData of COPYDATASTRUCT...
Ok. I had no idea what you were asking. I'm done. Sorry.
Last edited by Seven0528 on 22 Jan 2024, 06:36, edited 1 time in total.
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: across processes WM_COPYDATA can only use 0x4a
@Seven0528
WM_COPYDATA is a msg id,it not a data
COPYDATASTRUCT is what WM_COPYDATA to send
you say wParam to distinguish between processes
I say in the data to send can define usefor
it a better way to distinguish userfor not by processes
WM_COPYDATA is a msg id,it not a data
COPYDATASTRUCT is what WM_COPYDATA to send
you say wParam to distinguish between processes
I say in the data to send can define usefor
it a better way to distinguish userfor not by processes
Re: across processes WM_COPYDATA can only use 0x4a
I am well aware of that. (I frequently use WM_COPYDATA.)
Could you provide a bit more detail about your question?
No matter how many times I read it, I couldn't grasp what you were asking or how @just me response addressed your curiosity.
Do you want to send some data within the same process? Why would you want to do that...?
Could you provide a bit more detail about your question?
No matter how many times I read it, I couldn't grasp what you were asking or how @just me response addressed your curiosity.
Do you want to send some data within the same process? Why would you want to do that...?
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: across processes WM_COPYDATA can only use 0x4a
@Seven0528
in same process is to test it can work fine
it just a test,not the final usefor
In across processes,generally memory can't read each other.
I didn't realize that.
so i change the msg number the send the same memory(data)
it not work
@just me tell me send data with 0x4a
system may process the memory for read in diffcult processe
in same process is to test it can work fine
it just a test,not the final usefor
In across processes,generally memory can't read each other.
I didn't realize that.
so i change the msg number the send the same memory(data)
it not work
@just me tell me send data with 0x4a
system may process the memory for read in diffcult processe
Re: across processes WM_COPYDATA can only use 0x4a
@viv WM_COPYDATA is the name for the value 0x004A. If you use any other number than that then it is NOT WM_COPYDATA. For example 0x0201 is WM_LBUTTONDOWN.
WM_COPYDATA is special in the way that @just me described, in the sense that the data is marshaled. That means the receiving process gets a copy of the data contained in COPYDATASTRUCT, but not the original data itself. If you send COPYDATASTRUCT without WM_COPYDATA then the memory addresses will be invalid: the receiving process would need to use ReadProcessMemory instead to access the data. If you are sending data inside the same process (for some unknown reason... you should never need that in AHK) then you could indeed use a custom message number created by RegisterWindowMessage, since the address space will be the same inside one process and the data doesn't need to be marshaled to be read by normal means (eg NumGet, StrGet).
I've outlined other ways to send data as well in my tutorial about IPC.
WM_COPYDATA is special in the way that @just me described, in the sense that the data is marshaled. That means the receiving process gets a copy of the data contained in COPYDATASTRUCT, but not the original data itself. If you send COPYDATASTRUCT without WM_COPYDATA then the memory addresses will be invalid: the receiving process would need to use ReadProcessMemory instead to access the data. If you are sending data inside the same process (for some unknown reason... you should never need that in AHK) then you could indeed use a custom message number created by RegisterWindowMessage, since the address space will be the same inside one process and the data doesn't need to be marshaled to be read by normal means (eg NumGet, StrGet).
I've outlined other ways to send data as well in my tutorial about IPC.
Re: across processes WM_COPYDATA can only use 0x4a
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
; 1.
F1:: {
SendBuffer("Hello", A_ScriptName " ahk_class AutoHotkey")
}
OnMessage 0x7000, ReceiveBuffer
ReceiveBuffer(wParam, lParam, msg, hwnd)
{
StringAddress := NumGet(lParam, 2*A_PtrSize, "Ptr")
CopyOfData := StrGet(StringAddress)
ToolTip A_ScriptName "`n" CopyOfData
return true
}
SendBuffer(StringToSend, TargetScriptTitle)
{
CopyDataStruct := Buffer(3*A_PtrSize)
SizeInBytes := (StrLen(StringToSend) + 1) * 2
NumPut( "Ptr", SizeInBytes
, "Ptr", StrPtr(StringToSend)
, CopyDataStruct, A_PtrSize)
Prev_DetectHiddenWindows := DetectHiddenWindows(True)
Prev_TitleMatchMode := SetTitleMatchMode(2)
RetValue := SendMessage(0x7000, 0, CopyDataStruct,, TargetScriptTitle,,,, 4000)
DetectHiddenWindows Prev_DetectHiddenWindows
SetTitleMatchMode Prev_TitleMatchMode
return RetValue
}
; 2.
F2:: {
static Str:="Hello" ; https://www.autohotkey.com/docs/v2/lib/StrPtr.htm#Remarks
SetData(&Str, &DataStruct)
GetData(&DataStruct)
}
SetData(&Str, &DataStruct) {
DataStruct := Buffer(3*A_PtrSize)
SizeInBytes := (StrLen(Str) + 1) * 2
NumPut( "Ptr", SizeInBytes
, "Ptr", StrPtr(Str)
, DataStruct, A_PtrSize)
}
GetData(&DataStruct) {
StringAddress := NumGet(DataStruct, 2*A_PtrSize, "Ptr")
Data := StrGet(StringAddress)
ToolTip A_ScriptName "`n" Data
}
F5::Run A_ScriptFullPath
Ah, I now understand your situation.
It seems like you were NOT attempting to use WM_COPYDATA.
Instead, you just passed the address of a Buffer to yourself using SendMessage and OnMessage.
Last edited by Seven0528 on 22 Jan 2024, 06:38, edited 1 time in total.
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: across processes WM_COPYDATA can only use 0x4a
@Descolada
Thx.
It's name is WM_COPYDATA
so it is a copy
I change the 0x4a
so it not a copy....
I understand
I just test, In across processes
lParam's memory address is changed
Thx.
It's name is WM_COPYDATA
so it is a copy
I change the 0x4a
so it not a copy....
I understand
I just test, In across processes
lParam's memory address is changed
Re: across processes WM_COPYDATA can only use 0x4a
@viv
Your words are correct.
However, that doesn't mean WM_COPYDATA is impossible within the same process. It's just useless...
I'm glad to be of help!
Your words are correct.
However, that doesn't mean WM_COPYDATA is impossible within the same process. It's just useless...
I'm glad to be of help!
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
OnMessage 0x004A, ReceiveBuffer ; WM_COPYDATA
OnMessage 0x7000, ReceiveBuffer ; The Msg value set arbitrarily by the user
F2::SendBuffer(0x004A, "Hello", A_ScriptName " ahk_class AutoHotkey")
F3::SendBuffer(0x7000, "Hello", A_ScriptName " ahk_class AutoHotkey")
ReceiveBuffer(wParam, lParam, msg, hwnd)
{
StringAddress := NumGet(lParam, 2*A_PtrSize, "Ptr")
CopyOfData := StrGet(StringAddress)
Msgbox "Msg`t`t: " format("0x{:04X}",msg) "`nReceiver Address`t: " lParam
return true
}
SendBuffer(msg, StringToSend, TargetScriptTitle)
{
CopyDataStruct := Buffer(3*A_PtrSize)
SizeInBytes := (StrLen(StringToSend) + 1) * 2
NumPut( "Ptr", SizeInBytes
, "Ptr", StrPtr(StringToSend)
, CopyDataStruct, A_PtrSize)
Prev_DetectHiddenWindows := DetectHiddenWindows(True)
Prev_TitleMatchMode := SetTitleMatchMode(2)
RetValue := SendMessage(msg, 0, CopyDataStruct,, TargetScriptTitle,,,, 4000)
Msgbox "Msg`t`t: " format("0x{:04X}",msg) "`nSender Address`t: " CopyDataStruct.Ptr
DetectHiddenWindows Prev_DetectHiddenWindows
SetTitleMatchMode Prev_TitleMatchMode
return RetValue
}
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: across processes WM_COPYDATA can only use 0x4a
@Seven0528
i dont say it not change in same processe
WM_COPYDATA client -> system -> system return a copy -> client
usermsg client -> system -> client
all msg need system forward
by the way
you can use A_ScriptHwnd instead A_ScriptName " ahk_class AutoHotkey"
i dont say it not change in same processe
WM_COPYDATA client -> system -> system return a copy -> client
usermsg client -> system -> client
all msg need system forward
by the way
you can use A_ScriptHwnd instead A_ScriptName " ahk_class AutoHotkey"