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 to 'PCHAR'.
I've tried to search for a solution and found lot's of cases for example :
in the .pro file
DEFINES -= UNICODE
DEFINES += _MBCS
But 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
UNICODEmacro being defined or not:
TCHAR hostName = _T("dczrh.juliusbaer.com"); ldap_init(hostName, LDAP_PORT);
Thank you for clarifying, I wasn't aware of that.