Visual Studio 2013 - C ++错误

时间:2014-12-01 14:55:12

标签: c++ visual-studio visual-studio-2013 compiler-errors poco

发生了一些奇怪的事情。当我在Dev-C ++中编译我的程序时,它给了我没有错误并编译干净。当我把它放在Visual Studio中时,我遇到了很多错误:

Error   1   error C2371: 'MailRecipient' : redefinition; different basic types
Error   2   error C3861: 'GetModuleFileName': identifier not found  
Error   3   error C2664: 'HRESULT SHGetFolderPathW(HWND,int,HANDLE,DWORD,LPWSTR)' : cannot convert argument 5 from 'char [260]' to 'LPWSTR'
Error   4   error C3861: 'CopyFile': identifier not found
Error   5   error C2664: 'BOOL SetFileAttributesW(LPCWSTR,DWORD)' : cannot convert argument 1 from 'char [512]' to 'LPCWSTR'
Error   6   error C2664: 'HRESULT SHGetFolderPathW(HWND,int,HANDLE,DWORD,LPWSTR)' : cannot convert argument 5 from 'char [260]' to 'LPWSTR'
Error   7   error C2664: 'BOOL SetFileAttributesW(LPCWSTR,DWORD)' : cannot convert argument 1 from 'char []' to 'LPCWSTR'
Error   8   error C2664: 'LSTATUS RegOpenKeyExW(HKEY,LPCWSTR,DWORD,REGSAM,PHKEY)' : cannot convert argument 2 from 'const char [46]' to 'LPCWSTR'
Error   9   error C2664: 'HRESULT SHGetFolderPathW(HWND,int,HANDLE,DWORD,LPWSTR)' : cannot convert argument 5 from 'char [260]' to 'LPWSTR'
Error   10  error C2664: 'LSTATUS RegSetValueExW(HKEY,LPCWSTR,DWORD,DWORD,const BYTE *,DWORD)' : cannot convert argument 2 from 'const char [9]' to 'LPCWSTR'

这一切都适用于Dev-C ++。我需要在VS中编译它,因为我想从POCO库中添加一些东西,具有讽刺意味的是,它不能在Dev-C ++中编译......有什么帮助吗?

2 个答案:

答案 0 :(得分:2)

默认情况下,Visual Studio项目定义 UNICODE

您可以在项目设置中关闭Unicode,或者重新编写程序以使用基于wchar_t的字符串(例如L"Blah"代替"Blah")。

或者,您可以#undef UNICODE包括<windows.h>,每个地方。

答案 1 :(得分:0)

项目中的#include语句似乎存在一些问题。您需要弄清楚MailRecipient重新定义的原因。您可能必须在Visual Studio中调整一些项目设置。
另外,第一个答案表明Visual Studio默认使用UNICODE,这会导致它调用Windows API函数的宽字符串版本。您可以使用std :: widen函数转换字符串,仅用于Windows API调用。有关此主题的更多信息,请参阅utf8everywhere.org