wcsncpy的警告怎么解决?
warning C4996: 'wcsncpy' was declared deprecated
  c:\program files\microsoft visual studio 8\vc\include\string.h(270) : see declaration of 'wcsncpy'
  Message: 'This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'

----解决方案--------------------
Message: 'This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'

这句说的很清楚了,用新版本换掉旧版本即可,不想用新的就加_CRT_SECURE_NO_DEPRECATE,这个应该是个宏定义
其实这问题怎么说呢,一些标准的 C++ 的坚定支持者指责微软破坏了 C++ 标准,
而微软认为这些函数存在缓冲区溢出的隐患,所以加了一个字符/字节数限制,形成了一些列的 _s 后缀的函数。
个人觉得微软这么做还是有道理的

 


在VS工程中,添加c/c++工程中外部头文件及库的基本步骤:

    1、添加工程的头文件目录:工程---属性---配置属性---c/c++---常规---附加包含目录:加上头文件存放目录。

    2、添加文件引用的lib静态库路径:工程---属性---配置属性---链接器---常规---附加库目录:加上lib文件存放目录。
         然后添加工程引用的lib文件名:工程---属性---配置属性---链接器---输入---附加依赖项:加上lib文件名。

    3、添加工程引用的dll动态库:把引用的dll放到工程的可执行文件所在的目录下。

 

VC6中,工程中添加XXX.h和XXX.lib的操作是:
1,菜单"Project"->"Add To Project"->"Files"添加文件
2,菜单"tool"->"Option"->"Directory"中,添加文件路径


 

1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlosapice.h(879) : warning C4996: 'wcsncpy' was declared deprecated
1>        c:\program files\windows ce tools\wce600\smdk2416_sdk.msi\include\armv4i\stdlib.h(177) : see declaration of 'wcsncpy'
1>        Message: 'This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlosapice.h(893) : warning C4996: '_vsnwprintf' was declared deprecated
1>        c:\program files\windows ce tools\wce600\smdk2416_sdk.msi\include\armv4i\stdlib.h(382) : see declaration of '_vsnwprintf'
1>        Message: 'This function or variable may be unsafe. Consider using _vsnwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlosapice.h(910) : warning C4996: '_vsnprintf' was declared deprecated
1>        c:\program files\windows ce tools\wce600\smdk2416_sdk.msi\include\armv4i\stdlib.h(377) : see declaration of '_vsnprintf'
1>        Message: 'This function or variable may be unsafe. Consider using _vsnprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlosapice.h(1075) : warning C4996: 'wcsncpy' was declared deprecated
1>        c:\program files\windows ce tools\wce600\smdk2416_sdk.msi\include\armv4i\stdlib.h(177) : see declaration of 'wcsncpy'
1>        Message: 'This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlosapice.h(1123) : warning C4996: 'wcsncpy' was declared deprecated
1>        c:\program files\windows ce tools\wce600\smdk2416_sdk.msi\include\armv4i\stdlib.h(177) : see declaration of 'wcsncpy'
1>        Message: 'This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlchecked.h(157) : warning C4996: '_strlwr' was declared deprecated
1>        C:\Program Files\Windows CE Tools\wce600\SMDK2416_SDK.msi\include\ARMV4I\stdlib.h(240) : see declaration of '_strlwr'
1>        Message: 'This function or variable may be unsafe. Consider using _strlwr_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlchecked.h(167) : warning C4996: '_wcslwr' was declared deprecated
1>        C:\Program Files\Windows CE Tools\wce600\SMDK2416_SDK.msi\include\ARMV4I\stdlib.h(189) : see declaration of '_wcslwr'
1>        Message: 'This function or variable may be unsafe. Consider using _wcslwr_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlchecked.h(192) : warning C4996: '_wcslwr' was declared deprecated
1>        C:\Program Files\Windows CE Tools\wce600\SMDK2416_SDK.msi\include\ARMV4I\stdlib.h(189) : see declaration of '_wcslwr'
1>        Message: 'This function or variable may be unsafe. Consider using _wcslwr_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlchecked.h(209) : warning C4996: '_wcsupr' was declared deprecated
1>        C:\Program Files\Windows CE Tools\wce600\SMDK2416_SDK.msi\include\ARMV4I\stdlib.h(190) : see declaration of '_wcsupr'
1>        Message: 'This function or variable may be unsafe. Consider using _wcsupr_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlchecked.h(226) : warning C4996: '_wcsupr' was declared deprecated
1>        C:\Program Files\Windows CE Tools\wce600\SMDK2416_SDK.msi\include\ARMV4I\stdlib.h(190) : see declaration of '_wcsupr'
1>        Message: 'This function or variable may be unsafe. Consider using _wcsupr_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlchecked.h(291) : warning C4996: '_gcvt' was declared deprecated
1>        C:\Program Files\Windows CE Tools\wce600\SMDK2416_SDK.msi\include\ARMV4I\stdlib.h(529) : see declaration of '_gcvt'
1>        Message: 'This function or variable may be unsafe. Consider using _gcvt_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
解决:

