How to get return a value from WndProc()  
Author Message
DeepakGupta





PostPosted: .NET Framework Networking and Communication, How to get return a value from WndProc() Top

Hi,

In a C# application, I am SendMessage () function defined in user32.dll and accepting the call in another C# application by overriding the WndProc (ref Message m) function.

I need to return a value (0 or 1) from WndProc to the process where SendMessage () was called.

I tired the Result member of Message to do the same but was unsuccessful.

Can anybody suggest something that that could be helpful.

Thanks.

Deepak



.NET Development20  
 
 
Mattias Sjogren





PostPosted: .NET Framework Networking and Communication, How to get return a value from WndProc() Top

Setting Message.Result should work. What happens if you try it Can you post relevant parts of your code.



 
 
DeepakGupta





PostPosted: .NET Framework Networking and Communication, How to get return a value from WndProc() Top

Hi Mattias,

In the application where the windows message is handles, the following code is there:

protected override void WndProc ( ref Message m )
{
// process the message
if (FlagsAttribute)
m.Result = (IntPtr)1;
else
m.Result = (IntPtr)0;
}

The code of the application thats raises the windows message is as below:

......
long result = 0;
result = SendMessage(hnd, mymessage, 0, ref cds);
.... process according to the value of result

The value of result is always a large non-zero value which cannot be convert to IntPtr.

If you know any options or settings that needs to be set for this to work, please reply.

Thanks

Best Regards,
Deepak Gupta


 
 
Mattias Sjogren





PostPosted: .NET Framework Networking and Communication, How to get return a value from WndProc() Top

long result = 0;
result = SendMessage(hnd, mymessage, 0, ref cds);
.... process according to the value of result

The value of result is always a large non-zero value which cannot be convert to IntPtr.

You shouldn't have to convert it. Make the SendMessage return type an IntPtr and you should get the correct value.



 
 
DeepakGupta





PostPosted: .NET Framework Networking and Communication, How to get return a value from WndProc() Top

Hi Mattias,

Thanks for the reply and the suggestion. It did worked. All I did was change the return type of the SendMessage () function from long to IntPtr and the type-casted the returend IntPtr to Int as shown below.

....
IntPtr resultPtr = Win32.SendMessage(Hnd, myMessage, 0, ref cds);
int result = resultPtr.ToInt32();

....

Thanks a lot,

Deepak