tags:

views:

18

answers:

2

When you have a console based client and a COM Server, can you call ::MessageBox(...) from the COM Server and expect it to work?

+1  A: 

Yes, you can, but in some cases the box will be shown on another desktop and effectively block the calling thread, so you better not try this other than for debugging purposes.

sharptooth
You can make sure the message box ownership is correct by setting the parent parameter to the console HWND, instead of NULL (desktop HWND). See `http://support.microsoft.com/kb/124103`
Ryan Ginstrom
A: 

You can use WTSSendMessage function (see http://msdn.microsoft.com/en-us/library/aa383842.aspx and http://msdn.microsoft.com/en-us/library/ms683502.aspx) instead of MessageBox.

To get the session id SessionId you can use WTS_CURRENT_SESSION or WTSEnumerateSessions or WTSGetActiveConsoleSessionId or GetTokenInformation with TokenSessionId and a clients token received during client impersonation. All depends on the scenarios which you have.

Oleg