Opening a video file through c++

This is a discussion on Opening a video file through c++ within the C++ Programming forums, part of the General Programming Boards category; "path" is the string "path". You want the variable path....

  1. #16
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    "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

  2. #17
    Registered User
    Join Date
    Jan 2006
    Posts
    34
    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ÌÌÌÌ&#2 04;ÌÌÌÌÌÌÌ&#204 ;ÌÌÌÌÌÌ"
    I am betting that these ÌÌÌÌÌÌÌÌ&# 204;ÌÌÌÌÌÌÌ&#20 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.

  3. #18
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #19
    Registered User
    Join Date
    May 2006
    Posts
    903
    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
    *cough*

  5. #20
    Registered User
    Join Date
    May 2006
    Posts
    903
    Besides... why don't you just use std::string instead of those ugly C-style strings ?

  6. #21
    Registered User
    Join Date
    Jan 2006
    Posts
    34
    Quote Originally Posted by Desolation View Post
    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

  7. #22
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    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.

  8. #23
    Registered User
    Join Date
    Jan 2006
    Posts
    34
    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.

  9. #24
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    You are welcome!

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21