Are you using MFC project to do this? If so, don't. Write a native Win32
app that just spins in WinMain doing whatever you want it to do.
As long as you don't call CreateWindow() API you won't have any
windows.
Yeah, that's precisely what I am trying to do. But the "GDI+ Window"
appears anyway, even though I am not calling CreateWindow explicitly anywhere
in my code.
The entire shell app is one short .cpp. I'll post it here in case anybody
would like to comment on it.
thanks much,
--FritzM.
=================================================
//-------------------------------------------------------------
//
// File: Launcher.cpp
//
// Copyright 2005 (c) by Euphonix, Inc.
//
// Description:
//
// Simple shell application for XPE. Reads a registry entry
// (set via target designer) to find an init file. Reads the
// init file to find an app to launch and working dir to use.
// Launches the app and waits for the launched process to
// terminate.
//
// If failure occurs anywhere along the way, launches an XP
// command window as a failsafe.
//
// Author: Fritz Mueller
//
// Creation Date: 8/3/05
//
// Implementation Notes:
//
//-------------------------------------------------------------
#define WINVER 0x0501
#include <afxwin.h>
#include <tchar.h>
#include <sstream>
using namespace std;
typedef basic_ostringstream<TCHAR> tostringstream;
typedef basic_string<TCHAR> tstring;
class LauncherErr
{
public:
LauncherErr(DWORD iCode, const tstring &iDesc) : mCode(iCode), mDesc(iDesc)
{}
DWORD mCode;
tstring mDesc;
};
DWORD SpawnProcess(
const tstring &cmdline,
const tstring &workingdir,
DWORD creationFlags)
{
DWORD result;
BOOL success;
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
PROCESS_INFORMATION pi;
success = CreateProcess(
NULL, (LPTSTR)cmdline.c_str(), NULL, NULL, FALSE, creationFlags, NULL,
workingdir.empty() ? NULL : workingdir.c_str(), &si, &pi
);
if (!success) throw LauncherErr(GetLastError(), _T("Could not create
process."));
result = WaitForSingleObject(pi.hProcess, INFINITE);
if (result == WAIT_FAILED) throw LauncherErr(GetLastError(), _T("Process
wait failed."));
DWORD exitcode;
success = GetExitCodeProcess(pi.hProcess, &exitcode);
if (!success) throw LauncherErr(GetLastError(), _T("Could not retrieve
process exit code."));
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return exitcode;
}
int APIENTRY _tWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
DWORD result;
try {
HKEY key;
result = RegOpenKey(HKEY_LOCAL_MACHINE,
_T("Software\\Euphonix\\LauncherShell\\"), &key);
if (result != ERROR_SUCCESS) throw LauncherErr(GetLastError(), _T("Could
not open launcher registry key."));
DWORD valuetype;
TCHAR initpath[MAX_PATH];
DWORD initpathsize = sizeof(initpath);
result = RegQueryValueEx(key, _T("InitFile"), NULL, &valuetype,
(LPBYTE)initpath, &initpathsize);
if (result != ERROR_SUCCESS) throw LauncherErr(GetLastError(), _T("Could
not retrieve init file registry value."));
TCHAR cmdline[MAX_PATH];
DWORD cmdlinesize = MAX_PATH;
cmdlinesize = GetPrivateProfileString(_T("application"), _T("cmdline"),
NULL, cmdline, cmdlinesize, initpath);
if (cmdlinesize == 0) throw LauncherErr(GetLastError(), _T("Could not
retrieve command."));
TCHAR workingdir[MAX_PATH];
DWORD workingdirsize = MAX_PATH;
workingdirsize = GetPrivateProfileString(_T("application"),
_T("workingdir"), _T(""), workingdir, workingdirsize, initpath);
result = SpawnProcess(cmdline, workingdir, DETACHED_PROCESS);
}
catch(const LauncherErr &err) {
tostringstream str;
str << _T("cmd /k echo Euphonix Launcher Error (") << err.mCode << _T("):
") << err.mDesc << endl;
result = SpawnProcess(str.str(), _T(""), CREATE_NEW_CONSOLE);
}
return (result == ERROR_SUCCESS) ? 0 : -1;
}