CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    wcscpy_s problem

    What am I doing wrong here..?

    Code:
    // Needed for wcscpy_s
    #include <string.h> 
    
    // Later in the code
     wcscpy_s (some_destination, L"Hello World");
    The above code gives me error C2660: 'wcscpy_s': function does not take 2 arguments

    But it does take 2 arguments according to MSDN

    [Edit...] Apologies - it's wcscpy that takes 2 arguments, not wcscpy_s. Does anyone have an example of how to use wcscpy_s? Everything I've tried so far has produced a runtime exception

    [Edit2...] Groan... apparently there's a template version of wcscpy_s which DOES take 2 arguments (and that one seems to work for me...)
    Last edited by John E; July 2nd, 2021 at 03:06 AM.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: wcscpy_s problem

    So after all that... here's the problem I was trying to solve in the first place !!

    Code:
        LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    IDS_APP_TITLE retrieves a value from my project's RC file (in other words, it's defined at compile time). I was trying to figure out if there's some way to use the app's name at run time - i.e. if I change the exe's name, can I retrieve its runtime name somehow?
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  3. #3
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: wcscpy_s problem

    Yeah, the syntax of wcscpy_s (and others!) changes as to whether you're compiling as c or c++ - and if for C++, can the template version determine the size of the destination.

    If the size of the destination can be determined for C++, then the only difference between wcscpy and wcscpy_s with 2 params is the return type.

    Note that the size of the destination with C+ can't be determined in all circumstances - in which case wcscpy_s will still require 3 params.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: wcscpy_s problem

    To retrieve the exe's name inside a windows program (it's easy for main() as it's argv[0]), use GetCommandLine()

    See https://docs.microsoft.com/en-us/win...etcommandlinea
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: wcscpy_s problem

    Quote Originally Posted by John E View Post
    ...
    I was trying to figure out if there's some way to use the app's name at run time - i.e. if I change the exe's name, can I retrieve its runtime name somehow?
    Did you try the GetModuleFileName function?
    Victor Nijegorodov

  6. #6
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: wcscpy_s problem

    That's great, guys - thanks !!
    "A problem well stated is a problem half solved.” - Charles F. Kettering

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured