Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

C++ Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
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
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(C++) Chilkat Functions Returning a String

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

If a string is returned directly by a Chilkat method (in 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 C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Win Mobile 5.0/Pocket PC 2003

Solaris C/C++

FreeBSD C/C++

OpenBSD C/C++

MinGW C/C++

#include <CkJsonObject.h>

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

    CkJsonObject json;

    // First, build a JSON document.
    json.UpdateString("x1","1");
    json.UpdateString("x2","2");
    json.UpdateString("x3","3");
    json.UpdateString("x4","4");
    json.UpdateString("x5","5");
    json.UpdateString("x6","6");
    json.UpdateString("x7","7");
    json.UpdateString("x8","8");
    json.UpdateString("x9","9");
    json.UpdateString("x10","10");
    json.UpdateString("x11","11");
    json.UpdateString("x12","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 char *x1 = json.stringOf("x1");
    std::cout << "x1: " << x1 << "\r\n";
    const char *x2 = json.stringOf("x2");
    std::cout << "x2: " << x2 << "\r\n";
    const char *x3 = json.stringOf("x3");
    std::cout << "x3: " << x3 << "\r\n";
    const char *x4 = json.stringOf("x4");
    std::cout << "x4: " << x4 << "\r\n";
    const char *x5 = json.stringOf("x5");
    std::cout << "x5: " << x5 << "\r\n";
    const char *x6 = json.stringOf("x6");
    std::cout << "x6: " << x6 << "\r\n";
    const char *x7 = json.stringOf("x7");
    std::cout << "x7: " << x7 << "\r\n";
    const char *x8 = json.stringOf("x8");
    std::cout << "x8: " << x8 << "\r\n";
    const char *x9 = json.stringOf("x9");
    std::cout << "x9: " << x9 << "\r\n";
    const char *x10 = json.stringOf("x10");
    std::cout << "x10: " << x10 << "\r\n";
    // This call invalidates the memory pointed to by x1.
    const char *x11 = json.stringOf("x11");
    std::cout << "x11: " << x11 << "\r\n";
    // This call invalidates the memory pointed to by x2.
    const char *x12 = json.stringOf("x12");
    std::cout << "x12: " << x12 << "\r\n";
    std::cout << "---" << "\r\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.
    std::cout << "x1: " << x1 << "\r\n";
    std::cout << "x2: " << x2 << "\r\n";
    std::cout << "x3: " << x3 << "\r\n";
    std::cout << "x4: " << x4 << "\r\n";
    std::cout << "x5: " << x5 << "\r\n";
    std::cout << "x6: " << x6 << "\r\n";
    std::cout << "x7: " << x7 << "\r\n";
    std::cout << "x8: " << x8 << "\r\n";
    std::cout << "x9: " << x9 << "\r\n";
    std::cout << "x10: " << x10 << "\r\n";
    std::cout << "x11: " << x11 << "\r\n";
    std::cout << "x12: " << x12 << "\r\n";
    }

 

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