Fix build break with WindowsOS CRT
authorJan Kotas <jkotas@microsoft.com>
Sat, 17 Oct 2015 01:54:12 +0000 (18:54 -0700)
committerJan Kotas <jkotas@microsoft.com>
Sat, 17 Oct 2015 01:54:12 +0000 (18:54 -0700)
_get_wpgmptr is not available in WindowsOS CRT. Replace it with GetModuleFileName.

[tfs-changeset: 1538931]

Commit migrated from https://github.com/dotnet/coreclr/commit/5992ffac963acc0fbd9e3fd9976d9842a74abbe7

src/coreclr/src/coreclr/hosts/coreconsole/coreconsole.cpp

index 1d9f3b7..7b93dd8 100644 (file)
@@ -595,24 +595,25 @@ void showHelp() {
                );
 }
 
+static wchar_t programPath[MAX_LONGPATH];
+
 int __cdecl wmain(const int argc, const wchar_t* argv[])
 {
-    wchar_t* wpgmptr;
-    if (_get_wpgmptr(&wpgmptr) != 0) {
+    DWORD dwModuleFileName = GetModuleFileName(NULL, programPath, MAX_LONGPATH);
+    if (dwModuleFileName == 0 || dwModuleFileName >= MAX_LONGPATH) {
         ::wprintf(W("Failed to get the path to the current executable"));
         return -1;
     }
-    auto programPath = _wcsdup(wpgmptr);
     auto extension = wcsrchr(programPath, '.');
     if (extension == NULL || (wcscmp(extension, L".exe") != 0)) {
         ::wprintf(W("This executable needs to have 'exe' extension"));
         return -1;
     }
 
-       // Change the extension from ".exe" to ".dll"
-       extension[1] = 'd';
-       extension[2] = 'l';
-       extension[3] = 'l';
+    // Change the extension from ".exe" to ".dll"
+    extension[1] = 'd';
+    extension[2] = 'l';
+    extension[3] = 'l';
 
     // Parse the options from the command line
     bool verbose = false;