< prev index next >

src/jdk.incubator.jpackage/windows/native/applauncher/WinLauncher.cpp

Print this page




  83                 << "AddDllDirectory(" << dirPath << ") failed", func));
  84     }
  85 
  86     LOG_TRACE(tstrings::any() << "AddDllDirectory(" << dirPath << "): OK");
  87 
  88     // Important: use LOAD_LIBRARY_SEARCH_DEFAULT_DIRS flag,
  89     // but not LOAD_LIBRARY_SEARCH_USER_DIRS!
  90     HMODULE dllHandle = LoadLibraryEx(dllFullPath.c_str(), NULL,
  91             LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
  92 
  93     LOG_TRACE(tstrings::any() << "LoadLibraryEx(" << dllFullPath
  94             << ", LOAD_LIBRARY_SEARCH_DEFAULT_DIRS): " << dllHandle);
  95 
  96     const auto freeDll = runAtEndOfScope([&dllHandle]() -> void {
  97         Dll::freeLibrary(dllHandle);
  98     });
  99 
 100     return std::unique_ptr<Dll>(new Dll(dllFullPath));
 101 }
 102 









































 103 void launchApp() {
 104     // [RT-31061] otherwise UI can be left in back of other windows.
 105     ::AllowSetForegroundWindow(ASFW_ANY);
 106 
 107     const tstring launcherPath = SysInfo::getProcessModulePath();
 108     const tstring appImageRoot = FileUtils::dirname(launcherPath);
 109 
 110     std::unique_ptr<Jvm> jvm(AppLauncher()
 111         .setImageRoot(appImageRoot)
 112         .addJvmLibName(_T("bin\\jli.dll"))
 113         .setAppDir(FileUtils::mkpath() << appImageRoot << _T("app"))
 114         .setDefaultRuntimePath(FileUtils::mkpath() << appImageRoot
 115                 << _T("runtime"))
 116         .createJvmLauncher());
 117 
 118     std::unique_ptr<Dll> jvmDll;
 119     try {
 120         // Try load JVM DLL.
 121         jvmDll = std::unique_ptr<Dll>(new Dll(jvm->getPath()));
 122     } catch (const std::exception&) {
 123         // JVM DLL load failed, though it exists in file system.
 124         try {
 125             // Try adjust the DLL search paths with AddDllDirectory() WINAPI CALL
 126             jvmDll = loadDllWithAddDllDirectory(jvm->getPath());
 127         } catch (const std::exception&) {
 128             // AddDllDirectory() didn't work. Try altering PATH environment
 129             // variable as the last resort.
 130             jvmDll = loadDllWithAlteredPATH(jvm->getPath());
 131         }
 132     }
 133 
 134     jvm->launch();
 135 }
 136 
 137 } // namespace
 138 
 139 #ifndef JP_LAUNCHERW
 140 
 141 int __cdecl  wmain() {
 142     return AppLauncher::launch(std::nothrow, launchApp);
 143 }
 144 
 145 #else
 146 
 147 namespace {
 148 
 149 class LastErrorGuiLogAppender : public LogAppender {
 150 public:
 151     virtual void append(const LogEvent& v) {




  83                 << "AddDllDirectory(" << dirPath << ") failed", func));
  84     }
  85 
  86     LOG_TRACE(tstrings::any() << "AddDllDirectory(" << dirPath << "): OK");
  87 
  88     // Important: use LOAD_LIBRARY_SEARCH_DEFAULT_DIRS flag,
  89     // but not LOAD_LIBRARY_SEARCH_USER_DIRS!
  90     HMODULE dllHandle = LoadLibraryEx(dllFullPath.c_str(), NULL,
  91             LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
  92 
  93     LOG_TRACE(tstrings::any() << "LoadLibraryEx(" << dllFullPath
  94             << ", LOAD_LIBRARY_SEARCH_DEFAULT_DIRS): " << dllHandle);
  95 
  96     const auto freeDll = runAtEndOfScope([&dllHandle]() -> void {
  97         Dll::freeLibrary(dllHandle);
  98     });
  99 
 100     return std::unique_ptr<Dll>(new Dll(dllFullPath));
 101 }
 102 
 103 
 104 class DllWrapper {
 105 public:
 106     DllWrapper(const tstring& dllName) {
 107         try {
 108             // Try load DLL.
 109             dll = std::unique_ptr<Dll>(new Dll(dllName));
 110             LOG_TRACE(tstrings::any() << "Load [" << dllName << "]: OK");
 111         }
 112         catch (const std::exception&) {
 113             // JVM DLL load failed, though it exists in file system.
 114             try {
 115                 // Try adjust the DLL search paths with AddDllDirectory() WINAPI CALL
 116                 dll = loadDllWithAddDllDirectory(dllName);
 117             }
 118             catch (const std::exception&) {
 119                 // AddDllDirectory() didn't work. Try altering PATH environment
 120                 // variable as the last resort.
 121                 dll = loadDllWithAlteredPATH(dllName);
 122             }
 123         }
 124     }
 125 
 126 private:
 127     DllWrapper(const DllWrapper&);
 128     DllWrapper& operator=(const DllWrapper&);
 129 
 130 private:
 131     std::unique_ptr<Dll> dll;
 132 };
 133 
 134 
 135 tstring getJvmLibPath(const Jvm& jvm) {
 136     FileUtils::mkpath path;
 137 
 138     path << FileUtils::dirname(jvm.getPath()) << _T("server") << _T("jvm.dll");
 139 
 140     return path;
 141 }
 142 
 143 
 144 void launchApp() {
 145     // [RT-31061] otherwise UI can be left in back of other windows.
 146     ::AllowSetForegroundWindow(ASFW_ANY);
 147 
 148     const tstring launcherPath = SysInfo::getProcessModulePath();
 149     const tstring appImageRoot = FileUtils::dirname(launcherPath);
 150 
 151     std::unique_ptr<Jvm> jvm(AppLauncher()
 152         .setImageRoot(appImageRoot)
 153         .addJvmLibName(_T("bin\\jli.dll"))
 154         .setAppDir(FileUtils::mkpath() << appImageRoot << _T("app"))
 155         .setDefaultRuntimePath(FileUtils::mkpath() << appImageRoot
 156                 << _T("runtime"))
 157         .createJvmLauncher());
 158 
 159     const DllWrapper jliDll(jvm->getPath());
 160     std::unique_ptr<DllWrapper> splashDll;
 161     if (jvm->isWithSplash()) {
 162         const DllWrapper jvmDll(getJvmLibPath(*jvm));
 163         splashDll = std::unique_ptr<DllWrapper>(new DllWrapper(
 164                 FileUtils::mkpath() 
 165                         << FileUtils::dirname(jvm->getPath()) 
 166                         << _T("splashscreen.dll")));






 167     }
 168 
 169     jvm->launch();
 170 }
 171 
 172 } // namespace
 173 
 174 #ifndef JP_LAUNCHERW
 175 
 176 int __cdecl  wmain() {
 177     return AppLauncher::launch(std::nothrow, launchApp);
 178 }
 179 
 180 #else
 181 
 182 namespace {
 183 
 184 class LastErrorGuiLogAppender : public LogAppender {
 185 public:
 186     virtual void append(const LogEvent& v) {


< prev index next >