Problems with Unicode / Mulitbyte
-
I need to get some data from LDAP and found an example here : https://msdn.microsoft.com/en-us/library/aa367016(v=vs.85).aspx
I tried to add these lines to my programm:PCHAR hostName = "fabrikam.com"; LDAP* pLdapConnection = NULL; pLdapConnection = ldap_init(hostName, LDAP_PORT);
Now I've ran into the problem that I get an error cannot convert from 'const char[21] to 'PCHAR'.
I've tried to search for a solution and found lot's of cases for example :
https://forum.qt.io/topic/50799/error-cannot-convert-const-wchar-to-lpcwstr/15
https://stackoverflow.com/questions/9770636/cannot-convert-char-to-wchar-qt-c
https://forum.qt.io/topic/25572/a-few-problems-with-qtI've tried PCHAR hostName = L"fabrikam.com";
PCHAR hostName = _T("fabrikam.com");#ifdef _UNICODE
#ifndef UNICODE
#define UNICODE
#endif
#endif
#include <windows.h>in the .pro file
DEFINES -= UNICODE
DEFINES += _MBCSBut I keep getting the same error nomatter what.
-
OK, so this works...
char hostName[] = "dczrh.juliusbaer.com";
no other changes needed.Also for the ldap library add in the .pro file:
LIBS += -lwldap32 -
You're mixing ANSI and "universal" calls. You shouldn't do that as it won't compile in unicode mode.
These are the valid options:Use ANSI explicitly:
CHAR hostName[] = "dczrh.juliusbaer.com"; ldap_initA(hostName, LDAP_PORT);
Use UNICODE explicitly:
WCHAR hostName[] = L"dczrh.juliusbaer.com"; ldap_initW(hostName, LDAP_PORT);
Use "universal" code which will expand to one of the above depending on the
UNICODE
macro being defined or not:TCHAR hostName[] = _T("dczrh.juliusbaer.com"); ldap_init(hostName, LDAP_PORT);