Visual Studio 2013 - C++ Errors - c++

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 (e.g. 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.

Related

What the underlying reason C code will compile using mingw32 in Linux but Visual Studio C has problems

So Im wondering why C code compiled for me with mingw32 (this program here fo reference https://github.com/newsoft/adduser) with no issues or mentions of errors (other than some case-sensitivity in naming of the headers i mean)
Though, when I tried in Visual Studio 2019 I get the following "errors" that need to be cleaned up.
Error C2440 '=': cannot convert from 'const wchar_t [15]' to 'LPWSTR' adduser-test2 C:\Users\Administrator\source\repos\adduser-test\adduser-test2\adduser-test2.cpp 39
Error C2440 '=': cannot convert from 'const wchar_t [6]' to 'LPWSTR' adduser-test2 C:\Users\Administrator\source\repos\adduser-test\adduser-test2\adduser-test2.cpp 38
Is it some sort of strict compiler settings for "safer code"? Or is one compiler actually just able to convert a const wchar_t could convert to a pointer to a wchar_t if necessary

errors C2784, C2672 and C2664 in Visual studio 2015

I have following lines in visual studio 2015. It used to be compiled without error in visual studio 2013.
const std::basic_regex<wchar_t> e(_T("([eE][-+])(0)(\\d{2})"));
io_string = std::regex_replace(io_string, e, _T("$1$3"));
the error is:
error C2664: 'std::basic_regex>::basic_regex(std::basic_regex> &&) noexcept': cannot convert argument 1 from 'const char [21]' to 'const wchar_t *'
error C2672: 'std::regex_replace': no matching overloaded function found
4>
error C2784: 'std::basic_string<_Elem,std::char_traits<_Elem>,std::allocator<_Other>> std::regex_replace(const _Elem *,const std::basic_regex<_Elem,_RxTraits> &,const _Elem *,std::regex_constants::match_flag_type)': could not deduce template argument for 'const _Elem *' from 'std::string_t'
I know this issue is coming from change tchar.h. Any suggestion for resolving them. I also use CMake for project configuration and the project is running on windows 10.
Assuming you don't want to change your code, you need to ensure that your code is building for Unicode, so pass -D_UNICODE to the compiler. This post suggests:
ADD_DEFINITIONS(-DUNICODE)
ADD_DEFINITIONS(-D_UNICODE)
And this one illustrates how to enable Unicode through the GUI.

Writing wrappers for Python 3 vs Python 2

In Python, is there any difference in how one would write Python wrappers for c++ libraries if one aims to make it compatible with Py3 vs Py2?
Or should a wrapper originally written for Py2 work the same way for Py3 and visa versa? As I understand it, Python wrappers are written in c++ in a .cxx file which then have to be compiled.
Details
I ask because I'm wanting to install Aggdraw (wrapper for c++ Anti Grain Geometry drawing library), which works in Python 2.6-7, but results in errors on Python 3.4 (Windows 7 32-bit, via "PATH=C:/Python27[or Python34]" and "python setup.py install" in the command line). My hope is to revive this amazing wrapper module for Python 3, and was hoping anyone else here would be interesting in helping out.
I can get it compiled on Python 2.6 and 2.7 without any problems, and I have both Visual C++ 2008 and 2010 so it's not a compiler problem. The problem seems to be in the actual .cxx wrapper code.
Could it be that the Aggdraw wrapper was only written with Python 2x in mind (almost 10 years ago now), and so it didn't take into account problems that might arise in Python 3x? My best guess is that the wrapper fails to convert certain c++ objects/types over to Python due to deprecated and changed features in version 3.4.
I might be willing to go through the .cxx wrapper code to change the necessary parts, if someone can help me identify what the troubleparts are (see command line error codes below)? If we get it fixed then I'll update this post with a link to the "revived" wrapper code.
If there should´t be a difference between Python 2 and 3 wrappers, any idea why I´m getting the error codes below in Py3 but not Py2?
Thanks!
Original wrapper code: click here
C:\Users\BIGKIMO\Desktop\aggdraw-master>python setup.py build
=== freetype not available (edit setup.py to enable)
running install
running build
running build_ext
building 'aggdraw' extension
C:\Program Files\Microsoft Visual Studio 10.0\VC\BIN\cl.exe /c /nologo /Ox /MD /
W3 /GS- /DNDEBUG -Iagg2/include -IC:\Python34\include -IC:\Python34\include /Tpa
ggdraw.cxx /Fobuild\temp.win32-3.4\Release\aggdraw.obj
aggdraw.cxx
aggdraw.cxx(124) : error C2440: 'initializing' : cannot convert from 'const char
[5]' to 'Py_ssize_t'
There is no context in which this conversion is possible
aggdraw.cxx(126) : error C2440: 'initializing' : cannot convert from 'destructor
' to 'printfunc'
This conversion requires a reinterpret_cast, a C-style cast or function-
style cast
aggdraw.cxx(128) : error C2440: 'initializing' : cannot convert from 'getattrfun
c' to 'setattrfunc'
This conversion requires a reinterpret_cast, a C-style cast or function-
style cast
aggdraw.cxx(142) : error C2440: 'initializing' : cannot convert from 'const char
[4]' to 'Py_ssize_t'
There is no context in which this conversion is possible
aggdraw.cxx(144) : error C2440: 'initializing' : cannot convert from 'destructor
' to 'printfunc'
This conversion requires a reinterpret_cast, a C-style cast or function-
style cast
aggdraw.cxx(161) : error C2440: 'initializing' : cannot convert from 'const char
[6]' to 'Py_ssize_t'
There is no context in which this conversion is possible
aggdraw.cxx(163) : error C2440: 'initializing' : cannot convert from 'destructor
' to 'printfunc'
This conversion requires a reinterpret_cast, a C-style cast or function-
style cast
aggdraw.cxx(187) : error C2440: 'initializing' : cannot convert from 'const char
[5]' to 'Py_ssize_t'
There is no context in which this conversion is possible
aggdraw.cxx(189) : error C2440: 'initializing' : cannot convert from 'destructor
' to 'printfunc'
This conversion requires a reinterpret_cast, a C-style cast or function-
style cast
aggdraw.cxx(191) : error C2440: 'initializing' : cannot convert from 'getattrfun
c' to 'setattrfunc'
This conversion requires a reinterpret_cast, a C-style cast or function-
style cast
aggdraw.cxx(207) : error C2440: 'initializing' : cannot convert from 'const char
[5]' to 'Py_ssize_t'
There is no context in which this conversion is possible
aggdraw.cxx(209) : error C2440: 'initializing' : cannot convert from 'destructor
' to 'printfunc'
This conversion requires a reinterpret_cast, a C-style cast or function-
style cast
aggdraw.cxx(211) : error C2440: 'initializing' : cannot convert from 'getattrfun
c' to 'setattrfunc'
This conversion requires a reinterpret_cast, a C-style cast or function-
style cast
aggdraw.cxx(488) : error C3861: 'PyString_Check': identifier not found
aggdraw.cxx(489) : error C3861: 'PyString_AS_STRING': identifier not found
aggdraw.cxx(575) : error C3861: 'PyString_Check': identifier not found
aggdraw.cxx(583) : error C3861: 'PyString_AS_STRING': identifier not found
aggdraw.cxx(584) : error C3861: 'PyString_GET_SIZE': identifier not found
aggdraw.cxx(730) : error C3861: 'PyInt_Check': identifier not found
aggdraw.cxx(730) : error C3861: 'PyInt_AS_LONG': identifier not found
aggdraw.cxx(731) : error C3861: 'PyInt_Check': identifier not found
aggdraw.cxx(731) : error C3861: 'PyInt_AS_LONG': identifier not found
aggdraw.cxx(735) : error C3861: 'PyInt_Check': identifier not found
aggdraw.cxx(735) : error C3861: 'PyInt_AS_LONG': identifier not found
aggdraw.cxx(736) : error C3861: 'PyInt_Check': identifier not found
aggdraw.cxx(736) : error C3861: 'PyInt_AS_LONG': identifier not found
aggdraw.cxx(742) : error C3861: 'PyInt_Check': identifier not found
aggdraw.cxx(742) : error C3861: 'PyInt_AS_LONG': identifier not found
aggdraw.cxx(745) : error C3861: 'PyInt_Check': identifier not found
aggdraw.cxx(745) : error C3861: 'PyInt_AS_LONG': identifier not found
aggdraw.cxx(759) : error C3861: 'PyInt_Check': identifier not found
aggdraw.cxx(760) : error C3861: 'PyInt_AsLong': identifier not found
aggdraw.cxx(763) : error C3861: 'PyString_Check': identifier not found
aggdraw.cxx(765) : error C3861: 'PyString_AS_STRING': identifier not found
aggdraw.cxx(788) : error C3861: 'PyString_Check': identifier not found
aggdraw.cxx(789) : error C3861: 'PyString_AS_STRING': identifier not found
aggdraw.cxx(1157) : error C3861: 'PyString_FromStringAndSize': identifier not fo
und
aggdraw.cxx(1289) : error C3861: 'PyString_FromString': identifier not found
aggdraw.cxx(1294) : error C3861: 'Py_FindMethod': identifier not found
aggdraw.cxx(1482) : error C3861: 'Py_FindMethod': identifier not found
aggdraw.cxx(1890) : error C3861: 'Py_FindMethod': identifier not found
aggdraw.cxx(1910) : error C3646: 'initaggdraw' : unknown override specifier
aggdraw.cxx(1911) : error C2091: function returns function
aggdraw.cxx(1911) : error C4430: missing type specifier - int assumed. Note: C++
does not support default-int
aggdraw.cxx(1912) : error C2039: 'ob_type' : is not a member of '_typeobject'
c:\python34\include\object.h(334) : see declaration of '_typeobject'
aggdraw.cxx(1912) : error C2039: 'ob_type' : is not a member of '_typeobject'
c:\python34\include\object.h(334) : see declaration of '_typeobject'
aggdraw.cxx(1913) : error C2039: 'ob_type' : is not a member of '_typeobject'
c:\python34\include\object.h(334) : see declaration of '_typeobject'
aggdraw.cxx(1913) : error C2039: 'ob_type' : is not a member of '_typeobject'
c:\python34\include\object.h(334) : see declaration of '_typeobject'
aggdraw.cxx(1913) : error C2039: 'ob_type' : is not a member of '_typeobject'
c:\python34\include\object.h(334) : see declaration of '_typeobject'
aggdraw.cxx(1915) : error C3861: 'Py_InitModule': identifier not found
aggdraw.cxx(1940) : warning C4508: 'DL_EXPORT' : function should return a value;
'void' return type assumed
The Python FFI library (ctype) has changes between each version of python. It would be up to you to go through the change list and see what exactly is different and why it isn't working.
For example, ssizet and strings are different between the two Python versions.
https://docs.python.org/3/whatsnew/3.2.html#ctypes
Differences in ctypes between Python 2 and 3
In the interest of expanding upon the previous answer, there are many functions which acted upon string in Py2.7 and now act upon bytes or unicode in Py3. Similarly, what referred to int may now refer to long. As just one example of this that caused a problem here, PyString_Check has been deprecated by pyBytes_Check. Read the following for more details:
https://docs.python.org/3/howto/cporting.html?highlight=pystring

password filter cannot compile in vs2012

I have downloaded some code about password filter in this place. The original project was compiled in vs2008 and vs2010. I updated it to vs2012, and i found it cannot be compiled. How can i fix this, Thank you.
This is the error message:
Error 1 error C2440: '=' : cannot convert from 'char *' to 'TCHAR *' D:\SVN\branch\nobull-branch\util.cpp 72 1 passwdHk
Error 2 error C2664: 'int sprintf_s(char *,size_t,const char *,...)' : cannot convert parameter 1 from 'TCHAR *' to 'char *' D:\SVN\branch\nobull-branch\util.cpp 89 1 passwdHk
Error 3 error C2664: '_strdup' : cannot convert parameter 1 from 'TCHAR *' to 'const char *' D:\SVN\branch\nobull-branch\util.cpp 91 1 passwdHk
Error 4 error C2664: 'strlen' : cannot convert parameter 1 from 'TCHAR *' to 'const char *' D:\SVN\branch\nobull-branch\util.cpp 188 1 passwdHk
Error 5 error C2664: 'pshk_log_write_w' : cannot convert parameter 2 from 'const char [28]' to 'LPCWSTR' D:\SVN\branch\nobull-branch\util.cpp 202 1 passwdHk
Error 6 error C2664: 'strlen' : cannot convert parameter 1 from 'TCHAR *' to 'const char *' D:\SVN\branch\nobull-branch\util.cpp 208 1 passwdHk
Error 7 error C2664: 'strlen' : cannot convert parameter 1 from 'TCHAR *' to 'const char *' D:\SVN\branch\nobull-branch\util.cpp 211 1 passwdHk
Error 8 error C2664: '_strdup' : cannot convert parameter 1 from 'TCHAR *' to 'const char *' D:\SVN\branch\nobull-branch\util.cpp 224 1 passwdHk
Error 9 error C2664: 'strlen' : cannot convert parameter 1 from 'TCHAR *' to 'const char *' D:\SVN\branch\nobull-branch\util.cpp 229 1 passwdHk
Error 10 error C2446: ':' : no conversion from 'const char *' to 'TCHAR *' D:\SVN\branch\nobull-branch\util.cpp 249 1 passwdHk
Error 11 error C2664: 'int _snprintf_s(char *,size_t,size_t,const char *,...)' : cannot convert parameter 1 from 'TCHAR *' to 'char *' D:\SVN\branch\nobull-branch\util.cpp 249 1 passwdHk
Error 12 error C2664: 'int _snprintf_s(char *,size_t,size_t,const char *,...)' : cannot convert parameter 1 from 'TCHAR *' to 'char *' D:\SVN\branch\nobull-branch\util.cpp 254 1 passwdHk
It is highly likely you do not want unicode compilation for your current predicament (erahh... project).
Right click your project in the project explorer, select "Properties..."
At the very top of the properties dialog is a Configuration selection drop-down list. You likely want to change all your configurations (unless for some odd reason you want to build non-Unicode debug, but Unicode release). If you want them all non-Unicode (and you likely do) select "All Configurations".
In the left pane immediately under Configuration Properties, select "General"
In the right pane, under Project Defaults, find "Character Set"
If it is currently set to Unicode Character Set, change it to "Multi-Byte Character Set" or "Not Set" if you're not planning on using MBCS features.
Save your project file, and rebuild the world.
Note: some of the the function calls in your APIs are hopefully chosen-via-macro definition. one in particular I'm concerned about is pshk_log_write_w(), the name implying it is chosen because you were compiling as Unicode (I hope). With any luck there is an associated pshk_log_write_a() narrow-version of that function that will automatically be picked up as the intended target when you make the above changes. If not, there may be some places where you'll need to do some wide-to-narrow conversions, but I can only hope not. It is a pain to do so.
TCHAR is Microsoft's macro for either 8 bit chars (char) or 16 bit chars (wchar_t) to help distinguish between Unicode and ASCII strings. They have two distinct API sets in the SDK, so that is why the compiler is compiler. It seems like Visual Studio 2012 defaults to wchar_t instead of char. You can disable it via the options for the project: Right click the project, then click Properties. Under the general section, there should be a Character Set option. Change it from Use Unicode character set to Use MultiByte characters. Read the following page for more details: http://msdn.microsoft.com/en-us/library/c426s321%28v=vs.71%29.aspx Hope that helps.

Asio Compiler errors (Win7 64 Bit + VC11)

a few days ago I upgraded from Win7 32Bit + Visual Studio 2008 to Win7 64Bit + Visual Studio 2012 (VC11). Now I have problems with compiling my application. I get the following errors:
1>...\asio-1.5.3\include\asio/detail/impl/win_thread.ipp(51): error C2664: 'QueueUserAPC': cannot convert parameter 1 from 'void (__cdecl *)(ULONG)' to 'PAPCFUNC'
1>...\asio-1.5.3\include\asio/detail/impl/win_iocp_io_service.ipp(119): error C2664: 'GetQueuedCompletionStatus': cannot convert parameter 3 from 'DWORD *' to 'PULONG_PTR'
1>...\asio-1.5.3\include\asio/detail/impl/win_iocp_io_service.ipp(349): error C2664: 'GetQueuedCompletionStatus': cannot convert parameter 3 from 'DWORD *' to 'PULONG_PTR'
And I get the same errors with the latest version of boost::asio (Boost 1.52)
What’s wrong here?
with WINVER set to 0x0501 it's working - Many Thanks to Hans Passant for his hint!