Question

I have a project that I'm building with Visual Studio 2005. The sources are also used in another project that gets built using Visual Studio 6.

This results in potential errors since the new _s-functions introduced by the Security Enhancements in the CRT are not present in VS6.

To ensure that my sources are also playing nice with VS6 while not having to keep a separate installation of VS6, I'd like to compile them with VS2005 but disable the new secure functions (introduced by the Security Enhancements). Is that possible?

Was it helpful?

Solution 3

The answer given by Sergius inspired me to run a home made way:

  • implement the wrappers for the secure functions in a file secure.c
  • checking for availability of secure functions can be done with
    #if (_MSC_VER >= 1400)
  • take the list of the Security Enhanced Versions of CRT Functions into a file
  • search each pattern in my sources using these few lines on a cygwin console:
    for i in $(cat secure_functions.txt)
    do
    grep -rn --exclude "secure.c" -w $i path/to/sources
    done
  • This points me to the places where there are occurrences of the new functions.

Backup: if someone wants to do that too, here's the list of secure functions:

_access_s
_waccess_s
_malloca
asctime_s
_wasctime_s
bsearch_s
_cgets_s
_cgetws_s
_chsize_s
clearerr_s
_controlfp_s
_cprintf_s
_cprintf_s_l
_cwprintf_s
_cwprintf_s_l
_cscanf_s
_cscanf_s_l
_cwscanf_s
_cwscanf_s_l
_ctime_s
_ctime32_s
_ctime64_s
_wctime_s
_wctime32_s
_wctime64_s
_ecvt_s
_fcvt_s
fopen_s
_wfopen_s
fprintf_s
_fprintf_s_l
fwprintf_s
_fwprintf_s_l
freopen_s
_wfreopen_s
fscanf_s
_fscanf_s_l
fwscanf_s
_fwscanf_s_l
_ftime_s
_ftime32_s
_ftime64_s
_gcvt_s
getenv_s
_wgetenv_s
gets_s
_getws_s
_gmtime32_s
_gmtime64_s
_itoa_s
_i64toa_s
_ui64toa_s
_itow_s
_i64tow_s
_ui64tow_s
_lfind_s
localtime_s
_localtime32_s
_localtime64_s
_lsearch_s
_ltoa_s
_ltow_s
_makepath_s
_wmakepath_s
_mbccpy_s
_mbccpy_s_l
_mbsnbcat_s
_mbsnbcat_s_l
_mbsnbcpy_s
_mbsnbcpy_s_l
mbsrtowcs_s
mbstowcs_s
_mbstowcs_s_l
memcpy_s
wmemcpy_s
memmove_s
wmemmove_s
_mktemp_s
_wmktemp_s
printf_s
_printf_s_l
wprintf_s
_wprintf_s_l
_putenv_s
_wputenv_s
qsort_s
rand_s
scanf_s
_scanf_s_l
wscanf_s
_wscanf_s_l
_searchenv_s
_wsearchenv_s
_snprintf_s
_snprintf_s_l
_snwprintf_s
_snwprintf_s_l
_snscanf_s
_snscanf_s_l
_snwscanf_s
_snwscanf_s_l
_sopen_s
_wsopen_s
_splitpath_s
_wsplitpath_s
sprintf_s
_sprintf_s_l
swprintf_s
_swprintf_s_l
sscanf_s
_sscanf_s_l
swscanf_s
_swscanf_s_l
strcat_s
wcscat_s
_mbscat_s
strcpy_s
wcscpy_s
_mbscpy_s
_strdate_s
_wstrdate_s
strerror_s
_strerror_s
_wcserror_s
__wcserror_s
_strlwr_s
_strlwr_s_l
_mbslwr_s
_mbslwr_s_l
_wcslwr_s
_wcslwr_s_l
strncat_s
_strncat_s_l
wcsncat_s
_wcsncat_s_l
_mbsncat_s
_mbsncat_s_l
strncpy_s
_strncpy_s_l
wcsncpy_s
_wcsncpy_s_l
_mbsncpy_s
_mbsncpy_s_l
_strtime_s
_wstrtime_s
strtok_s
_strtok_s_l
wcstok_s
_wcstok_s_l
_mbstok_s
_mbstok_s_l
_strupr_s
_strupr_s_l
_mbsupr_s
_mbsupr_s_l
_wcsupr_s
_wcsupr_s_l
tmpfile_s
tmpnam_s
_wtmpnam_s
_ultoa_s
_ultow_s
_umask_s
_vcprintf_s
_vcprintf_s_l
_vcwprintf_s
_vcwprintf_s_l
vfprintf_s
_vfprintf_s_l
vfwprintf_s
_vfwprintf_s_l
vprintf_s
_vprintf_s_l
vwprintf_s
_vwprintf_s_l
vsnprintf_s
_vsnprintf_s
_vsnprintf_s_l
_vsnwprintf_s
_vsnwprintf_s_l
vsprintf_s
_vsprintf_s_l
vswprintf_s
_vswprintf_s_l
wcrtomb_s
wcsrtombs_s
wcstombs_s
_wcstombs_s_l
wctomb_s
_wctomb_s_l

OTHER TIPS

You can disable warning about insecure functions by defining _CRT_SECURE_NO_WARNINGS. Also you can add a conditional compiled wrapper for _s function: on VS2005 and higher use _s functions and on anything other use wrapped _s functions which just call normal functions.

The files (framework, libraries, assemblies) used by VS .Net and VS6 are completely different. Although its possible to use some of the libraries from VS6 using COM wrapper, you won't get full VS6 compatibility in VS .Net.

If it's important, one time effort of porting the code will be beneficial.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top