Sample code for 30+ languages & platforms
Unicode 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 Unicode C Downloads

Unicode C
#include <C_CkFormatsW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkFormatsW fmt;
    HCkJsonObjectW json;
    HCkJsonObjectW jsonOut;

    success = FALSE;

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

    fmt = CkFormatsW_Create();
    json = CkJsonObjectW_Create();
    jsonOut = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateInt(json,L"render.moduleSize",6);
    CkJsonObjectW_UpdateBool(json,L"output.overwrite",TRUE);
    CkJsonObjectW_UpdateString(json,L"output.return",L"none");

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

    wprintf(L"email: version %d, %s\n",CkJsonObjectW_IntOf(jsonOut,L"symbols[0].selectedEncoding.version"),CkJsonObjectW_stringOf(jsonOut,L"outputs[0].path"));

    //  image

    //  A phone number to dial, in international form.
    CkJsonObjectW_UpdateString(json,L"payload.text",L"tel:+15555550100");
    CkJsonObjectW_UpdateString(json,L"output.path",L"qa_output/qr_phone.png");
    success = CkFormatsW_QrCode(fmt,L"generate",json,jsonOut);
    if (success == FALSE) {
        wprintf(L"%s\n",CkFormatsW_lastErrorText(fmt));
        CkFormatsW_Dispose(fmt);
        CkJsonObjectW_Dispose(json);
        CkJsonObjectW_Dispose(jsonOut);
        return;
    }

    wprintf(L"phone: version %d, %s\n",CkJsonObjectW_IntOf(jsonOut,L"symbols[0].selectedEncoding.version"),CkJsonObjectW_stringOf(jsonOut,L"outputs[0].path"));

    //  image

    //  A text message: the number, then the message.
    CkJsonObjectW_UpdateString(json,L"payload.text",L"SMSTO:+15555550100:Please call me back");
    CkJsonObjectW_UpdateString(json,L"output.path",L"qa_output/qr_sms.png");
    success = CkFormatsW_QrCode(fmt,L"generate",json,jsonOut);
    if (success == FALSE) {
        wprintf(L"%s\n",CkFormatsW_lastErrorText(fmt));
        CkFormatsW_Dispose(fmt);
        CkJsonObjectW_Dispose(json);
        CkJsonObjectW_Dispose(jsonOut);
        return;
    }

    wprintf(L"sms: version %d, %s\n",CkJsonObjectW_IntOf(jsonOut,L"symbols[0].selectedEncoding.version"),CkJsonObjectW_stringOf(jsonOut,L"outputs[0].path"));

    //  image

    //  A location: latitude, then longitude, in degrees.
    CkJsonObjectW_UpdateString(json,L"payload.text",L"geo:41.8781,-87.6298");
    CkJsonObjectW_UpdateString(json,L"output.path",L"qa_output/qr_location.png");
    success = CkFormatsW_QrCode(fmt,L"generate",json,jsonOut);
    if (success == FALSE) {
        wprintf(L"%s\n",CkFormatsW_lastErrorText(fmt));
        CkFormatsW_Dispose(fmt);
        CkJsonObjectW_Dispose(json);
        CkJsonObjectW_Dispose(jsonOut);
        return;
    }

    wprintf(L"location: version %d, %s\n",CkJsonObjectW_IntOf(jsonOut,L"symbols[0].selectedEncoding.version"),CkJsonObjectW_stringOf(jsonOut,L"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


    CkFormatsW_Dispose(fmt);
    CkJsonObjectW_Dispose(json);
    CkJsonObjectW_Dispose(jsonOut);

    }