Thread: strcpy_s exception in VC 2005

  1. #1
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470

    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.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.

  3. #3
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    thanx 4 the input. So how to fix the code?
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

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

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, 07:33 AM
  2. exception handling
    By coletek in forum C++ Programming
    Replies: 2
    Last Post: 01-12-2009, 05: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, 02:36 PM
  5. Problem with the exception class in MINGW
    By indigo0086 in forum C++ Programming
    Replies: 6
    Last Post: 01-20-2007, 01:12 PM