Click here to Skip to main content
       

C / C++ / MFC

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionShellExecute ProblemmemberLFK_Michael4 Feb '13 - 22:56 
Hello Everybody,
 
I hope i have choosen the right forum for my Question.
 
I have a little application which starts another programm with a specific path (a txt-file).
Yes, easy and simple, it works fine with ShellExecute, but i have a problem with some Executables(I have to test a few programs). One Executable opens correct but it don´t opens the given path. I don´t understake whats wrong, because if I drag and drop the txt-file manualy on the executable it works.
So my Question is, are ShellExecute and Drag&Drop two different things to open a programm? Does anybody know a way to fix my problem ?
 
Thanks in advance,
Michael
AnswerRe: ShellExecute Problem PinmvpRichard MacCutchan5 Feb '13 - 0:00 
You need to show the section of the code that tries to start the program and explain exactly what part of it is not working.
GeneralRe: ShellExecute Problem PinmemberLFK_Michael5 Feb '13 - 0:16 
void StartEXE (String^ path)
{
TCHAR prog[] = TEXT("C:\\...\\...."); // Programpath

string p ;
MarshalString(path, p);
std::string str= p;
TCHAR *param=new TCHAR[str.size()+1];
param[str.size()]=0;
 
const TCHAR open[] = TEXT("runas")
ShellExecute( NULL, open, prog, param, NULL, SW_SHOWNORMAL );
}
 
void MarshalString ( String ^ s, string& os )
        {
        using namespace Runtime::InteropServices;
        const char* chars =
        (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
        os = chars;
        Marshal::FreeHGlobal(IntPtr((void*)chars));
        }
 
 
This is the code i use. I call StartEXE with a String like C:\\test.txt , the programmpath is fix in the code.
The Programm i want to open opens but it don´t open the path.
This happens only by one Programm, if i want to open another programm this code works.
Any Ideas?
GeneralRe: ShellExecute Problem PinmvpRichard MacCutchan5 Feb '13 - 0:26 
Without seeing the actual parameters and the code of the executing program it's impossible to guess what may be happening. It would probably be a good idea to add some debug code to the called program so you can see exactly what parameters it is trying to deal with. What is the "runas" parameter supposed to do?
SuggestionRe: ShellExecute Problem PinmemberDavidCrow5 Feb '13 - 2:17 
You might also want to consider asking for help here.

"One man's wage rise is another man's price increase." - Harold Wilson

"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous


AnswerRe: ShellExecute Problem PinmemberMarius Bancila5 Feb '13 - 1:05 
That should only work if the application you want to start supports command line parameters, or if it the default application for starting the document type you're trying to open.
GeneralRe: ShellExecute Problem PinmemberLFK_Michael5 Feb '13 - 3:15 
Thats what i wanted to hear Smile | :)
The "runas" is to start a exe with admin rights.
 
Is it right that open a Programm with ShellExecute is different to Drag&Drop way ? Because if i drag and drop a textfile on the Program i want to open it works. btw the program is a finished one done not by myself.

Is there a way to drag&drop the textfile to the program via code?
GeneralRe: ShellExecute Problem PinmemberMarius Bancila5 Feb '13 - 9:28 
Starting a program by command line and drag&drop are different things. An application can implement any (or neither). You cannot simulate drag&drop from code if that application is not handling the drop.
GeneralRe: ShellExecute Problem PinmemberLFK_Michael5 Feb '13 - 12:03 
Thank you for the answer.
The Application i want to open supports drag&drop.
How can i implement the drag&drop function in my program?
Do you have any Ideas ?
AnswerRe: ShellExecute Problem PinmemberAlbert Holguin5 Feb '13 - 14:35 
Not exactly sure what may be causing your problem... but the unix/linux calls (also supported by Windows) usually work pretty well for me.
 
Try them out (required header is in documentation)...
spawn[^]
exec[^]

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid