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 <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkJsonObject json;
    const char *x1;
    const char *x2;
    const char *x3;
    const char *x4;
    const char *x5;
    const char *x6;
    const char *x7;
    const char *x8;
    const char *x9;
    const char *x10;
    const char *x11;
    const char *x12;

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

    json = CkJsonObject_Create();

    // First, build a JSON document.
    CkJsonObject_UpdateString(json,"x1","1");
    CkJsonObject_UpdateString(json,"x2","2");
    CkJsonObject_UpdateString(json,"x3","3");
    CkJsonObject_UpdateString(json,"x4","4");
    CkJsonObject_UpdateString(json,"x5","5");
    CkJsonObject_UpdateString(json,"x6","6");
    CkJsonObject_UpdateString(json,"x7","7");
    CkJsonObject_UpdateString(json,"x8","8");
    CkJsonObject_UpdateString(json,"x9","9");
    CkJsonObject_UpdateString(json,"x10","10");
    CkJsonObject_UpdateString(json,"x11","11");
    CkJsonObject_UpdateString(json,"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.
    x1 = CkJsonObject_stringOf(json,"x1");
    printf("x1: %s\n",x1);
    x2 = CkJsonObject_stringOf(json,"x2");
    printf("x2: %s\n",x2);
    x3 = CkJsonObject_stringOf(json,"x3");
    printf("x3: %s\n",x3);
    x4 = CkJsonObject_stringOf(json,"x4");
    printf("x4: %s\n",x4);
    x5 = CkJsonObject_stringOf(json,"x5");
    printf("x5: %s\n",x5);
    x6 = CkJsonObject_stringOf(json,"x6");
    printf("x6: %s\n",x6);
    x7 = CkJsonObject_stringOf(json,"x7");
    printf("x7: %s\n",x7);
    x8 = CkJsonObject_stringOf(json,"x8");
    printf("x8: %s\n",x8);
    x9 = CkJsonObject_stringOf(json,"x9");
    printf("x9: %s\n",x9);
    x10 = CkJsonObject_stringOf(json,"x10");
    printf("x10: %s\n",x10);
    // This call invalidates the memory pointed to by x1.
    x11 = CkJsonObject_stringOf(json,"x11");
    printf("x11: %s\n",x11);
    // This call invalidates the memory pointed to by x2.
    x12 = CkJsonObject_stringOf(json,"x12");
    printf("x12: %s\n",x12);
    printf("---\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.
    printf("x1: %s\n",x1);
    printf("x2: %s\n",x2);
    printf("x3: %s\n",x3);
    printf("x4: %s\n",x4);
    printf("x5: %s\n",x5);
    printf("x6: %s\n",x6);
    printf("x7: %s\n",x7);
    printf("x8: %s\n",x8);
    printf("x9: %s\n",x9);
    printf("x10: %s\n",x10);
    printf("x11: %s\n",x11);
    printf("x12: %s\n",x12);


    CkJsonObject_Dispose(json);

    }

 

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