1

I am setting up a scratch desktop to run another application in a "silent mode" - the other app is noisy and throws all sorts of windows around while it processes.

I have used the info here: CreateDesktop() with vista and UAC on (C, windows)

and CreateDesktop works - I can create the other desktop, I can launch the application into the other desktop (I see it launching in task manager) - but when I try to interact with the app via DDE, the DdeConnect call hangs until it times out.

And here's how I'm calling CreateDesktop:

                LPSTR desktopName = "MYDESKTOPNAME";
                HDESK hDesk = CreateDesktop(desktopName , NULL, NULL, 0, DESKTOP_SWITCHDESKTOP|
                                          DESKTOP_WRITEOBJECTS|
                                          DESKTOP_READOBJECTS|
                                          DESKTOP_ENUMERATE|
                                          DESKTOP_CREATEWINDOW|
                                          DESKTOP_CREATEMENU, NULL);

Here is CreateProcess to actually launch the app into the new desktop:

                STARTUPINFO startupInfo;
                GetStartupInfo(&startupInfo);
                startupInfo.lpDesktop = desktopName;

                PROCESS_INFORMATION procInfo;
                memset(&procInfo, 0, sizeof(procInfo));


                if (CreateProcess(NULL, exePath, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &startupInfo, &procInfo)){
                    WaitForInputIdle(procInfo.hProcess, INFINITE);
                    CloseHandle(procInfo.hProcess);
                    CloseHandle(procInfo.hThread);
                }

If it matters, the call to DdeInitialize:

DWORD afCmd = APPCLASS_STANDARD | APPCMD_CLIENTONLY | CBF_SKIP_ALLNOTIFICATIONS;
UINT rslt = ::DdeInitialize(&ddeInst, NULL, afCmd, 0);

Here is the DdeConnect call (the hsz* parameters, etc... are all fine - if I launch the app into the regular desktop, the calls all work perfectly).

        hConv = ::DdeConnect(ddeInst,
                               hszService,
                               hszTopic,
                               NULL);

This call just hangs for ~60 seconds.

Is this a security issue of some sort? i.e. the windows messages aren't passing between desktops? Or does anyone have any suggestion on how to troubleshoot this further?

Community
  • 1
  • 1
Kevin Day
  • 16,067
  • 8
  • 44
  • 68

2 Answers2

4

The documentation for CreateDesktop contains a cross-reference to the Desktops topic, which says

Window messages can be sent only between processes that are on the same desktop.

The overview topics are important. They provide background information to help you understand the feature.

Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
  • I am honored - been reading your blog for years. I'll move the controlling process into the same desktop - thanks! – Kevin Day Feb 03 '12 at 17:24
1

Raymond explains why the messages don't get through. In order to solve the problem, assuming you continue with the separate desktop, you will simply need to run the process that performs the DDE in the same desktop as the target app. If you need to communicate between your process on the main desktop and the target process then you will need to use some other form of IPC.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490