We help IT Professionals succeed at work.

RegisterWindowMessage() question

astankovic
astankovic asked
on
1,837 Views
Last Modified: 2007-12-19
Ok, I think this is the last piece of the puzzle that I need to find before making this work.
See https://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20826109.html for more info.

According to MSDN if two different applications call RegisterWindowMessage() passing the same string they should get the same message.

Well this is not working for me, and it might be because I app is C# and another is C++ DLL. I get different values returned by a call from C++ DLL and from C# (which is importing RegisterWindowMessage() from user32.dll

Is it due to different data types being passed to the function? In C++ I’m passing LPCTSTR, but in C# it’s a string type?!

Thanks,
Alex
Comment
Watch Question

jkr
CERTIFIED EXPERT
Top Expert 2012
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I just tried that, and still getting different values:
DLL gets 49653 but C# app gets 49818 for the same string "TIMETRACKER_PC_LOCK"
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
Are both applications using managed code or is the C++ app 'unmanaged'? BTW, if the problem persists, you might want to use a workaround like having the 1st app to register the message write the value to a special location in the registry...

Author

Commented:
C++ is unmanaged VC++ 6 application. I don't really want to write to registry, i might try to return the message value from the function that is called to set hWnd.

Thanks for your help,
Alex
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>i might try to return the message value from the function that is called to set hWnd.

That's an even better workaround. Nevertheless, this API is supposed to work the way it's advertised, so this is quite a bummer :-(

Commented:
Are these two modules possibly executing under different user accounts.

Author

Commented:
jkr,
I know. All I wanted to do is to respond to "computer lock" and "computer unlock" events in my little C# app. It turns out the only way to do this "right" is to register a C++ DLL to be notified by Winlogon.exe whenever that happens. So here am I trying to write a C++ DLL for the first time :)

_ys_,
No, they are executing under the same user account. I am not sure what are you getting at?

Thanks,
Alex
CERTIFIED EXPERT
Author of the Year 2009
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Author of the Year 2009

Commented:
I used a search string of:
     RegisterWindowMessage and desktop
here:
    http://groups.google.com

Author

Commented:
Thanks all
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.