How to Use Unicode in C++ Editions


Unicode characters are supported across all /n software editions, including the C++ editions. When working with Unicode, wide character strings should be used wherever string input is required. The implementation differs between newer (2020+) and older versions, and this article outlines how to work with both.

Newer Versions (2020+)

In 2020 and later, Unicode support is provided through updated header files that enable components to work directly with wide character strings. To use this functionality, add the <installation directory>/include/unicode folder to your include path.

To update existing code:

  1. Update the include path to use <installation directory>/include/unicode.
  2. Remove the "W" suffix from class and type names.

Older Versions (2016 and Earlier)

In older versions, Unicode support is implemented through separate classes that use wide character strings. These classes are identical to the standard ones but include a "W" suffix (for example, IPPortW).

The following examples demonstrate equivalent functionality in older and newer versions:

2016 2020

class mySFTP : public SFTPW {
public:
  virtual int FireSSHServerAuthentication(SFTPSSHServerAuthenticationEventParamsW* e) {
    e->Accept = true;
    return 0;
  }
  virtual int FireSSHStatus(SFTPSSHStatusEventParamsW* e) {
    OutputDebugStringW(e->Message);
    return 0;
  }
};
int main()
{
  mySFTP sftp;
  sftp.SetSSHUser((LPWSTR)L"user");
  sftp.SetSSHPassword((LPWSTR)L"password");
  sftp.SSHLogon((LPWSTR)L"sftp.server.com", 22);
  sftp.ListDirectory();
  sftp.SSHLogoff();
}

class mySFTP : public SFTP {
public:
  virtual int FireSSHServerAuthentication(SFTPSSHServerAuthenticationEventParams* e) {
    e->Accept = true;
    return 0;
  }
  virtual int FireSSHStatus(SFTPSSHStatusEventParams* e) {
    OutputDebugStringW(e->Message);
    return 0;
  }
};
int main()
{
  mySFTP sftp;
  sftp.SetSSHUser((LPWSTR)L"user");
  sftp.SetSSHPassword((LPWSTR)L"password");
  sftp.SSHLogon((LPWSTR)L"sftp.server.com", 22);
  sftp.ListDirectory();
  sftp.SSHLogoff();
}

We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.