Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#DataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVBScriptXojo PluginNode.jsGo

Unicode C++ Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Unicode C++) Chilkat Functions Returning a String

This example explains Chilkat functions in Unicode C++ that directly return a string. These functions begin with a lowercase letter.

If a string is returned directly by a Chilkat method (in Unicode C++), it is a pointer into internal memory managed by Chilkat. It is not guaranteed to stay in memory forever. In fact, there are 10 possible internal buffers to hold the strings returned by a lowercase function. After the 10th lowercase function is called, the string returned by the least recent function call is no longer valid.

The intent of returning the string directly is for convenience. It is for cases where the application will immediately use the string, or for cases where the application immediately copies the string to an object or buffer under its own management.

This example demonstrates the 10 internal buffer limit.

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS/Heroku C/C++

MAC OS X C/C++

C++ Builder

Solaris C/C++

iOS C/C++

Android C/C++

Raspberry Pi C/C++

Windows Mobile 5.0/Pocket PC 2003

ARM Embedded Linux C/C++

PowerLinux C/C++

FreeBSD C/C++

MinGW C/C++

#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    // This example demonstrates the 10 internal buffer limit for functions returning strings.
    // We'll demonstrate using the JSON object.

    CkJsonObjectW json;

    // First, build a JSON document.
    json.UpdateString(L"x1",L"1");
    json.UpdateString(L"x2",L"2");
    json.UpdateString(L"x3",L"3");
    json.UpdateString(L"x4",L"4");
    json.UpdateString(L"x5",L"5");
    json.UpdateString(L"x6",L"6");
    json.UpdateString(L"x7",L"7");
    json.UpdateString(L"x8",L"8");
    json.UpdateString(L"x9",L"9");
    json.UpdateString(L"x10",L"10");
    json.UpdateString(L"x11",L"11");
    json.UpdateString(L"x12",L"12");

    // Call 12 functions in a row that directly return strings.
    // This is an error because there are a max of 10 internal buffers per Chilkat object
    // to hold the returned strings.
    // The calls to get "x11" and "x12" overwrite the internal buffers used by x1 and x2.
    const wchar_t *x1 = json.stringOf(L"x1");
    wprintf(L"x1: %s\n",x1);
    const wchar_t *x2 = json.stringOf(L"x2");
    wprintf(L"x2: %s\n",x2);
    const wchar_t *x3 = json.stringOf(L"x3");
    wprintf(L"x3: %s\n",x3);
    const wchar_t *x4 = json.stringOf(L"x4");
    wprintf(L"x4: %s\n",x4);
    const wchar_t *x5 = json.stringOf(L"x5");
    wprintf(L"x5: %s\n",x5);
    const wchar_t *x6 = json.stringOf(L"x6");
    wprintf(L"x6: %s\n",x6);
    const wchar_t *x7 = json.stringOf(L"x7");
    wprintf(L"x7: %s\n",x7);
    const wchar_t *x8 = json.stringOf(L"x8");
    wprintf(L"x8: %s\n",x8);
    const wchar_t *x9 = json.stringOf(L"x9");
    wprintf(L"x9: %s\n",x9);
    const wchar_t *x10 = json.stringOf(L"x10");
    wprintf(L"x10: %s\n",x10);
    // This call invalidates the memory pointed to by x1.
    const wchar_t *x11 = json.stringOf(L"x11");
    wprintf(L"x11: %s\n",x11);
    // This call invalidates the memory pointed to by x2.
    const wchar_t *x12 = json.stringOf(L"x12");
    wprintf(L"x12: %s\n",x12);
    wprintf(L"---\n");

    // If we try to get x1 and x2 again, 
    // we can see how the buffers were overwritten.
    // In fact, x1 and x2 may point to already-deleted memory,
    // and accessing the memory at these pointers may cause a crash.
    wprintf(L"x1: %s\n",x1);
    wprintf(L"x2: %s\n",x2);
    wprintf(L"x3: %s\n",x3);
    wprintf(L"x4: %s\n",x4);
    wprintf(L"x5: %s\n",x5);
    wprintf(L"x6: %s\n",x6);
    wprintf(L"x7: %s\n",x7);
    wprintf(L"x8: %s\n",x8);
    wprintf(L"x9: %s\n",x9);
    wprintf(L"x10: %s\n",x10);
    wprintf(L"x11: %s\n",x11);
    wprintf(L"x12: %s\n",x12);
    }

 

© 2000-2022 Chilkat Software, Inc. All Rights Reserved.