SendMessage always returns zero
up vote
1
down vote
favorite
I am using the User32 SendMessage
function to send raw keyboard input to my API.
The function that intercepts the SendMessage
call is the WndProc
function. I need to receive this data back where SendMessage
was called from. I have tried setting the message.Result
and saving the SendMessage
function to an int, but every time it equals 0. How can I obtain this return data?
Calling the Function
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, int wParam, ref Rawkeyboard lParam);
public void SomeFunction(...){
int result = SendMessage(Hook, 0x1230FF, 0, ref lParamKeyboard).ToInt32(); // Send data
Console.WriteLine(result);
}
Responding to the call
protected override void WndProc(ref Message message){
switch (message.Msg){
case 0x1230FF: {
message.Result = (IntPtr)6; // Set result as 6 (just for testing)
}
break;
}
base.WndProc(ref message);
}
c# user32
add a comment |
up vote
1
down vote
favorite
I am using the User32 SendMessage
function to send raw keyboard input to my API.
The function that intercepts the SendMessage
call is the WndProc
function. I need to receive this data back where SendMessage
was called from. I have tried setting the message.Result
and saving the SendMessage
function to an int, but every time it equals 0. How can I obtain this return data?
Calling the Function
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, int wParam, ref Rawkeyboard lParam);
public void SomeFunction(...){
int result = SendMessage(Hook, 0x1230FF, 0, ref lParamKeyboard).ToInt32(); // Send data
Console.WriteLine(result);
}
Responding to the call
protected override void WndProc(ref Message message){
switch (message.Msg){
case 0x1230FF: {
message.Result = (IntPtr)6; // Set result as 6 (just for testing)
}
break;
}
base.WndProc(ref message);
}
c# user32
1
After you setmessage.Result
, you then callbase.WndProc(ref message)
which will modify the message further. Also, window message numbers go up to 65535. 0x1230ff is out of range.
– Raymond Chen
Nov 21 at 6:33
@RaymondChen I have changed the message number to0x00FF
as well as not executingbase.WndProc(ref message)
if the case is my message, still not working ;( any other suggestions?
– SillySam
Nov 21 at 7:16
1
Message0x00FF
is already defined by the system asWM_INPUT
. Class custom messages must be in the range0x0400
to0x7FFF
. App custom messages must be in the range0x8000
to0xBFFF
.
– Raymond Chen
Nov 21 at 7:33
1
This isn't broken. Simplest explanation is that you used the wrong window handle. Start VS a second time and use it to debug the app with the WndProc call. Set a breakpoint to verify that code actually runs.
– Hans Passant
Nov 21 at 9:43
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am using the User32 SendMessage
function to send raw keyboard input to my API.
The function that intercepts the SendMessage
call is the WndProc
function. I need to receive this data back where SendMessage
was called from. I have tried setting the message.Result
and saving the SendMessage
function to an int, but every time it equals 0. How can I obtain this return data?
Calling the Function
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, int wParam, ref Rawkeyboard lParam);
public void SomeFunction(...){
int result = SendMessage(Hook, 0x1230FF, 0, ref lParamKeyboard).ToInt32(); // Send data
Console.WriteLine(result);
}
Responding to the call
protected override void WndProc(ref Message message){
switch (message.Msg){
case 0x1230FF: {
message.Result = (IntPtr)6; // Set result as 6 (just for testing)
}
break;
}
base.WndProc(ref message);
}
c# user32
I am using the User32 SendMessage
function to send raw keyboard input to my API.
The function that intercepts the SendMessage
call is the WndProc
function. I need to receive this data back where SendMessage
was called from. I have tried setting the message.Result
and saving the SendMessage
function to an int, but every time it equals 0. How can I obtain this return data?
Calling the Function
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, int wParam, ref Rawkeyboard lParam);
public void SomeFunction(...){
int result = SendMessage(Hook, 0x1230FF, 0, ref lParamKeyboard).ToInt32(); // Send data
Console.WriteLine(result);
}
Responding to the call
protected override void WndProc(ref Message message){
switch (message.Msg){
case 0x1230FF: {
message.Result = (IntPtr)6; // Set result as 6 (just for testing)
}
break;
}
base.WndProc(ref message);
}
c# user32
c# user32
edited Nov 21 at 5:57
John
10.4k31734
10.4k31734
asked Nov 21 at 5:53
SillySam
526
526
1
After you setmessage.Result
, you then callbase.WndProc(ref message)
which will modify the message further. Also, window message numbers go up to 65535. 0x1230ff is out of range.
– Raymond Chen
Nov 21 at 6:33
@RaymondChen I have changed the message number to0x00FF
as well as not executingbase.WndProc(ref message)
if the case is my message, still not working ;( any other suggestions?
– SillySam
Nov 21 at 7:16
1
Message0x00FF
is already defined by the system asWM_INPUT
. Class custom messages must be in the range0x0400
to0x7FFF
. App custom messages must be in the range0x8000
to0xBFFF
.
– Raymond Chen
Nov 21 at 7:33
1
This isn't broken. Simplest explanation is that you used the wrong window handle. Start VS a second time and use it to debug the app with the WndProc call. Set a breakpoint to verify that code actually runs.
– Hans Passant
Nov 21 at 9:43
add a comment |
1
After you setmessage.Result
, you then callbase.WndProc(ref message)
which will modify the message further. Also, window message numbers go up to 65535. 0x1230ff is out of range.
– Raymond Chen
Nov 21 at 6:33
@RaymondChen I have changed the message number to0x00FF
as well as not executingbase.WndProc(ref message)
if the case is my message, still not working ;( any other suggestions?
– SillySam
Nov 21 at 7:16
1
Message0x00FF
is already defined by the system asWM_INPUT
. Class custom messages must be in the range0x0400
to0x7FFF
. App custom messages must be in the range0x8000
to0xBFFF
.
– Raymond Chen
Nov 21 at 7:33
1
This isn't broken. Simplest explanation is that you used the wrong window handle. Start VS a second time and use it to debug the app with the WndProc call. Set a breakpoint to verify that code actually runs.
– Hans Passant
Nov 21 at 9:43
1
1
After you set
message.Result
, you then call base.WndProc(ref message)
which will modify the message further. Also, window message numbers go up to 65535. 0x1230ff is out of range.– Raymond Chen
Nov 21 at 6:33
After you set
message.Result
, you then call base.WndProc(ref message)
which will modify the message further. Also, window message numbers go up to 65535. 0x1230ff is out of range.– Raymond Chen
Nov 21 at 6:33
@RaymondChen I have changed the message number to
0x00FF
as well as not executing base.WndProc(ref message)
if the case is my message, still not working ;( any other suggestions?– SillySam
Nov 21 at 7:16
@RaymondChen I have changed the message number to
0x00FF
as well as not executing base.WndProc(ref message)
if the case is my message, still not working ;( any other suggestions?– SillySam
Nov 21 at 7:16
1
1
Message
0x00FF
is already defined by the system as WM_INPUT
. Class custom messages must be in the range 0x0400
to 0x7FFF
. App custom messages must be in the range 0x8000
to 0xBFFF
.– Raymond Chen
Nov 21 at 7:33
Message
0x00FF
is already defined by the system as WM_INPUT
. Class custom messages must be in the range 0x0400
to 0x7FFF
. App custom messages must be in the range 0x8000
to 0xBFFF
.– Raymond Chen
Nov 21 at 7:33
1
1
This isn't broken. Simplest explanation is that you used the wrong window handle. Start VS a second time and use it to debug the app with the WndProc call. Set a breakpoint to verify that code actually runs.
– Hans Passant
Nov 21 at 9:43
This isn't broken. Simplest explanation is that you used the wrong window handle. Start VS a second time and use it to debug the app with the WndProc call. Set a breakpoint to verify that code actually runs.
– Hans Passant
Nov 21 at 9:43
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406007%2fsendmessage-always-returns-zero%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
After you set
message.Result
, you then callbase.WndProc(ref message)
which will modify the message further. Also, window message numbers go up to 65535. 0x1230ff is out of range.– Raymond Chen
Nov 21 at 6:33
@RaymondChen I have changed the message number to
0x00FF
as well as not executingbase.WndProc(ref message)
if the case is my message, still not working ;( any other suggestions?– SillySam
Nov 21 at 7:16
1
Message
0x00FF
is already defined by the system asWM_INPUT
. Class custom messages must be in the range0x0400
to0x7FFF
. App custom messages must be in the range0x8000
to0xBFFF
.– Raymond Chen
Nov 21 at 7:33
1
This isn't broken. Simplest explanation is that you used the wrong window handle. Start VS a second time and use it to debug the app with the WndProc call. Set a breakpoint to verify that code actually runs.
– Hans Passant
Nov 21 at 9:43