View Full Version : User32.dll and sendmessageA
clueless
02-27-2008, 12:09 PM
I've been looking at Worms excellent example of using user32.dll to send text between open windows in AMS as i want to make a program in another laguage that communicates with AMS but im not to sure how to use the 'SendMessageA" function.
From Worms Code :
function SendTo(nHandle, sMessage)
-- set the text
DLL.CallFunction(_SystemFolder.."\\User32.dll", "SendMessageA", nHandle..",12,0,\"~||~"..sMessage.."\"", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL)
-- send keypress to fire event
DLL.CallFunction(_SystemFolder.."\\User32.dll", "SendMessageA", nHandle..",256,0,13", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL)
end
The syntax for the function call is;
hwnd As Long,wMsg As Long,wParam As Long, lParam As Any
How can i construct the line
nHandle..",12,0,\"~||~"..sMessage.."\""
in another language like visual basic or VC++?
Also would the DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL stay the same?
You can do the same thing from VB
'Declare SendMessage
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Long) As Long
clueless
04-03-2008, 05:13 AM
Thanks i found the SendMessage function before its just i dont know what Lparam and wparam and i cant find any helpful info on the function .
MSDN2
Message..::.LParam Property
Specifies the LParam field of the message.
If you're looking to do the same as I did, simply use the same values as I did in the AMS app. If you're looking for more info on the parameters, all I can say is Google is your friend.
clueless
04-03-2008, 12:58 PM
thanks, finding the simple info allways seems to be the hardest task. :)
clueless
04-13-2008, 10:07 PM
I had another go at trying to get VB and AMS to talk to eachother tonight and ive worked out how the line
nHandle..",12,0,\"~||~"..sMessage.."\""
works in AMS.(I didnt realise it was a mix of code and regular strings.) I see that it translates to
nHandle,12,0,"~||~AndSomeMessage"
But im not sure if this has to be converted in anyway to work in visual basic ? Or would it be something simple like:
Call SendMessage(nHandle, 12, 0, "~||~AndSomeMessage")
thanks
clueless
06-09-2008, 12:26 PM
Is there anyone out there with enough VB experience to know the correct syntax for the code? Ive been trying to get this right for a while and im getting noware with it. Im a bit dyslexic so guessing the right syntax is a bit of a nightmare for me, but with an example to work from i have no problems :)
reteset
06-12-2008, 01:09 PM
actually ,
i have no knowledge about VB
but your question is a WINAPI question
and any programmer can reply your question
so :
SendMessage(HWND hWnd,UINT Msg, WPARAM wParam,LPARAM lParam);
hWnd : Window Handle That You Send Message To
Msg : A Predefined Message Or Registered By The RegisterWindowMessage()
wParam : This Is A Message Specific Data , Can Be In Any Type
(int,bool,string) And Must Be Converted To WPARAM
lParam : Second Message Specific Data , Can Be In Any Type
(int,bool,string) And Must Be Converted To LPARAM
An Example In C++
set a new icon for a window
HICON icon = LoadIcon();
SendMessage(hWnd,WM_SETICON, ICON_SMALL,(LPARAM)(LONG)icon);
Another One :
set a new text for a window
CString sz_newtitle;
sz_newtitle = "hello world";
SendMessage(hWnd,WM_SETTEXT, 0,(LPARAM)sz_newtitle);
finally LPARAM and WPARAM are specific datas for message that you used
and can be in any type
good bye
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.