Qai Posted January 29, 2014 Share Posted January 29, 2014 The following is example native C++/Windows code how to parse the command line in Windows. It is meant to be used with the Standard version of LW if you are re-compiling the exe and would like this feature. The code is from my own project not connected with LW, so just treat the references to DX/GL selection as an example of how to use the method. Having a command line parser is very useful for adding options to show a debugging window or write to a log, etc. Literally anything you want to pass via the command line to your main program. This makes it easier to create several shortcuts to your exe that invokes the application in different ways. #include <Windows.h> #include <stdio.h> bool parselpCmdLine(bool &DXSelected, bool &GLSelected, bool &engineDebugActive, int &debugWindow_WIDTH, int &debugWindow_HEIGHT, bool &engineLogActive) { LPWSTR *szArgList; int nArgs; LPWSTR argCmdLineDX = L"-dx"; LPWSTR argCmdLineGL = L"-gl"; LPWSTR argCmdLineDebug = L"-debug"; LPWSTR argCmdLineLog = L"-log"; szArgList = CommandLineToArgvW(GetCommandLineW(), &nArgs); // program requires at least one argument for either DirectX (-dx) or OpenGL (-gl) if (nArgs > 1) { // parse for DirectX (-dx) or OpenGL (-gl) // required: yes // number of arguments: 1 for (int i = 1; i < nArgs; i++) { if (lstrcmpi(szArgList[i], argCmdLineDX) == 0) { if (DXSelected == false) { DXSelected = true; } } else if (lstrcmpi(szArgList[i], argCmdLineGL) == 0) { if (GLSelected == false) { GLSelected = true; } } } if ((DXSelected == false) && (GLSelected == false)) { MessageBox(NULL, L"No selection for graphics type DirectX (-dx) or OpenGL (-gl) indicated.", L"Command Line Error", MB_OK | MB_ICONERROR); LocalFree(szArgList); return false; } if ((DXSelected == true) && (GLSelected == true)) { MessageBox(NULL, L"You cannot select both DirectX (-dx) and OpenGL (-gl).", L"Command Line Error", MB_OK | MB_ICONERROR); LocalFree(szArgList); return false; } // parse for debugging information // argument syntax: -debug window_WIDTH window_HEIGHT // argument types: window_WIDTH = integer, window_HEIGHT = integer // required: optional // number of arguments: 3 for (int i = 1; i < nArgs; i++) { if (lstrcmpi(szArgList[i], argCmdLineDebug) == 0) { engineDebugActive = true; swscanf_s(szArgList[i + 1], (L"%d"), &debugWindow_WIDTH); swscanf_s(szArgList[i + 2], (L"%d"), &debugWindow_HEIGHT); break; } } // parse for logging information // required: optional // number of arguments: 1 for (int i = 1; i < nArgs; i++) { if (lstrcmpi(szArgList[i], argCmdLineLog) == 0) { engineLogActive = true; break; } } } else { MessageBox(NULL, L"No selection for graphics type DirectX (-dx) or OpenGL (-gl) indicated.", L"Command Line Error", MB_OK | MB_ICONERROR); LocalFree(szArgList); return false; } LocalFree(szArgList); return true; } Quote Link to comment Share on other sites More sharing options...
bandrewk Posted January 31, 2014 Share Posted January 31, 2014 There is a command line parser inside Leadwerks. Accessible from both, LUA and C++: http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/system/systemgetproperty-r538 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.