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);
}









share|improve this question




















  • 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












  • @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




    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




    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















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);
}









share|improve this question




















  • 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












  • @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




    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




    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













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);
}









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 5:57









John

10.4k31734




10.4k31734










asked Nov 21 at 5:53









SillySam

526




526








  • 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












  • @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




    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




    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




    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






  • 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






  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...