//
// Integrated browser mode - package up a bunch of data into a COPYDATASTRUCT,
// and send it to the desktop window via SendMessage(WM_COPYDATA).
//
void LaunchInternetExplorerWithoutProcess()
{
#define MAX_IEEVENTNAME 32
// First piece of data is a wide string version of the command line.
WCHAR wsz[MAX_IEEVENTNAME] = L"";
COPYDATASTRUCT cds = { SW_NORMAL, sizeof(WCHAR), wsz };
// Second piece of data is the event to fire when the browser window reaches WM_CREATE.
static DWORD dwNextId = 0;
TCHAR szEvent[MAX_IEEVENTNAME + 1];
wsprintf(szEvent, TEXT("IE-%08X-%08X"), GetCurrentThreadId(), dwNextId++);
HANDLE hEventReady = CreateEvent(NULL, FALSE, FALSE, szEvent);
if(hEventReady)
{
// Put the (UNICODE) event name at the end of the cds data
LPWSTR pwszEvent = &wsz[1];
#ifdef UNICODE
lstrcpy(pwszEvent, szEvent);
#else
MultiByteToWideChar(CP_ACP, 0, szEvent, -1, pwszEvent, sizeof(szEvent) / sizeof(szEvent[0]));
#endif
cds.cbData += (lstrlenW(pwszEvent) + 1) * sizeof(WCHAR);
// Send the message
HWND hwndDesktop = GetShellWindow();
int iRet = (int)SendMessage(hwndDesktop, WM_COPYDATA, (WPARAM)hwndDesktop, (LPARAM)&cds);
if(iRet)
{
// Wait for the browser window to hit WM_CREATE.
// When this happens, all DDE servers will have been registered.
DWORD dwRet = WaitForSingleObject(hEventReady, 1000 * 10); // 10 seconds
#ifdef ASSERT
ASSERT(dwRet == WAIT_OBJECT_0);
#endif // ASSERT
}
CloseHandle(hEventReady);
}
#undef MAX_IEEVENTNAME
}