|
I think you'll get buffer overruns that way.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
That's assuming you cast away the const s so it even compiles.
Steve
|
|
|
|
|
Good point indeed.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
toxcct wrote: const char* exeroot = path.c_str();
strcat(exeroot, "/");
strcat(exeroot, "CharacterAnimation.exe");
Bad advice. The buffer returned from c_str is const and thus can't be modified. And it's wrong to cast away the const as it's const for a reason: the buffer used by a std::string need not be contiguous memory. If this is the case calling c_str makes a temporary buffer and copies the non-contiguous memory blocks into one contiguous memory block for you. It is not required to copy the blocks back. Also your code is in serious danger of causing a buffer overrun (if you made it compile by casting away the const ): how do you know how big the buffer is?
Anyway the correct way is simpler, safe, works, is portable and requires no casts:
std::string path = dtCore::GetDeltaRootPath();
path += "/CharacterAnimation.exe";
system(path.c_str());
Steve
|
|
|
|
|
You are sending strcat() the wrong param type i think.
std::string path = dtCore::GetDeltaRootPath();
const char* exeroot = path.c_str();
char* StrToCat = path.c_str();
strcat(StrToCat,"/");
strcat(StrToCat,","CharacterAnimation.exe");
etc..
|
|
|
|
|
Buffer overrun along the horizon.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
absolutely, but i only meant to identify the problem a lil more clearly ![Frown | :(](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_frown.gif)
|
|
|
|
|
|
T.RATHA KRISHNAN wrote: I followed the same method. But the following code:
Nope. You got it wrongly.
T.RATHA KRISHNAN wrote: std::string path = dtCore::GetDeltaRootPath();
const char* exeroot = path.c_str();
strcat(path,"/");
strcat(path,"CharacterAnimation.exe");
result = system(path);
return true;
change to
std::string path = dtCore::GetDeltaRootPath();
path +="/";
path +="CharacterAnimation.exe";
result = system(path.c_str());
return true;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks a lot. I resolved the errors. But now my problem is: the variable path contains "Program Files". Compiler takes only Program leaving the space and after that. So the console displays an error: "C:\Program" is not recognized as an internal or external command,operable program or batch file. What to do?
|
|
|
|
|
F*CK, you don't listen to me.
if you were using ShellExecute, that wouldn't have happened.
use quotes ( " " ) around your string (within the string I mean), or use ShellExecute
|
|
|
|
|
I don't understand this:(with in the string). My string definition is:
path += "/";
path += "CharacterAnimation.exe";
result = system(path.c_str());
Where should I put double quotes?
|
|
|
|
|
god, do you understand this : use ShellExecute ?????
::ShellExecuteA(NULL, "open", path.c_str(), NULL, NULL, SW_NORMAL);
|
|
|
|
|
Regards,
Sandip.
|
|
|
|
|
Thanks. It's working now.
|
|
|
|
|
T.RATHA KRISHNAN wrote: Thanks. It's working now
at last... glad to hear that
|
|
|
|
|
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You dont like ShellExecute(), do you??
within string means something like this
path += "\""; in the beginning and end also.
BTW if you have followed toxcct and used ShellExecute() there would not have be so much waste of your time.
Regards,
Sandip.
|
|
|
|
|
Relax dude
don't get so much angry
Regards,
Sandip.
|
|
|
|
|
Whenever you have a path containing spaces, you need to (double)quote the it, i.e.
path = "\"" + path + "\"";
system( path.c_str());
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Tuesday, July 1, 2008 9:06 AM
|
|
|
|
|
system() is deprecated.
moreover, i think we really should avoid to mention it anymore with this *ù"'#
ShellExecute() for ever ! lol
|
|
|
|
|
toxcct wrote: system() is deprecated.
And portable.
BTW strcat without enough storage is more than deprecate
(just kidding)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
absolutely, but that guy is coding like a pig...
|
|
|
|
|
Well, we, as teachers, are commited to do the miracle and transform him into a top-skilled-developer (brass band needed here).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|