2 * Copyright (C) 2014 John Emmas <john@creativepost.co.uk>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 int ardour_main (int argc, char *argv[]);
21 #if (defined(COMPILER_MSVC) && defined(NDEBUG) && !defined(RDC_BUILD))
26 bool IsAConsolePort (HANDLE handle)
30 return (GetConsoleMode(handle, &mode) != 0);
33 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
36 char szPathToProgram[768];
39 // Essential!! Make sure that any files used by Ardour
40 // will be created or opened in BINARY mode!
43 GetModuleFileName (NULL, (LPSTR)szPathToProgram, (DWORD)sizeof(szPathToProgram));
44 argv[0] = new char[(strlen(szPathToProgram) + 1)];
48 LPWSTR lpwCmdLine = 0;
49 int count, nArgs, argc = 1;
50 size_t argStringLen = strlen(lpCmdLine);
52 // Copy the program path to argv[0]
53 strcpy (argv[0], szPathToProgram);
55 // Parse the user's command line and add any parameters to argv
58 lpwCmdLine = new wchar_t[argStringLen+1];
59 mbstowcs (lpwCmdLine, lpCmdLine, argStringLen+1);
61 LPWSTR* pwArgv = CommandLineToArgvW ((LPCWSTR)lpwCmdLine, &nArgs);
65 for (count = 1; count <= nArgs; count++)
67 int argChars = wcslen (pwArgv[count-1]);
68 if (0 != (argv[count] = new char[(argChars+1)]))
71 wcstombs (argv[count], pwArgv[count-1], argChars+1);
73 // Append a NULL to the argv vector
84 // If the user started Mixbus from a console, re-attach
85 // to the console so we can see 'printf()' output etc.
86 FILE *pStdOut = 0, *pStdErr = 0;
87 BOOL bConsole = AttachConsole(ATTACH_PARENT_PROCESS);
88 HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
90 if ((bConsole) && (IsAConsolePort(hStdOut)))
92 pStdOut = freopen( "CONOUT$", "w", stdout );
93 pStdErr = freopen( "CONOUT$", "w", stderr );
96 ret = ardour_main (argc, argv);
105 // Detach and free the console from our application
106 INPUT_RECORD input_record;
108 input_record.EventType = KEY_EVENT;
109 input_record.Event.KeyEvent.bKeyDown = TRUE;
110 input_record.Event.KeyEvent.dwControlKeyState = 0;
111 input_record.Event.KeyEvent.uChar.UnicodeChar = VK_RETURN;
112 input_record.Event.KeyEvent.wRepeatCount = 1;
113 input_record.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
114 input_record.Event.KeyEvent.wVirtualScanCode = MapVirtualKey( VK_RETURN, 0 );
117 WriteConsoleInput( GetStdHandle( STD_INPUT_HANDLE ), &input_record, 1, &written );
122 for (count = 0; count < argc; count++)
123 delete[] argv[count];