1 // MIDLWrapper.cpp : Just calls the built-in midl.exe with the given arguments.
3 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
11 int wmain(int argc, wchar_t* argv[], wchar_t* envp[])
14 fwprintf(stderr, L"######### im in ur IDE, compiling ur c0des ########\n");
18 for (int i = 0; envp[i]; ++i)
19 if (!wcsncmp(envp[i], L"PATH=", 5)) {
24 if (pathIndex == -1) {
25 fwprintf(stderr, L"Couldn't find PATH environment variable!\n");
29 wchar_t* vcbin = wcsstr(envp[pathIndex], L"Tools\\vcbin");
31 fwprintf(stderr, L"Couldn't find Tools\\vcbin in PATH!\n");
35 wchar_t saved = *vcbin;
38 wchar_t* afterLeadingSemiColon = wcsrchr(envp[pathIndex], ';');
39 if (!afterLeadingSemiColon)
40 afterLeadingSemiColon = envp[pathIndex] + 5; // +5 for the length of "PATH="
42 afterLeadingSemiColon++;
46 size_t pathLength = wcslen(envp[pathIndex]);
48 wchar_t* trailingSemiColon = wcschr(vcbin, ';');
49 if (!trailingSemiColon)
50 trailingSemiColon = envp[pathIndex] + pathLength;
52 int vcbinLength = trailingSemiColon - afterLeadingSemiColon;
54 size_t newPathLength = pathLength - vcbinLength;
56 wchar_t* newPath = new wchar_t[newPathLength + 1];
58 // Copy everything before the vcbin path...
60 wchar_t* s = envp[pathIndex];
61 while (s < afterLeadingSemiColon)
64 // Copy everything after the vcbin path...
65 s = trailingSemiColon;
68 envp[pathIndex] = newPath;
71 fwprintf(stderr, L"New path: %s\n", envp[pathIndex]);
74 wchar_t** newArgv = new wchar_t*[argc + 1];
75 for (int i = 0; i < argc; ++i) {
76 size_t length = wcslen(argv[i]);
77 newArgv[i] = new wchar_t[length + 3];
79 wcscpy_s(newArgv[i] + 1, length + 2, argv[i]);
80 *(newArgv[i] + 1 + length) = '\"';
81 *(newArgv[i] + 2 + length) = 0;
85 return _wspawnvpe(_P_WAIT, L"midl", newArgv, envp);