I need to finish this by tomorrow, PLZ HELP!!!

Could someone convert this code into one where you can input the file directory from the console?

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
#define WIN32_LEAN_AND_MEAN // prevent windows.h from including "kitchen sink"
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{LPCSTR Application = "C:\\Program Files\\Windows Media Player\\wmplayer.exe";
// Media file extension must be provided
// Paths are quoted
char Command[1024] = "\"C:\\Program Files\\Windows Media Player\\wmplayer.exe\""
//Under this is what needs input.
" \"C:\\Documents and Settings\\Jason\\My Documents\\Jason\\My Music\\LOOKING LIKE THIS.wav\"";
STARTUPINFOA si = {0}; // zero struct
si.cb = sizeof(si);
PROCESS_INFORMATION pi = {0}; // zero struct
if( CreateProcessA(
Application,
Command,
NULL,
NULL,
FALSE,
NULL,
0,
NULL,
&si,
&pi) )
{cout << "Song playing\n";
WaitForSingleObject(pi.hProcess, INFINITE);
DWORD exitCode = 0;
GetExitCodeProcess(pi.hProcess, &exitCode);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);}else
{DWORD errCode = GetLastError();
cerr << "song playing failed\nError code: " << errCode << "\n";}}


This code works but te directory can only be changed from the code not the console.
Last edited on
pretty compact code... However, change the main header to:

int main( int argc, char **argv )

argc will be the number of paramters from the command line including the application name, i.e. it is at least 1.

argv is an array of c-strings holding the arguments, e.g. argv[0] is the application name.

calling the application like:
myapp 123 "hello world"

will result in argc being 3

argv[0] is "myapp\0"
argv[1] is "123\0"
argv[2] is "hello world\0"

where '\0' is the c-string terminator.
Last edited on
The new program is:
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
#define WIN32_LEAN_AND_MEAN // prevent windows.h from including "kitchen sink"
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;
int main( int argc, char **argv )
{
argv[0]="\C:\\Documents and Settings\\Jason\\My Documents\\Jason\\My Music\\LOOKING LIKE THIS.wav\\0";
argv[1];

LPCSTR Application = "C:\\Program Files\\Windows Media Player\\wmplayer.exe";
// Media file extension must be provided
// Paths are quoted
char Command[1024] = "\"C:\\Program Files\\Windows Media Player\\wmplayer.exe\""argv[0];
//Above this is what needs input.
STARTUPINFOA si = {0}; // zero struct
si.cb = sizeof(si);
PROCESS_INFORMATION pi = {0}; // zero struct
if( CreateProcessA(
Application,
Command,
NULL,
NULL,
FALSE,
NULL,
0,
NULL,
&si,
&pi) )
{cout << "Song playing\n";
WaitForSingleObject(pi.hProcess, INFINITE);
DWORD exitCode = 0;
GetExitCodeProcess(pi.hProcess, &exitCode);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);}else
{DWORD errCode = GetLastError();
cerr << "song playing failed\nError code: " << errCode << "\n";}}


This doesn't work either.
Last edited on
Topic archived. No new replies allowed.