Code fix

hello, can someone fix this for me? I can't seem to find where the problem 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";}}
Can we start with WHAT the problem is? Thank you for using code tags but how did you manage to destroy your formatting?
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
#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";
    }
}

I formatted your code into something more readable. What are you trying to do on line 16?
Last edited on
I'm trying to be able to input the file directory there. That is where it is failing and I don't know why.
What exactly are you trying to do with the arbitrary argv[0] on line 16?
input a file directory
Ex: \C:\\Program Files\\Windows Media Player\\wmplayer.exe\
Then why do you have the arbitrary argv[0]? Remove it and it will do what you are wanting.

Also line 11 does nothing.
Last edited on
I am trying to insert it in the console
The trouble with that is argv[0] is generally the current directory and name of the process that is running. You want argv[1] for the first argument. Also, why aren't you just using std::string? You an concatenate the argument to your literal with the "std::string.append()" member function.
I don't use that because i don't know what that is or does
You don't use what? std::string? Are you serious? Would you like one of us to Google that for you, or would you rather just take a dip into our beloved forums dated tutorial?
could you just explain it or use lmgtfy.com? Im a noob.
Did you seriously ask us to give you a lmgtfy link?

All you had to do was go on the reference on this site or search "std::string" at the top :P
http://www.cplusplus.com/reference/string/
maybe...
I still don't know what i'm doing...
ok... sheesh!
Topic archived. No new replies allowed.