int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR /*cmdParamarg*/, int cmdShow) #endif { QByteArray cmdParam = QString::fromWCharArray(GetCommandLine()).toLocal8Bit(); #if defined(Q_OS_WINCE) wchar_t appName[MAX_PATH]; GetModuleFileName(0, appName, MAX_PATH); cmdParam.prepend(QString(QLatin1String("\"%1\" ")).arg(QString::fromWCharArray(appName)).toLocal8Bit()); #endif int argc = 0; QVector<char *> argv(8); qWinMain(instance, prevInstance, cmdParam.data(), cmdShow, argc, argv); #if defined(Q_OS_WINCE) wchar_t uniqueAppID[MAX_PATH]; GetModuleFileName(0, uniqueAppID, MAX_PATH); QString uid = QString::fromWCharArray(uniqueAppID).toLower().replace(QLatin1String("\\"), QLatin1String("_")); // If there exists an other instance of this application // it will be the owner of a mutex with the unique ID. HANDLE mutex = CreateMutex(NULL, TRUE, (LPCWSTR)uid.utf16()); if (mutex && ERROR_ALREADY_EXISTS == GetLastError()) { CloseHandle(mutex); // The app is already running, so we use the unique // ID to create a unique messageNo, which is used // as the registered class name for the windows // created. Set the first instance's window to the // foreground, else just terminate. // Use bitwise 0x01 OR to reactivate window state if // it was hidden UINT msgNo = RegisterWindowMessage((LPCWSTR)uid.utf16()); HWND aHwnd = FindWindow((LPCWSTR)QString::number(msgNo).utf16(), 0); if (aHwnd) SetForegroundWindow((HWND)(((ULONG)aHwnd) | 0x01)); return 0; } #endif // Q_OS_WINCE int result = main(argc, argv.data()); #if defined(Q_OS_WINCE) CloseHandle(mutex); #endif return result; }
EXTERN_C int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR, int nShowCmd) { QT_USE_NAMESPACE qAxOutProcServer = true; GetModuleFileName(0, qAxModuleFilename, MAX_PATH); qAxInstance = hInstance; QByteArray cmdParam = QString::fromWCharArray(GetCommandLine()).toLocal8Bit(); QList<QByteArray> cmds = cmdParam.split(' '); QByteArray unprocessed; int nRet = 0; bool run = true; bool runServer = false; for (int i = 0; i < cmds.count(); ++i) { QByteArray cmd = cmds.at(i).toLower(); if (cmd == "-activex" || cmd == "/activex" || cmd == "-embedding" || cmd == "/embedding") { runServer = true; } else if (cmd == "-unregserver" || cmd == "/unregserver") { nRet = UpdateRegistry(false); run = false; break; } else if (cmd == "-regserver" || cmd == "/regserver") { nRet = UpdateRegistry(true); run = false; break; } else if (cmd == "-dumpidl" || cmd == "/dumpidl") { ++i; if (i < cmds.count()) { QByteArray outfile = cmds.at(i); ++i; QByteArray version; if (i < cmds.count() && (cmds.at(i) == "-version" || cmds.at(i) == "/version")) { ++i; if (i < cmds.count()) version = cmds.at(i); else version = "1.0"; } nRet = DumpIDL(QString::fromLatin1(outfile.constData()), QString::fromLatin1(version.constData())); } else { qWarning("Wrong commandline syntax: <app> -dumpidl <idl file> [-version <x.y.z>]"); } run = false; break; } else { unprocessed += cmds.at(i) + ' '; } } if (run) { if (SUCCEEDED(CoInitialize(0))) { int argc; QVector<char*> argv(8); qWinMain(hInstance, hPrevInstance, unprocessed.data(), nShowCmd, argc, argv); qAxInit(); if (runServer) QAxFactory::startServer(); nRet = ::main(argc, argv.data()); QAxFactory::stopServer(); qAxCleanup(); CoUninitialize(); } else { qErrnoWarning("CoInitialize() failed."); nRet = -1; } } return nRet; }