#define _CRT_SECURE_NO_DEPRECATE


1>.\BlueTTSDlg.cpp(296) : error C2664: 'ISpeechVoice::Speak' : cannot convert parameter 1 from 'const char [6]' to 'LPCTSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\BlueTTSDlg.cpp(326) : error C2664: 'ISpeechVoice::Speak' : cannot convert parameter 1 from 'const char [1]' to 'LPCTSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\BlueTTSDlg.cpp(415) : error C2664: 'ISpeechVoice::Speak' : cannot convert parameter 1 from 'const char [5]' to 'LPCTSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


解决:

const char to LPCTSTR不能转化问题


 

Visual C++ 2008里cannot convert parameter 1 from 'const char [13]' to 'LPCTSTR'造成不能运行的原因主要是2005和2008中增加了一些参数类型的安全性检查,所以通常在6.0没有问题的LPCTSTR与 const char之间的转换到了这里就玩不转。微软给出的解决办法有两个:

  1. Change your project configuration to use multibyte strings. Press ALT+F7 to open the properties, and navigate to Configuration Properties > General. Switch Character Set to "Use Multi-Byte Character Set".
  2. Indicate that the string literal, in this case "Hello world!" is of a specific encoding. This can be done through either prefixing it with L, such as L"Hello world!", or surrounding it with the generic _T("Hello world!") macro. The latter will expand to the L prefix if you are compiling for unicode (see #1), and nothing (indicating multi-byte) otherwise.

但是如果是变量,不是常量字符串的话,就还是会有问题。最痛快的办法就是在建立工程时,直接选不用那个Use Unicode libraries ,这样就不会再遇到这个问题了。



1>C:\Program Files\Windows CE Tools\wce600\SMDK2416_SDK.msi\include\ARMV4I\shellapi.h(321) : error C2061: syntax error : identifier 'SHFILEINFOW'



1>.\BlueTTSDlg.cpp(226) : error C2065: 'WM_ICONERASEBKGND' : undeclared identifier

解决;

暂时屏蔽掉此信息



c:/program files/microsoft speech sdk 5.1/include/sphelper.h(769) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int


c:/program files/microsoft speech sdk 5.1/include/sphelper.h(1419) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:/program files/microsoft speech sdk 5.1/include/sphelper.h(2373) : error C2065: 'psz' : undeclared identifier


c:/program files/microsoft speech sdk 5.1/include/sphelper.h(2559) : error C2440: 'initializing' : cannot convert from 'CSpDynamicString' to 'SPPHONEID *'
 No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
c:/program files/microsoft speech sdk 5.1/include/sphelper.h(2633) : error C2664: 'wcslen' : cannot convert parameter 1 from 'SPPHONEID *' to 'const wchar_t *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


Speech代码编写时间太早,语法不严密。而VS2003(及以上)对于语法检查非常严格,导致编译无法通过。修改头文件中的以下行即可正常编译:


Line 769


   修改前: const ulLenVendorPreferred = wcslen(pszVendorPreferred);
   修改后: const unsigned long ulLenVendorPreferred = wcslen(pszVendorPreferred);


Line 1418


    修改前: static CoMemCopyWFEX(const WAVEFORMATEX * pSrc, WAVEFORMATEX ** ppCoMemWFEX)


    修改后: static HRESULT CoMemCopyWFEX(const WAVEFORMATEX * pSrc, WAVEFORMATEX ** ppCoMemWFEX)


Line 2372


    修改前: for (const WCHAR * psz = (const WCHAR *)lParam; *psz; psz++) {}


    修改后: const WCHAR * psz; for (psz = (const WCHAR *)lParam; *psz; psz++) {}


Line 2559


    修改前: SPPHONEID* pphoneId = dsPhoneId;


    修改后: SPPHONEID* pphoneId = (SPPHONEID*)((WCHAR *)dsPhoneId);
Line 2633
    修改前: pphoneId += wcslen(pphoneId) + 1;
    修改后: pphoneId += wcslen((const wchar_t *)pphoneId) + 1;



等等各种错误,一般都是都是头文件路径包含错误,另外windows下与wince使用语言各种函数体不一样,大都不支持。所以需要改下。