CryptoSys PKI Pro Manual

CNV_Utf8FromWide

Maps a UTF-16 (wide character) string to a UTF-8-encoded string.

VBA/VB6 Syntax

No VBA/VB6 equivalent.

C/C++ Syntax

long __stdcall CNV_Utf8FromWide(char *szOut, long nOutChars, const wchar_t* wstr);

Parameters

szOut
[out] Buffer to receive null-terminated UTF-8-encoded string.
nOutChars
[in] Maximum length of output string in bytes (excluding the terminating null).
wstr
[in] String of wide characters to be processed.

Returns (VBA/C)

Number of characters (bytes) in or required for the output string; otherwise it returns a negative error code.

.NET Equivalent

No .NET equivalent.

C++ (STL) Equivalent

static std::string dipki::Cnv::Utf8FromWide (const std::wstring &wstr)

Remarks

Use this function to convert a C/C++ string of "Unicode" UTF-16 wchar_t characters to a UTF-8-encoded string of type char.

For the "raw" ANSI function, pass a NULL szOut or zero nOutChars to find the required output length in bytes. Allocate one extra byte for the terminating null.

This function is for C/C++ programmers only. There is no VBA or .NET equivalent.

Example

#include <wchar.h>
long nchars;
char *buf = NULL;
wchar_t *wstr = L"áéÍñóü";
// Find required output length (12 in this case)
nchars = CNV_Utf8FromWide(NULL, 0, wstr);
printf("CNV_Utf8FromWide returns %ld\n", nchars);
assert(nchars >= 0);
buf = malloc(nchars + 1);  // NB one extra byte
nchars = CNV_Utf8FromWide(buf, nchars, wstr);
assert(nchars >= 0);
// Assumes console codepage is set to UTF-8
printf("[%s]\n", buf);
free(buf);
#include <string>
std::string s;
std::wstring wstr;
wstr = L"áéÍñóü";
s = dipki::Cnv::Utf8FromWide(wstr);
cout << "Cnv::Utf8FromWide=[" << s << "]" << endl;
cout << "s-->utf-8 bytes: " << dipki::Cnv::ToHex(dipki::str2bvec(s)) << endl;
Cnv::Utf8FromWide=[áéÍñóü]
s-->utf-8 bytes: C3A1C3A9C3ADC3B1C3B3C3BC

See Also

[Contents] [Index]

[PREV: CNV_UTF8BytesFromLatin1...]   [Contents]   [Index]   
   [NEXT: COMPR_Compress...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.