Menu ▾ ▴

[f90d0d]: / Source / Tools / DevCppPortable / main.cpp  Maximize  Restore  History

Download this file

57 lines (50 with data), 1.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <windows.h>
#include <Shlwapi.h>
#include <string>
using std::wstring;
// Tried to use wmain, but GCC/MinGW doesn't define it because it's MS specific
// So, I'm sticking to the Windows API for now
int main() {
// Fill an argv array and argc similar to the standard ones
int ArgumentCount = 0;
wchar_t** ArgumentInput = CommandLineToArgvW(GetCommandLineW(),&ArgumentCount);
// Then build our selection to pass to devcpp.exe
wstring ArgumentsToDev = L"-c .\\config ";
for(int i = 1;i < ArgumentCount;i++) {
ArgumentsToDev += '\"';
ArgumentsToDev += ArgumentInput[i];
ArgumentsToDev += '\"';
if(i != ArgumentCount - 1) {
ArgumentsToDev += ' ';
}
}
// Free the strings pointed to by argv
LocalFree(ArgumentInput);
// Run "devcpp.exe" from the current directory and NOT from the directory
// from which files are dragged onto us for example
wchar_t CurrentDirectory[32768]; // NTFS max length
GetModuleFileNameW(NULL,CurrentDirectory,32768); // get full file path including filename to devcppPortable.exe
PathRemoveFileSpecW(CurrentDirectory); // extract filename
// Attempt to execute
int Result = (INT_PTR)ShellExecuteW(
NULL, // no parent window
L"open", // open the file
L"devcpp.exe", // the file to open
ArgumentsToDev.c_str(), // extra parameters to pass
CurrentDirectory, // use the current directory
SW_SHOWNORMAL // activate and display window
);
if(Result <= 32) {
switch(Result) {
case ERROR_FILE_NOT_FOUND: {
MessageBoxW(NULL,L"devcpp.exe",L"File not found",MB_OK);
break;
}
default: {
MessageBoxW(NULL,L"An unspecified error has occured!",L"Error",MB_OK);
break;
}
}
}
return 0;
}