jruby-launcher 0.9.9-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/jvmlauncher.cpp ADDED
@@ -0,0 +1,421 @@
1
+ /*
2
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
+ *
4
+ * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
5
+ *
6
+ * The contents of this file are subject to the terms of either the GNU
7
+ * General Public License Version 2 only ("GPL") or the Common
8
+ * Development and Distribution License("CDDL") (collectively, the
9
+ * "License"). You may not use this file except in compliance with the
10
+ * License. You can obtain a copy of the License at
11
+ * http://www.netbeans.org/cddl-gplv2.html
12
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
+ * specific language governing permissions and limitations under the
14
+ * License. When distributing the software, include this License Header
15
+ * Notice in each file and include the License file at
16
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
+ * particular file as subject to the "Classpath" exception as provided
18
+ * by Sun in the GPL Version 2 section of the License file that
19
+ * accompanied this code. If applicable, add the following below the
20
+ * License Header, with the fields enclosed by brackets [] replaced by
21
+ * your own identifying information:
22
+ * "Portions Copyrighted [year] [name of copyright owner]"
23
+ *
24
+ * Contributor(s):
25
+ *
26
+ * The Original Software is NetBeans. The Initial Developer of the Original
27
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28
+ * Microsystems, Inc. All Rights Reserved.
29
+ *
30
+ * If you wish your version of this file to be governed by only the CDDL
31
+ * or only the GPL Version 2, indicate your decision by adding
32
+ * "[Contributor] elects to include this software in this distribution
33
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
+ * single choice of license, a recipient has the option to distribute
35
+ * your version of this file under either the CDDL, the GPL Version 2 or
36
+ * to extend the choice of license to its licensees as provided above.
37
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
38
+ * Version 2 license, then the option applies only if the new code is
39
+ * made subject to such option by the copyright holder.
40
+ *
41
+ * Author: Tomas Holy
42
+ */
43
+
44
+ #include "jvmlauncher.h"
45
+ #include <cassert>
46
+
47
+ using namespace std;
48
+
49
+ const char *JvmLauncher::JDK_KEY = "Software\\JavaSoft\\Java Development Kit";
50
+ const char *JvmLauncher::JRE_KEY = "Software\\JavaSoft\\Java Runtime Environment";
51
+ const char *JvmLauncher::CUR_VERSION_NAME = "CurrentVersion";
52
+ const char *JvmLauncher::JAVA_HOME_NAME = "JavaHome";
53
+ const char *JvmLauncher::JAVA_BIN_DIR = "\\bin";
54
+ const char *JvmLauncher::JAVA_EXE_FILE = "\\bin\\java.exe";
55
+ const char *JvmLauncher::JAVAW_EXE_FILE = "\\bin\\javaw.exe";
56
+ const char *JvmLauncher::JAVA_CLIENT_DLL_FILE = "\\bin\\client\\jvm.dll";
57
+ const char *JvmLauncher::JAVA_SERVER_DLL_FILE = "\\bin\\server\\jvm.dll";
58
+ const char *JvmLauncher::JAVA_JRE_PREFIX = "\\jre";
59
+ const char *JvmLauncher::JNI_CREATEVM_FUNC = "JNI_CreateJavaVM";
60
+
61
+
62
+ JvmLauncher::JvmLauncher()
63
+ : suppressConsole(false) {
64
+ }
65
+
66
+ JvmLauncher::JvmLauncher(const JvmLauncher& orig) {
67
+ }
68
+
69
+ JvmLauncher::~JvmLauncher() {
70
+ }
71
+
72
+ bool JvmLauncher::checkJava(const char *path, const char *prefix) {
73
+ assert(path);
74
+ assert(prefix);
75
+ logMsg("checkJava(%s)", path);
76
+ javaPath = path;
77
+ if (*javaPath.rbegin() == '\\') {
78
+ javaPath.erase(javaPath.length() - 1, 1);
79
+ }
80
+ javaExePath = javaPath + prefix + JAVA_EXE_FILE;
81
+ javawExePath = javaPath + prefix + JAVAW_EXE_FILE;
82
+ javaClientDllPath = javaPath + prefix + JAVA_CLIENT_DLL_FILE;
83
+ javaServerDllPath = javaPath + prefix + JAVA_SERVER_DLL_FILE;
84
+ if (!fileExists(javaClientDllPath.c_str())) {
85
+ javaClientDllPath = "";
86
+ }
87
+ if (!fileExists(javaServerDllPath.c_str())) {
88
+ javaServerDllPath = "";
89
+ }
90
+ javaBinPath = javaPath + prefix + JAVA_BIN_DIR;
91
+ if (fileExists(javaExePath.c_str()) || !javaClientDllPath.empty() || !javaServerDllPath.empty()) {
92
+ if (!fileExists(javawExePath.c_str())) {
93
+ logMsg("javaw.exe not exists, forcing java.exe");
94
+ javawExePath = javaExePath;
95
+ }
96
+ return true;
97
+ }
98
+
99
+ javaPath.clear();
100
+ javaBinPath.clear();
101
+ javaExePath.clear();
102
+ javawExePath.clear();
103
+ javaClientDllPath.clear();
104
+ javaServerDllPath.clear();
105
+ return false;
106
+ }
107
+
108
+ bool JvmLauncher::initialize(const char *javaPathOrMinVersion) {
109
+ logMsg("JvmLauncher::initialize()\n\tjavaPathOrMinVersion: %s", javaPathOrMinVersion);
110
+ assert(javaPathOrMinVersion);
111
+ if (isVersionString(javaPathOrMinVersion)) {
112
+ return findJava(javaPathOrMinVersion);
113
+ } else {
114
+ return (checkJava(javaPathOrMinVersion, JAVA_JRE_PREFIX) || checkJava(javaPathOrMinVersion, ""));
115
+ }
116
+ }
117
+
118
+ bool JvmLauncher::getJavaPath(string &path) {
119
+ logMsg("JvmLauncher::getJavaPath()");
120
+ path = javaPath;
121
+ return !javaPath.empty();
122
+ }
123
+
124
+ bool JvmLauncher::start(const char *mainClassName, list<string> args, list<string> options, bool &separateProcess, DWORD *retCode) {
125
+ assert(mainClassName);
126
+ logMsg("JvmLauncher::start()\n\tmainClassName: %s\n\tseparateProcess: %s",
127
+ mainClassName, separateProcess ? "true" : "false");
128
+ logMsg(" args:");
129
+ for (list<string>::iterator it = args.begin(); it != args.end(); ++it) {
130
+ logMsg("\t%s", it->c_str());
131
+ }
132
+ logMsg(" options:");
133
+ for (list<string>::iterator it = options.begin(); it != options.end(); ++it) {
134
+ logMsg("\t%s", it->c_str());
135
+ }
136
+
137
+ if (javaExePath.empty() && javaClientDllPath.empty() && javaServerDllPath.empty()) {
138
+ // try to find out any java installed (check the registry)
139
+ if (!initialize("")) {
140
+ return false;
141
+ }
142
+ }
143
+
144
+ if (!separateProcess) {
145
+ // both client/server found, check option which should be used
146
+ if (!javaClientDllPath.empty() && !javaServerDllPath.empty()) {
147
+ // By default, load client VM. Load server VM only if explicitly asked.
148
+ javaDllPath = findServerOption(options) ? javaServerDllPath: javaClientDllPath;
149
+ } else {
150
+ javaDllPath = javaClientDllPath.empty() ? javaServerDllPath : javaClientDllPath;
151
+ }
152
+
153
+ // it is necessary to absolutize dll path because current dir has to be
154
+ // temporarily changed for dll loading
155
+ char absoluteJavaDllPath[MAX_PATH] = "";
156
+ strncpy(absoluteJavaDllPath, javaDllPath.c_str(), MAX_PATH);
157
+ normalizePath(absoluteJavaDllPath, MAX_PATH);
158
+ javaDllPath = absoluteJavaDllPath;
159
+
160
+ logMsg("Java DLL path: %s", javaDllPath.c_str());
161
+ if (!canLoadJavaDll()) {
162
+ logMsg("Falling back to running Java in a separate process; DLL cannot be loaded (64-bit DLL?).");
163
+ separateProcess = true;
164
+ }
165
+ }
166
+
167
+ return separateProcess ? startOutProcJvm(mainClassName, args, options, retCode)
168
+ : startInProcJvm(mainClassName, args, options);
169
+ }
170
+
171
+ bool JvmLauncher::findServerOption(list<string> &options) {
172
+ for (list<string>::iterator it = options.begin(); it != options.end(); ++it) {
173
+ if (*it == "-server") {
174
+ return true;
175
+ }
176
+ }
177
+ return false;
178
+ }
179
+
180
+ bool JvmLauncher::canLoadJavaDll() {
181
+ // be prepared for stupid placement of msvcr71.dll in java installation
182
+ // (in java 1.6/1.7 jvm.dll is dynamically linked to msvcr71.dll which si placed
183
+ // in bin directory)
184
+ PrepareDllPath prepare(javaBinPath.c_str());
185
+ HMODULE hDll = LoadLibrary(javaDllPath.c_str());
186
+ if (hDll) {
187
+ FreeLibrary(hDll);
188
+ return true;
189
+ }
190
+ logErr(true, false, "Cannot load %s.", javaDllPath.c_str());
191
+ return false;
192
+ }
193
+
194
+ bool JvmLauncher::isVersionString(const char *str) {
195
+ char *end = 0;
196
+ strtod(str, &end);
197
+ return *end == '\0';
198
+ }
199
+
200
+ bool JvmLauncher::startInProcJvm(const char *mainClassName, std::list<std::string> args, std::list<std::string> options) {
201
+
202
+ class Jvm {
203
+ public:
204
+
205
+ Jvm(JvmLauncher *jvmLauncher)
206
+ : hDll(0)
207
+ , jvm(0)
208
+ , env(0)
209
+ , jvmOptions(0)
210
+ , jvmLauncher(jvmLauncher)
211
+ {
212
+ }
213
+
214
+ ~Jvm() {
215
+ if (env && env->ExceptionOccurred()) {
216
+ env->ExceptionDescribe();
217
+ }
218
+
219
+ if (jvm) {
220
+ logMsg("Destroying JVM");
221
+ jvm->DestroyJavaVM();
222
+ }
223
+
224
+ if (jvmOptions) {
225
+ delete[] jvmOptions;
226
+ }
227
+
228
+ if (hDll) {
229
+ FreeLibrary(hDll);
230
+ }
231
+ }
232
+
233
+ bool init(list<string> options) {
234
+ logMsg("JvmLauncher::Jvm::init()");
235
+ logMsg("LoadLibrary(\"%s\")", jvmLauncher->javaDllPath.c_str());
236
+ {
237
+ PrepareDllPath prepare(jvmLauncher->javaBinPath.c_str());
238
+ hDll = LoadLibrary(jvmLauncher->javaDllPath.c_str());
239
+ if (!hDll) {
240
+ logErr(true, true, "Cannot load %s.", jvmLauncher->javaDllPath.c_str());
241
+ return false;
242
+ }
243
+ }
244
+
245
+ CreateJavaVM createJavaVM = (CreateJavaVM) GetProcAddress(hDll, JNI_CREATEVM_FUNC);
246
+ if (!createJavaVM) {
247
+ logErr(true, true, "GetProcAddress for %s failed.", JNI_CREATEVM_FUNC);
248
+ return false;
249
+ }
250
+
251
+ // Explicity remove -server and -client options, they are not
252
+ // needed, since we invoke JVM in-process and already know
253
+ // which DLL to use.
254
+ options.remove("-server");
255
+ options.remove("-client");
256
+
257
+ logMsg("JVM options:");
258
+ jvmOptions = new JavaVMOption[options.size()];
259
+ int i = 0;
260
+ for (list<string>::iterator it = options.begin(); it != options.end(); ++it, ++i) {
261
+ string &option = *it;
262
+ logMsg("\t%s", option.c_str());
263
+ jvmOptions[i].optionString = (char *) option.c_str();
264
+ jvmOptions[i].extraInfo = 0;
265
+ }
266
+
267
+ JavaVMInitArgs jvmArgs;
268
+ jvmArgs.options = jvmOptions;
269
+ jvmArgs.nOptions = options.size();
270
+ jvmArgs.version = JNI_VERSION_1_4;
271
+ jvmArgs.ignoreUnrecognized = JNI_FALSE;
272
+
273
+ logMsg("Creating JVM...");
274
+ if (createJavaVM(&jvm, &env, &jvmArgs) < 0) {
275
+ logErr(false, true, "JVM creation failed");
276
+ return false;
277
+ }
278
+ logMsg("JVM created.");
279
+ return true;
280
+ }
281
+ typedef jint (CALLBACK *CreateJavaVM)(JavaVM **jvm, JNIEnv **env, void *args);
282
+
283
+ HMODULE hDll;
284
+ JavaVM *jvm;
285
+ JNIEnv *env;
286
+ JavaVMOption *jvmOptions;
287
+ JvmLauncher *jvmLauncher;
288
+ };
289
+
290
+ Jvm jvm(this);
291
+ if (!jvm.init(options)) {
292
+ return false;
293
+ }
294
+
295
+ jclass mainClass = jvm.env->FindClass(mainClassName);
296
+ if (!mainClass) {
297
+ logErr(false, true, "Cannot find class %s.", mainClassName);
298
+ return false;
299
+ }
300
+
301
+ jmethodID mainMethod = jvm.env->GetStaticMethodID(mainClass, "main", "([Ljava/lang/String;)V");
302
+ if (!mainMethod) {
303
+ logErr(false, true, "Cannot get main method.");
304
+ return false;
305
+ }
306
+
307
+ jclass jclassString = jvm.env->FindClass("java/lang/String");
308
+ if (!jclassString) {
309
+ logErr(false, true, "Cannot find java/lang/String class");
310
+ return false;
311
+ }
312
+
313
+ jstring jstringArg = jvm.env->NewStringUTF("");
314
+ if (!jstringArg) {
315
+ logErr(false, true, "NewStringUTF() failed");
316
+ return false;
317
+ }
318
+
319
+ jobjectArray mainArgs = jvm.env->NewObjectArray(args.size(), jclassString, jstringArg);
320
+ if (!mainArgs) {
321
+ logErr(false, true, "NewObjectArray() failed");
322
+ return false;
323
+ }
324
+ int i = 0;
325
+ for (list<string>::iterator it = args.begin(); it != args.end(); ++it, ++i) {
326
+ string &arg = *it;
327
+ jstring jstringArg = jvm.env->NewStringUTF(arg.c_str());
328
+ if (!jstringArg) {
329
+ logErr(false, true, "NewStringUTF() failed");
330
+ return false;
331
+ }
332
+ jvm.env->SetObjectArrayElement(mainArgs, i, jstringArg);
333
+ }
334
+
335
+ jvm.env->CallStaticVoidMethod(mainClass, mainMethod, mainArgs);
336
+ return true;
337
+ }
338
+
339
+
340
+ bool JvmLauncher::startOutProcJvm(const char *mainClassName, std::list<std::string> args, std::list<std::string> options, DWORD *retCode) {
341
+ string cmdLine = '\"' + (suppressConsole ? javawExePath : javaExePath) + '\"';
342
+ cmdLine.reserve(32*1024);
343
+ for (list<string>::iterator it = options.begin(); it != options.end(); ++it) {
344
+ cmdLine += " \"";
345
+ cmdLine += *it;
346
+ cmdLine += "\"";
347
+ }
348
+
349
+ // mainClass and args
350
+ cmdLine += ' ';
351
+ cmdLine += mainClassName;
352
+ for (list<string>::iterator it = args.begin(); it != args.end(); ++it) {
353
+ if (javaClientDllPath.empty() && *it == "-client") {
354
+ logMsg("Removing -client option, client java dll not found.");
355
+ // remove client parameter, no client java found
356
+ continue;
357
+ }
358
+ cmdLine += " \"";
359
+ cmdLine += *it;
360
+ cmdLine += "\"";
361
+ }
362
+
363
+ logMsg("Command line:\n%s", cmdLine.c_str());
364
+ if (cmdLine.size() >= 32*1024) {
365
+ logErr(false, true, "Command line is too long. Length: %u. Maximum length: %u.", cmdLine.c_str(), 32*1024);
366
+ return false;
367
+ }
368
+
369
+ STARTUPINFO si = {0};
370
+ si.cb = sizeof (STARTUPINFO);
371
+ PROCESS_INFORMATION pi = {0};
372
+
373
+ char cmdLineStr[32*1024] = "";
374
+ strcpy(cmdLineStr, cmdLine.c_str());
375
+ if (!CreateProcess(NULL, cmdLineStr, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, &si, &pi)) {
376
+ logErr(true, true, "Failed to create process");
377
+ return false;
378
+ }
379
+
380
+ disableFolderVirtualization(pi.hProcess);
381
+ ResumeThread(pi.hThread);
382
+ WaitForSingleObject(pi.hProcess, INFINITE);
383
+ if (retCode) {
384
+ GetExitCodeProcess(pi.hProcess, retCode);
385
+ }
386
+ CloseHandle(pi.hProcess);
387
+ CloseHandle(pi.hThread);
388
+ return true;
389
+ }
390
+
391
+ bool JvmLauncher::findJava(const char *minJavaVersion) {
392
+ if (findJava(JDK_KEY, JAVA_JRE_PREFIX, minJavaVersion)) {
393
+ return true;
394
+ }
395
+ if (findJava(JRE_KEY, "", minJavaVersion)) {
396
+ return true;
397
+ }
398
+ javaPath = "";
399
+ javaExePath = "";
400
+ javaClientDllPath = "";
401
+ javaServerDllPath = "";
402
+ javaBinPath = "";
403
+ return false;
404
+ }
405
+
406
+ bool JvmLauncher::findJava(const char *javaKey, const char *prefix, const char *minJavaVersion) {
407
+ logMsg("JvmLauncher::findJava()\n\tjavaKey: %s\n\tprefix: %s\n\tminJavaVersion: %s", javaKey, prefix, minJavaVersion);
408
+ string value;
409
+ if (getStringFromRegistry(HKEY_LOCAL_MACHINE, javaKey, CUR_VERSION_NAME, value)) {
410
+ if (value >= minJavaVersion) {
411
+ string path;
412
+ if (getStringFromRegistry(HKEY_LOCAL_MACHINE, (string(javaKey) + "\\" + value).c_str(), JAVA_HOME_NAME, path)) {
413
+ if (*path.rbegin() == '\\') {
414
+ path.erase(path.length() - 1, 1);
415
+ }
416
+ return checkJava(path.c_str(), prefix);
417
+ }
418
+ }
419
+ }
420
+ return false;
421
+ }
data/jvmlauncher.h ADDED
@@ -0,0 +1,141 @@
1
+ /*
2
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
+ *
4
+ * Copyright 1997-2008, 2010 Sun Microsystems, Inc. All rights reserved.
5
+ *
6
+ * The contents of this file are subject to the terms of either the GNU
7
+ * General Public License Version 2 only ("GPL") or the Common
8
+ * Development and Distribution License("CDDL") (collectively, the
9
+ * "License"). You may not use this file except in compliance with the
10
+ * License. You can obtain a copy of the License at
11
+ * http://www.netbeans.org/cddl-gplv2.html
12
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
+ * specific language governing permissions and limitations under the
14
+ * License. When distributing the software, include this License Header
15
+ * Notice in each file and include the License file at
16
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
+ * particular file as subject to the "Classpath" exception as provided
18
+ * by Sun in the GPL Version 2 section of the License file that
19
+ * accompanied this code. If applicable, add the following below the
20
+ * License Header, with the fields enclosed by brackets [] replaced by
21
+ * your own identifying information:
22
+ * "Portions Copyrighted [year] [name of copyright owner]"
23
+ *
24
+ * Contributor(s):
25
+ *
26
+ * The Original Software is NetBeans. The Initial Developer of the Original
27
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28
+ * Microsystems, Inc. All Rights Reserved.
29
+ *
30
+ * If you wish your version of this file to be governed by only the CDDL
31
+ * or only the GPL Version 2, indicate your decision by adding
32
+ * "[Contributor] elects to include this software in this distribution
33
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
+ * single choice of license, a recipient has the option to distribute
35
+ * your version of this file under either the CDDL, the GPL Version 2 or
36
+ * to extend the choice of license to its licensees as provided above.
37
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
38
+ * Version 2 license, then the option applies only if the new code is
39
+ * made subject to such option by the copyright holder.
40
+ *
41
+ * Author: Tomas Holy
42
+ */
43
+
44
+ #ifndef _JVMLAUNCHER_H
45
+ #define _JVMLAUNCHER_H
46
+
47
+ #include <windows.h>
48
+ #include <string>
49
+ #include <list>
50
+ #include "jni.h"
51
+ #include "utilsfuncs.h"
52
+
53
+ class JvmLauncher {
54
+ static const int MAX_ARGS_LEN = 32*1024;
55
+
56
+ static const char *JDK_KEY;
57
+ static const char *JRE_KEY;
58
+ static const char *CUR_VERSION_NAME;
59
+ static const char *JAVA_HOME_NAME;
60
+ static const char *JAVA_BIN_DIR;
61
+ static const char *JAVA_EXE_FILE;
62
+ static const char *JAVAW_EXE_FILE;
63
+ static const char *JAVA_CLIENT_DLL_FILE;
64
+ static const char *JAVA_SERVER_DLL_FILE;
65
+ static const char *JAVA_JRE_PREFIX;
66
+ static const char *JNI_CREATEVM_FUNC;
67
+
68
+ public:
69
+ JvmLauncher();
70
+ virtual ~JvmLauncher();
71
+
72
+ bool initialize(const char *javaPathOrMinVersion);
73
+ bool getJavaPath(std::string &path);
74
+ bool start(const char *mainClassName, std::list<std::string> args, std::list<std::string> options, bool &separateProcess, DWORD *retCode);
75
+
76
+ void setSuppressConsole(bool val) {
77
+ suppressConsole = val;
78
+ }
79
+
80
+ private:
81
+ JvmLauncher(const JvmLauncher& orig);
82
+
83
+ bool checkJava(const char *javaPath, const char *prefix);
84
+ bool findJava(const char *minJavaVersion);
85
+ bool findJava(const char *javaKey, const char *prefix, const char *minJavaVersion);
86
+ bool startOutProcJvm(const char *mainClassName, std::list<std::string> args, std::list<std::string> options, DWORD *retCode);
87
+ bool startInProcJvm(const char *mainClassName, std::list<std::string> args, std::list<std::string> options);
88
+ bool isVersionString(const char *str);
89
+ bool canLoadJavaDll();
90
+ bool findServerOption(std::list<std::string> &options);
91
+
92
+ private:
93
+ bool suppressConsole;
94
+ std::string javaExePath;
95
+ std::string javawExePath;
96
+ std::string javaDllPath;
97
+ std::string javaClientDllPath;
98
+ std::string javaServerDllPath;
99
+ std::string javaPath;
100
+ std::string javaBinPath;
101
+
102
+ class PrepareDllPath {
103
+ public:
104
+ PrepareDllPath(const char *dllDirectory)
105
+ : setDllDirectory(0) {
106
+ logMsg("PrepareDllPath: %s", dllDirectory);
107
+ oldCurDir[0] = '\0';
108
+
109
+ // SetDllDirectory is present since XP SP1, so we have to load it dynamically
110
+ HINSTANCE hKernel32 = GetModuleHandle("kernel32");
111
+ if (!hKernel32) {
112
+ logErr(true, false, "Cannot load kernel32.");
113
+ return;
114
+ }
115
+
116
+ LPFNSDD setDllDirectory = (LPFNSDD)GetProcAddress(hKernel32, "SetDllDirectoryA");
117
+ if (setDllDirectory) {
118
+ setDllDirectory(dllDirectory);
119
+ } else {
120
+ logErr(true, false, "Cannot find SetDllDirectoryA");
121
+ }
122
+ GetCurrentDirectory(MAX_PATH, oldCurDir);
123
+ SetCurrentDirectory(dllDirectory);
124
+ }
125
+ ~PrepareDllPath() {
126
+ if (setDllDirectory) {
127
+ setDllDirectory(NULL);
128
+ }
129
+ if (oldCurDir[0]) {
130
+ SetCurrentDirectory(oldCurDir);
131
+ }
132
+ }
133
+ private:
134
+ typedef BOOL (WINAPI *LPFNSDD)(LPCTSTR lpPathname);
135
+ LPFNSDD setDllDirectory;
136
+ char oldCurDir[MAX_PATH];
137
+ };
138
+ };
139
+
140
+ #endif /* _JVMLAUNCHER_H */
141
+