< 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, bool isClientJvm) {
 136     FileUtils::mkpath path;
 137     path << FileUtils::dirname(jvm.getPath());
 138     if (isClientJvm) {
 139         path << _T("client");
 140     } else {
 141         path << _T("server");
 142     }
 143     path << _T("jvm.dll");
 144 
 145     if (isClientJvm && !FileUtils::isFileExists(path)) {
 146         return getJvmLibPath(jvm, false);
 147     }
 148 
 149     return path;
 150 }
 151 
 152 
 153 void launchApp() {
 154     // [RT-31061] otherwise UI can be left in back of other windows.
 155     ::AllowSetForegroundWindow(ASFW_ANY);
 156 
 157     const tstring launcherPath = SysInfo::getProcessModulePath();
 158     const tstring appImageRoot = FileUtils::dirname(launcherPath);
 159 
 160     std::unique_ptr<Jvm> jvm(AppLauncher()
 161         .setImageRoot(appImageRoot)
 162         .addJvmLibName(_T("bin\\jli.dll"))
 163         .setAppDir(FileUtils::mkpath() << appImageRoot << _T("app"))
 164         .setDefaultRuntimePath(FileUtils::mkpath() << appImageRoot
 165                 << _T("runtime"))
 166         .createJvmLauncher());
 167 
 168     const DllWrapper jliDll(jvm->getPath());
 169     std::unique_ptr<DllWrapper> splashDll;
 170     if (jvm->isWithSplash()) {
 171         const DllWrapper jvmDll(getJvmLibPath(*jvm, jvm->isClientJvm()));
 172         splashDll = std::unique_ptr<DllWrapper>(new DllWrapper(
 173                 FileUtils::mkpath() 
 174                         << FileUtils::dirname(jvm->getPath()) 
 175                         << _T("splashscreen.dll")));






 176     }
 177 
 178     jvm->launch();
 179 }
 180 
 181 } // namespace
 182 
 183 #ifndef JP_LAUNCHERW
 184 
 185 int __cdecl  wmain() {
 186     return AppLauncher::launch(std::nothrow, launchApp);
 187 }
 188 
 189 #else
 190 
 191 namespace {
 192 
 193 class LastErrorGuiLogAppender : public LogAppender {
 194 public:
 195     virtual void append(const LogEvent& v) {


< prev index next >