2 Copyright (C) 2001-2012 Paul Davis
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
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 int ardour_main (int argc, char *argv[]);
22 #if (defined(COMPILER_MSVC) && defined(NDEBUG) && !defined(RDC_BUILD))
27 bool IsAConsolePort (HANDLE handle)
31 return (GetConsoleMode(handle, &mode) != 0);
34 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
37 char szPathToProgram[768];
40 // Essential!! Make sure that any files used by Ardour
41 // will be created or opened in BINARY mode!
44 GetModuleFileName (NULL, (LPSTR)szPathToProgram, (DWORD)sizeof(szPathToProgram));
45 argv[0] = new char[(strlen(szPathToProgram) + 1)];
49 LPWSTR lpwCmdLine = 0;
50 int count, nArgs, argc = 1;
51 size_t argStringLen = strlen(lpCmdLine);
53 // Copy the program path to argv[0]
54 strcpy (argv[0], szPathToProgram);
56 // Parse the user's command line and add any parameters to argv
59 lpwCmdLine = new wchar_t[argStringLen+1];
60 mbstowcs (lpwCmdLine, lpCmdLine, argStringLen+1);
62 LPWSTR* pwArgv = CommandLineToArgvW ((LPCWSTR)lpwCmdLine, &nArgs);
66 for (count = 1; count <= nArgs; count++)
68 int argChars = wcslen (pwArgv[count-1]);
69 if (0 != (argv[count] = new char[(argChars+1)]))
72 wcstombs (argv[count], pwArgv[count-1], argChars+1);
74 // Append a NULL to the argv vector
85 // If the user started Mixbus from a console, re-attach
86 // to the console so we can see 'printf()' output etc.
87 FILE *pStdOut = 0, *pStdErr = 0;
88 BOOL bConsole = AttachConsole(ATTACH_PARENT_PROCESS);
89 HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
91 if ((bConsole) && (IsAConsolePort(hStdOut)))
93 pStdOut = freopen( "CONOUT$", "w", stdout );
94 pStdErr = freopen( "CONOUT$", "w", stderr );
97 ret = ardour_main (argc, argv);
106 // Detach and free the console from our application
107 INPUT_RECORD input_record;
109 input_record.EventType = KEY_EVENT;
110 input_record.Event.KeyEvent.bKeyDown = TRUE;
111 input_record.Event.KeyEvent.dwControlKeyState = 0;
112 input_record.Event.KeyEvent.uChar.UnicodeChar = VK_RETURN;
113 input_record.Event.KeyEvent.wRepeatCount = 1;
114 input_record.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
115 input_record.Event.KeyEvent.wVirtualScanCode = MapVirtualKey( VK_RETURN, 0 );
118 WriteConsoleInput( GetStdHandle( STD_INPUT_HANDLE ), &input_record, 1, &written );
123 for (count = 0; count < argc; count++)
124 delete[] argv[count];