Я собрал множество онлайн-ресурсов, которые привели меня сюда. Надеюсь, что у меня есть близко. К сожалению, у меня нет опыта программирования на Windows. Я родом из Linux. Я также новичок в alien для Lua, но я знаю Lua достаточно хорошо.Lua Alien - SendMessage to Notepad.exe с WinAPI
Что я хочу сделать, это отправить простой «Hello World» с sendMessage()
из Win32 API
в бегущее окно Notepad.exe
.
Я получил идентификатор процесса из командной строки с помощью следующей команды:
tasklist /FI "IMAGENAME eq notepad.exe" /FI "USERNAME eq user"
И я получил сообщение, чтобы отправить код из 0x000C из here.
До сих пор это то, что у меня есть:
require "luarocks.require"
require "alien"
myTestMessage = 0x000C -- Notepad "Set text" id
notepadPID = 2316 -- Notepad Process ID
-- Prototype the SendMessage function from User32.dll
local SendMessage= alien.User32.SendMessageA
SendMessage:types{ret ='long', abi = 'stdcall','long','long','string','string'}
-- Prototype the FindWindowExA function from User32.dll
local FindWindowEx = alien.User32.FindWindowExA
FindWindowEx:types{ret = 'long', abi = 'stdcall', 'long', 'long', 'string', 'string'}
-- Prototype the GetWindowThreadProcessID function from User32.dll
local GetWindowThreadProcessId = alien.User32.GetWindowThreadProcessId
GetWindowThreadProcessId:types{ret = 'long', abi = 'stdcall', 'long', 'pointer'}
local buffer = alien.buffer(4) -- This creates a 4-byte buffer
local threadID = GetWindowThreadProcessId(notepadPID, buffer) -- this fills threadID and our 4-byte buffer
local longFromBuffer = buffer:get(1, 'long') -- this tells that I want x bytes forming a 'long' value and starting at the first byte of the
-- 'buffer' to be in 'longFromBuffer' variable and let its type be 'long'
local handle = FindWindowEx(threadID, "0", "Edit", nil); -- Get the handle to send the message to
local x = SendMessage(handle, myTestMessage, "0", "Hello World!") -- Actually send the message
Много этого кода была собрана из Lua alien documents, msdn, и некоторые Google поиск (namely this result).
Есть ли кто-нибудь, кто мог бы стать героем и объяснить мне, что я делаю неправильно, и как я должен это делать. И, самое главное, почему!