"path" is the string "path". You want the variable path.
"path" is the string "path". You want the variable path.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
right..."path" is a tring and i want variable...actually in the code i dont have " ".That was a mistake while pasting it here on the board.However i think i know why this is happening now
During another debugging i found out that the char array path is filled with the following data :
"C:\\Movies\\IceAge.aviÌÌÌÌ 04;ÌÌÌÌÌÌÌÌ ;ÌÌÌÌÌÌ"
I am betting that these ÌÌÌÌÌÌÌÌ&# 204;ÌÌÌÌÌÌÌ 4;ÌÌ charachters whatever they r are messing up the entire thing.Although i dont know where they r coming from since the size of path has been defined as 22 i.e char path[22];
Is there no way i can simply pass a string as the 3rd parameter to the ShellExecuteA...I am at a loss to know as to why the alien ÌÌÌÌÌÌÌÌ&# 204;ÌÌÌÌ charachters are being appended to the char path array ?? Would rather simply work with strings
Last edited by roalme00; 09-09-2007 at 04:20 PM.
Well you need two things
1. Make sure your path array has sufficient size. 22 chars just isn't enough for most file paths
2. Make sure that when you copy the path that you also add a \0 at the end.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
*cough*HINSTANCE hRet = ShellExecuteA(
HWND_DESKTOP, //Parent window
"open", //Operation to perform
"path", //Path to program
NULL, //Parameters
NULL, //Default directory
SW_SHOW); //How to open
Besides... why don't you just use std::string instead of those ugly C-style strings ?
True...I dont myself like the ugly C style strings.But passing a std::string as a 3rd Parameter to the ShellExecuteA function results in a compiler error which says
"'ShellExecuteA' : cannot convert parameter 3 from 'std::string' to 'LPCSTR"
I am only able to get rid of this by making sure that the parameter that is being passed is a char array.
Half knowledge is dangerous than no knowledge...I think this is what is happening in my case here
you would want to use the .c_str() member of the string class to pass to that function. And then you could use the string interface you are familar with.
using .c_str() member of the string class got rid of the compiler error and i could run the code successfully
Also putting an '\0' at the end of char array path solved it.( i now so remember my teacher saying not to forget this a few years ago)
Thanks to all (Desolation, prog-bman,Salem,CornedBee,CrazyNorman and dwks) and sorry for bothering to such an extent (especially since the error was so noob).I have learnt my lesson
Thannks again
Last edited by roalme00; 09-09-2007 at 06:25 PM.
You are welcome!