Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

C++ Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
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
Misc
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
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(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++

Solaris 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-2024 Chilkat Software, Inc. All Rights Reserved.