-
July 2nd, 2021, 02:45 AM
#1
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
-
July 2nd, 2021, 03:24 AM
#2
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
-
July 2nd, 2021, 03:27 AM
#3
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)
-
July 2nd, 2021, 03:34 AM
#4
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)
-
July 2nd, 2021, 03:47 AM
#5
Re: wcscpy_s problem
Originally Posted by John E
...
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
-
July 2nd, 2021, 04:47 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|