0

I'm trying to create a combo box in Win32 by following this msdn tutorial.

When I implement step 2 and try to compile, I get the following error:

error: 'wcscpy_s' was not declared in this scope
wcscpy_s(A, sizeof(A) / sizeof(TCHAR),  (TCHAR*)Planets[k]);

I've included the following header files, hoping to solve this issue:

#include <string.h>
#include <wchar.h>
#include <windows.h>
#include <CommCtrl.h>
#include <math.h>
#include <objbase.h>

Can someone help me understand why I'm getting this error? Thanks in advance.

4
  • 1
    if you use sizeof(A) / sizeof(TCHAR), you should probably use _tcscpy_s.
    – wimh
    Aug 4, 2015 at 18:39
  • I cannot reproduce your error: it compiles perfectly unders MSVC2013 with a Win32 project. Even if I undef the default VS symbols (UNICODE, WIN32, ...) I don't get the same error as you (but a complaint error C2664: 'errno_t wcscpy_s(wchar_t *,rsize_t,const wchar_t *)' ). Can you tell which compiler, version, and options you've set ?
    – Christophe
    Aug 4, 2015 at 19:34
  • I'm using mingw. CFLAGS := -g -Wall -std=c++11 -Wl,--stack,20971520 -DLIBARCHIVE_STATIC ...... SETUPFLAGS := -g -std=c++1 ..... LDFLAGS := -s -lwinmm -lgdi32 -lcomctl32 -Wl,--subsystem,windows -Wl,--stack,20971520 -static -static-libgcc -static-libstdc++
    – Astartes
    Aug 5, 2015 at 12:12
  • Is there another function I could call to get the same effect?
    – Astartes
    Aug 5, 2015 at 17:30

1 Answer 1

0

From cpp-reference

As with all bounds-checked functions, wcscpy_s is only guaranteed to be available if STDC_LIB_EXT1 is defined by the implementation and if the user defines STDC_WANT_LIB_EXT1 to the integer constant 1 before including wchar.h.

3
  • I've added #define STDC_WANT_LIB_EXT1 1 and #define STDC_LIB_EXT1 2 before including wchar.h. I'm getting the same error.
    – Astartes
    Aug 4, 2015 at 18:48
  • 1
    It says that the implementation must define STDC_LIB_EXT1, not the user (you).
    – jensa
    Aug 4, 2015 at 18:56
  • Based on what you see in the tutorial, is there an alternative I can use?
    – Astartes
    Aug 4, 2015 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.