开发者

Question on C# App MessageBox.Show() that called by Cpp App CreateProcess()

I have done 2 tests.

I got two applications that ran on the same computer. 1st time, when I click my CsAPP.exe. the MessageBox.Show() works quite well and a new window pop-up the way I wished.

2nd time, when I run CppAPP.exe there is a CreateProcess() to call CsApp.exe. At this point, my MessageBox.Show() doesn't work. I set breakpoint to my CsApp code and verfied that the code ran to MessageBox.Show() but the Pop-up window didn't show up.

C++ code snippet

CreateProcess(apppath.c_str(), NULL, &sa, &sa, FALSE, 0, NULL, appdir.c_str(), &si, &pi);

C# code snippet

MessageBox.Show("Read " + xmlFile + " failed, an invalid XML 开发者_运维百科format file found",
                "Critical Warning",
                MessageBoxButtons.OK,
                MessageBoxIcon.Error);

Any replies and comments are appreciated.

[Updated on Aug 23rd]

I consulted one guy. And He said that the MessageBox showed on another invisible desktop actually for my test2. He recommended me to read a book named 'Windows internals'. If any found I will update my post later. Thanks.


Try creating the Process in the user Context.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682429%28v=vs.85%29.aspx

As far as i read, your problem is described here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx

If the calling process is impersonating another user, the new process uses the token for the calling process, not the impersonation token. To run the new process in the security context of the user represented by the impersonation token, use the CreateProcessAsUser or CreateProcessWithLogonW function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