Re: Problem with EnumDesktopWindows

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



SendMessage, PostMessage, and other messgae-related APIs are defined NOT to work across
desktops. In fact, inter-desktop communication is, as far as I know, impossible. You
can't use shared-memory DLLs, you can't send messages, and so on. You could consider
starting up a second program in the same desktop, let IT find an manipulate the windows,
and communicate to it via a valid communication mechanism, where the typical first choice
is to use a named pipe (named pipe communication does not care about desktops). There is
a problem if two or more instances of the program are running in two or more desktops,
because the named pipe name would pose a problem unless you included the desktop name as
part of the name, e.g., if the desired pipe name was "Controller" then you might create a
pipe called Desktop1-Controller for a desktop called Desktop1. Then you could send
messages via the named pipe to Desktop1-Controller, and it in turn would do a SendMessage
or PostMessage to the app which was also running in Desktop1. This would remove the
ambiguity problem..
joe

On Sat, 3 Feb 2007 17:59:00 -0800, ThaMubber <ThaMubber@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Hi,

I have here a foreign MFC application A which I have to control with my own
program B.
The user has to start B which creates a second Desktop, because A must run
hidden.

[cpp]
...
secDesk.nLength = sizeof(secDesk);
secDesk.lpSecurityDescriptor = NULL;
secDesk.bInheritHandle = true;
...

hdesk =
CreateDesktopW(desktop,NULL,NULL,DF_ALLOWOTHERACCOUNTHOOK,GENERIC_ALL,&secDesk);
[/cpp]

After creating the Desktop, B must run the method LogonUser, because the
foreign application A needs admin privileges to run.

[cpp]

LogonUser(L"Administrator",L".",L"password",LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,&hToken)

[/cpp]



Now I have to run the foreign application (as Admin):

[cpp]
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;

securProc.nLength = sizeof(securProc);
securProc.lpSecurityDescriptor = NULL;
securProc.bInheritHandle = true;

if(CreateProcessAsUser(hToken,NULL,file,&securProc,NULL,TRUE,0,NULL,dir,&si,&piProc))
{
WaitForInputIdle(piProc.hProcess,INFINITE);
wi.dwProcessID = piProc.dwProcessId;
wi.hWnd = 0;
}

[/cpp]

Everything works well till here (i think).

But now the problem, my program B must control the foreign program A.

So I have to do this to get a handle of the running window

[cpp]

EnumDesktopWindows(hdesk,EnumWindowsProc,(LPARAM) &wi);

....

BOOL CALLBACK MyProg::EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
WNDINFO* pWndInfo = (WNDINFO*)(lParam);
DWORD dwProcessID;

::GetWindowThreadProcessId(hwnd, &dwProcessID);
if (dwProcessID == pWndInfo->dwProcessID)
{
pWndInfo->hWnd = hwnd;
return false;
}
return true;
}


[/cpp]


With controlling I mean that I search for some text on the foreign MFC
Dialog and do
some PostMessage for clicking on the existing Buttons on it.

Thats the whole thing. But my problem is that i don't get a handle to work
with.

Where is my mistake?


PS.: If something is unclear, please let me know.



Thanks
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Problem with EnumDesktopWindows
    ... In fact, inter-desktop communication is, as far as I know, impossible. ... is to use a named pipe. ... I have here a foreign MFC application A which I have to control with my own ...
    (microsoft.public.vc.mfc)
  • Re: advice on messaging between threads
    ... you write yourself or a Point-to-Point message queue provided by the ... For sending stuff to the GUI, you could PostMessage() a custom message ... sets some variables if there is communication error. ... to passed to third thread graphics. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Bye bye Palin?
    ... Which was, explicitly, a violation of the Foreign Intelligence ... and someone in the US requires a FISA warrant. ... His "other than" implies that a communication that does involve ... foreign powers does not require a FISA order. ...
    (rec.arts.sf.fandom)
  • Re: Bye bye Palin?
    ... Which was, explicitly, a violation of the Foreign Intelligence ... Any communication which *might* involve persons ... and someone in the US requires a FISA warrant. ... foreign power on one end and someone inside the US on the other is ...
    (rec.arts.sf.fandom)
  • Re: Windows Services
    ... so just read the appropriate examples in the MSDN. ... The only problem remaining is how to establish the communication. ... use a named pipe as the means of communication. ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)