Sample code for 30+ languages & platforms
C Requires Chilkat v11.7.0+

QR Codes for Email, Phone, SMS and Location

See more QR Code Examples

Demonstrates QR codes that start an action on a phone. A QR code only holds text, and what happens on scanning depends on the form of that text: mailto: starts an email, tel: dials a number, SMSTO: starts a text message, and geo: opens a map at a latitude and longitude. A web address opens in the browser.

Chilkat C Downloads

C
#include <C_CkFormats.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkFormats fmt;
    HCkJsonObject json;
    HCkJsonObject jsonOut;

    success = FALSE;

    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    fmt = CkFormats_Create();
    json = CkJsonObject_Create();
    jsonOut = CkJsonObject_Create();
    CkJsonObject_UpdateInt(json,"render.moduleSize",6);
    CkJsonObject_UpdateBool(json,"output.overwrite",TRUE);
    CkJsonObject_UpdateString(json,"output.return","none");

    //  An email, with the address and optionally a subject.  Spaces in the subject are written %20.
    CkJsonObject_UpdateString(json,"payload.text","mailto:support@example.com?subject=Order%2012345");
    CkJsonObject_UpdateString(json,"output.path","qa_output/qr_email.png");
    success = CkFormats_QrCode(fmt,"generate",json,jsonOut);
    if (success == FALSE) {
        printf("%s\n",CkFormats_lastErrorText(fmt));
        CkFormats_Dispose(fmt);
        CkJsonObject_Dispose(json);
        CkJsonObject_Dispose(jsonOut);
        return;
    }

    printf("email: version %d, %s\n",CkJsonObject_IntOf(jsonOut,"symbols[0].selectedEncoding.version"),CkJsonObject_stringOf(jsonOut,"outputs[0].path"));

    //  image

    //  A phone number to dial, in international form.
    CkJsonObject_UpdateString(json,"payload.text","tel:+15555550100");
    CkJsonObject_UpdateString(json,"output.path","qa_output/qr_phone.png");
    success = CkFormats_QrCode(fmt,"generate",json,jsonOut);
    if (success == FALSE) {
        printf("%s\n",CkFormats_lastErrorText(fmt));
        CkFormats_Dispose(fmt);
        CkJsonObject_Dispose(json);
        CkJsonObject_Dispose(jsonOut);
        return;
    }

    printf("phone: version %d, %s\n",CkJsonObject_IntOf(jsonOut,"symbols[0].selectedEncoding.version"),CkJsonObject_stringOf(jsonOut,"outputs[0].path"));

    //  image

    //  A text message: the number, then the message.
    CkJsonObject_UpdateString(json,"payload.text","SMSTO:+15555550100:Please call me back");
    CkJsonObject_UpdateString(json,"output.path","qa_output/qr_sms.png");
    success = CkFormats_QrCode(fmt,"generate",json,jsonOut);
    if (success == FALSE) {
        printf("%s\n",CkFormats_lastErrorText(fmt));
        CkFormats_Dispose(fmt);
        CkJsonObject_Dispose(json);
        CkJsonObject_Dispose(jsonOut);
        return;
    }

    printf("sms: version %d, %s\n",CkJsonObject_IntOf(jsonOut,"symbols[0].selectedEncoding.version"),CkJsonObject_stringOf(jsonOut,"outputs[0].path"));

    //  image

    //  A location: latitude, then longitude, in degrees.
    CkJsonObject_UpdateString(json,"payload.text","geo:41.8781,-87.6298");
    CkJsonObject_UpdateString(json,"output.path","qa_output/qr_location.png");
    success = CkFormats_QrCode(fmt,"generate",json,jsonOut);
    if (success == FALSE) {
        printf("%s\n",CkFormats_lastErrorText(fmt));
        CkFormats_Dispose(fmt);
        CkJsonObject_Dispose(json);
        CkJsonObject_Dispose(jsonOut);
        return;
    }

    printf("location: version %d, %s\n",CkJsonObject_IntOf(jsonOut,"symbols[0].selectedEncoding.version"),CkJsonObject_stringOf(jsonOut,"outputs[0].path"));

    //  image

    //  Sample output:

    //  email: version 4, qa_output/qr_email.png
    //  phone: version 2, qa_output/qr_phone.png
    //  sms: version 3, qa_output/qr_sms.png
    //  location: version 2, qa_output/qr_location.png


    CkFormats_Dispose(fmt);
    CkJsonObject_Dispose(json);
    CkJsonObject_Dispose(jsonOut);

    }