what is wrong with this simple function?

int _tmain(int argc, _TCHAR* argv[])
{


char cFilename[] = "c:\\Program Files\Diablo II\Diablo II.exe";
const char cAction[5] = {"open"};


ShellExecute(NULL,cAction[] ,cFilename[], NULL, NULL, 1);
// If ShellExecute returns an error code, let the user know.
//bool iReturn = (true || false);

return 0;

says expression expected in the shell exucute fuction on the [] of my variables. won't let me use the variables without the [] so screwed both ways
Try replacing

const char cAction[5] = {"open"}; //here you have an array of c-strings

with

const char cAction[] = "open"; //just one c-string

and remove the [] from the arguments and see how it goes.

EDIT: Actually, what error(s) does it give you when you remove the []? I compiled the above without the brackets and I don't receive any errors. The cAction initialization works as is.
Last edited on
I don't think you need to include [] when passing arrays to functions. You only need the array name by itself.
int _tmain(int argc, _TCHAR* argv[])
{

char cDir[] = "c:\\Program Files\\Diablo II" ;
char cFilename[] = "Diablo II.exe";
const char cAction[] = {"open"};
char* a = cFilename;


ShellExecute(NULL,_T("cAction[]") ,_T("cFilename[]"), _T("cDir[]"), NULL, 1);
// If ShellExecute returns an error code, let the user know.
//bool iReturn = (true || false);

return 0;


I changed it to this but It still not working. If i don't include the variables in "" i get like some type of error. I think it this microsoft visual studio being overly picky, maybe i need to start with softer compiler or somethin. If i don't include the [] in the argument it act like c[] != c ..... if there included it says "expression expected on the closing bracket ]. The above code gives no errors but don't open the file.
What is the compiler error (copy and paste it) you receive if you do this?

ShellExecute(NULL,cAction ,cFilename, cDir, NULL, 1);

Your current code doesn't open the file because you're telling windows to execute the "cAction[]" action on the file "cFilename[]" located in the directory "cDir[]".
#include "stdafx.h"

#include <Windows.h>

// shellexecute(hndwin,cAction,filename,cparams,directory,showwindow)

int _tmain(int argc, _TCHAR* argv[])
{

char cDir[] = "c:\\Program Files\Diablo II" ;
char cFilename[] = "Diablo II.exe";
const char cAction[] = "open";



ShellExecute(NULL,cAction[] ,cFilename[], cDir[], NULL, 1);
// If ShellExecute returns an error code, let the user know.
//bool iReturn = (true || false);

return 0;


//MessageBox ("Cannot open file. File may have been moved or deleted.", "Error!", MB_OK | MB_ICONEXCLAMATION) ;

}



returns these errors

13): warning C4129: 'D' : unrecognized character escape sequence
1>c:\users\mark\documents\visual studio 2010\projects\dick\dick\dick.cpp(19): error C2059: syntax error : ']'
1>

also says expected expression for all 3 ] in the function arguments..........

do i need different include files or somethin like that? dnt know why i can't get this right so easy on autoit
Last edited on
Your ShellExecute function call still has parameters with the [] brackets. Remove those from that line. You shouldn't receive any compiler errors.
when i remove them is says "not compatible with parameters of LPCWSTR"
Alright, it seems you're compiling with Unicode.

Try this:

ShellExecute(NULL, _T(cAction), _T(cFilename), _T(cDir), NULL, 1);
that don't work either says LcAction is undefined... if i add char LcAction = cAction my computer explodes.
LcAction? It seems like you've made a typo. Try copying and pasting the line I showed you above.
Think the issue might be that i was under a win 32 console project.... i switched to normal win 32.

the errors went away with the shell execute itself now i have other issues

ya thats cute now it says shellexecute is undefined

OMG!!
Last edited on
Try making an empty project with this code:

1
2
3
4
5
6
7
8
9
10
11
12
#include <windows.h>

int main()
{
    char cDir[] = "c:\\Program Files\\Diablo II" ;
    char cFilename[] = "Diablo II.exe"; 
    const char cAction[] = "open";

    ShellExecute(NULL, cAction, cFilename, cDir, NULL, 1);

    return 0;
}
Last edited on
ok that actually works with no errors. But when i compile it nothing happens the file doesn't launch after i click on it that is, black window pops up for a sec an nothin happens
Last edited on
Did you try running with administrator privileges? Right-click your .exe and run as administrator. Or, if you're going to run it from Visual Studio, then right-click Visual Studio and run as administrator to start it.
i give up i'm goin to bed. Sad part is i just wanted to make a simple launching program to compile so i could use my decompiler an study the assembly code...... which came first the chicken or the egg?
Topic archived. No new replies allowed.