简体   繁体   中英

Visual Studio 2013 - C++ Errors

Some strange things happen. When I compile my program in Dev-C++ it gives me no errors and compiles clean. When I put it in Visual Studio I got a LOT of errors:

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'

It all works on Dev-C++ tho. I need to compile it in VS because I want to add something from the POCO library, which, ironically, doesn't compile in Dev-C++... Any help?

A Visual Studio project defines UNICODE by default.

You can either turn off Unicode in the project settings, or rework your program to use wchar_t based strings (eg L"Blah" instead of "Blah" ).

Or, you can #undef UNICODE before including <windows.h> , every place.

There seem to be some issues about #include statements in your Project. You need to figure out why MailRecipient gets redefined. You will probably have to adjust some of the project settings in Visual Studio.
Also, as the first answer suggests Visual Studio uses UNICODE by default, which causes it to call the wide string versions of Windows API functions. You can use the std::widen function to convert your strings just for Windows API calls. For more information on this topic see utf8everywhere.org .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM