How to send sms from c/c++ with smpp

To create software for sending text messages from c/c++ with smpp requires basic knowledge of how mobile text messaging works and you must be familiar with c/c++ programming. This solution is based on Ozeki SMS Gateway. It can be downloaded from our website. The goal is to make the process of creating your c/c++ SMS program with smpp as quick as possible. This document presents the tutorial steps and the necessary information to help you complete the c/c++ sms api integration efficiently. We provide a list of requirements and resources that you need to know, before you start this sms integration project.

What is c/c++ smpp?

C/C++ smpp is an sms api used by c/c++ developers to send and receive sms messages from their development environment and finished software products.

how to send text from c and c++ with smpp
Figure 1 - Send text message from c/c++ with smpp

Detailed instructions to send sms from c/c++ with smpp

To send sms from c/c++ with smpp:

  1. Open the Ozeki management console
  2. Setup an SMPP Client connection
  3. Create an SMS API user for your c/c++ api
  4. Navigate to 'Add new user/application...'
  5. Select http user
  6. Hit 'install'
  7. Setup an sms route from c/c++ to smpp
  8. Create the .cpp file based on the c/c++ SMPP sms example
  9. Send your first sms from your c/c++ program
  10. Check the logs to see if your texts were successfully sent

C/C++ requirements and useful resources

C and C++ are commonly used programming languages that can be used to efficiently add SMS support. This will give your applications and mobiles the ability to send and receive SMS messages. Here are the requirements to send and receive SMS using C and C++:

  • Visual Studio (optional)
  • Ozeki C/C++ sms example code
  • Existing SMS api account created in Ozeki SMS Gateway
  • Configured SMPP Client connection in Ozeki SMS gateway
  • Downloaded ozApi.dll

SMPP C/C++ example code

The following C/C++ sms api example source code is free to use. You can simply implement it into your project. You can modify the source code to use it for other projects or applications. In order to run the following example, you just need to copy-paste it into a blank project. Add the ozApi.dll to the linker and run it.

#include "../ozApi/ozApi.h"
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;

// dll description
HINSTANCE hDLL = NULL;

// This function unload ozApi.dll
void UnLoadOzekiApi()
{
        FreeLibrary((HMODULE)hDLL);
}

// This function load ozApi.dll
ozApi* LoadOzekiApi()
{
        HINSTANCE hDLL = NULL;
        SmsConnection conn;

        // Load ozApi.dll
        hDLL = LoadLibrary("ozApi.dll");

        if (hDLL != NULL)
        {
                conn = (SmsConnection)GetProcAddress((HMODULE)hDLL, "CreateSmsConnection");
            if (conn != NULL) return conn();
                UnLoadOzekiApi();
        }

        return NULL;
}


int main(int argc, char** argv)
{
        // Load ozApi dll and connect to it.
        ozApi* myConn = LoadOzekiApi();
        if (myConn == NULL)
        {
                // Error while connect to dll.
                cout << "Unable to load ozApi.dll" << endl;
                system("pause");
                return 0;
        }
        else
        {
                // Dll is loaded.
                cout << "Loaded" << endl;
        }

        // Connect to Ozeki NG SMS Gateway
        // on localhost (127.0.0.1) at port 9500.
        myConn->open("127.0.0.1", 9500);

        // Login with default username and password
        // (admin / abc123)
        if(myConn->login("admin", "abc123"))
        {
                // Send a test message to 0011111
                myConn->sendMessage("0011111", "Test Message.");
        }
        else
        {
                // If username/password is bad
                cout << "Bad usename or password" << endl;
        }


        // Closing connection.
        cout << "Closing connection..." << endl;
        myConn->close();

        // Unload ozApi.dll
        UnLoadOzekiApi();
        cout << "Done" << endl;

    return 0;
}

Conclusion

We did our very best to make it simple and to walk you through all the details as painlessly as possible. By following the steps above, you can create the solution in a short period of time. You have seen the advantages Ozeki SMS Gateway can bring. If you have already completed the steps I am sure, if you let your wife (or girlfriend) know, you will be rewarded. If you would like to find out more useful insights about the benefits of other smiliar solutions, please open ozeki-sms-gateway.com. I hope this page will be useful to all the readers.

More information