Browse Source

use GetModuleFileName()

David Rose 21 years ago
parent
commit
f96ddb1420
1 changed files with 14 additions and 1 deletions
  1. 14 1
      dtool/src/dtoolutil/executionEnvironment.cxx

+ 14 - 1
dtool/src/dtoolutil/executionEnvironment.cxx

@@ -25,6 +25,9 @@
 // Windows requires this for getcwd().
 // Windows requires this for getcwd().
 #include <direct.h>
 #include <direct.h>
 #define getcwd _getcwd
 #define getcwd _getcwd
+
+// And this is for GetModuleFileName().
+#include <windows.h>
 #endif
 #endif
 
 
 
 
@@ -330,7 +333,17 @@ void ExecutionEnvironment::
 read_args() {
 read_args() {
 #if defined(HAVE_GLOBAL_ARGV)
 #if defined(HAVE_GLOBAL_ARGV)
   int argc = GLOBAL_ARGC;
   int argc = GLOBAL_ARGC;
-  if (argc > 0) {
+
+#ifdef WIN32_VC
+  static const DWORD buffer_size = 1024;
+  char buffer[buffer_size];
+  DWORD size = GetModuleFileName(NULL, buffer, buffer_size);
+  if (size != 0) {
+    _binary_name = Filename::from_os_specific(string(buffer, size));
+  }
+#endif  // WIN32_VC
+
+  if (_binary_name.empty() && argc > 0) {
     _binary_name = GLOBAL_ARGV[0];
     _binary_name = GLOBAL_ARGV[0];
   }
   }