strcpy_s exception in VC 2005

This is a discussion on strcpy_s exception in VC 2005 within the Windows Programming forums, part of the Platform Specific Boards category; Hi I tried to compile this code in VC 2005 and it requests typed LPCWSTR variables for strcpy_s function. But ...

  1. #1
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    362

    strcpy_s exception in VC 2005

    Hi
    I tried to compile this code in VC 2005 and it requests typed LPCWSTR variables for strcpy_s function. But if i don't convert thoes strings into char* pointers, again the compiler gives wrong argument type errors. So i've casted variable cmd into char*, but now the program gives an exception. How to fix the code?

    Code:
    LPWSTR mediacmd;
    LPCWSTR cmd;
    strcpy_s((char*)cmd, strlen((char*)cmd), "play %");
    wsprintf(mediacmd,cmd, "D:\\MUSIC COPY\\JOSHUA_TREE+\\Lord of the Rigns soundtrack(partial)\\1.10 Fangorn.mp3");
    And why can't i just pass c-style char arrays into strcpy() in VC2005, like i've used to do in older VC versions?
    Code:
    char cmd[50];
    strcpy_s(cmd, strlen(cmd), "play %");
    Thanx for any help
    Last edited by geek@02; 08-07-2009 at 06:55 AM.
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    > again the compiler gives wrong argument type errors.
    Probably because it's in UNICODE mode, and LPWSTR is a pointer to a wide string.
    Simply casting your way out of trouble just silences the compiler, but doesn't fix the underlying problem.
    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.

  3. #3
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    362
    thanx 4 the input. So how to fix the code?
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Exception handling in a large project
    By EVOEx in forum C++ Programming
    Replies: 7
    Last Post: 01-25-2009, 06:33 AM
  2. exception handling
    By coletek in forum C++ Programming
    Replies: 2
    Last Post: 01-12-2009, 04:28 PM
  3. Task list in VC 2005
    By VirtualAce in forum Tech Board
    Replies: 0
    Last Post: 05-13-2008, 08:59 PM
  4. Signal and exception handling
    By nts in forum C++ Programming
    Replies: 23
    Last Post: 11-15-2007, 01:36 PM
  5. Problem with the exception class in MINGW
    By indigo0086 in forum C++ Programming
    Replies: 6
    Last Post: 01-20-2007, 12:12 PM

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