I'm working on a C++ DDL, however I get the following issue in some places:
C4996 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
I did try #define _CRT_SECURE_NO_WARNINGS
, but the issue remains.
This is the code:
sprintf(szDebugString, "%s: 0x%x (%s%s%i)", ptrName, (DWORD)funcPtr, interfaceName, interfaceVersion.c_str(), i);
This function or variable may be unsafe. Consider using safe-version instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
_CRT_SECURE_NO_WARNINGS means you don't want the compiler to suggest the secure versions of the library functions, e.g. scanf_s when you use scanf .
Detail steps as below: Right Click 'Project Properties->C/C+±>Preprocessor' Add '_CRT_SECURE_NO_WARNINGS' to preprocessor Definitions and click ok. In addition, if you have any other issue, please create a new feedback to us!
You have to define _CRT_SECURE_NO_WARNINGS
before #include <Windows.h>
.
Alternatively, use the safe version:
sprintf_s(szDebugString, sizeof(szDebugString), "%s: 0x%x (%s%s%i)",
ptrName, (DWORD)funcPtr, interfaceName, interfaceVersion.c_str(), i);
put this define into stdafx.h
.
E.g.
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
To turn off the warning for an entire project in the Visual Studio IDE:
1- Open the Property Pages dialog for your project.
2- Select the Configuration Properties > C/C++ > Advanced page.
3- Edit the Disable Specific Warnings property to add 4996. Choose OK to apply your changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With