ActiveXperts Twitter Toolkit Add Twitter capabilities to any Windows or .NET application

Quicklinks


How to use ActiveXperts Twitter Toolkit with Microsoft Visual C++

Twitter is a popular social networking service that enables its users to send and read messages called Tweets. Tweets are text-based posts of up to 140 characters. They are displayed on the author's profile page.

Twitter users can send and receive tweets through the Twitter website or through compatible applications. Applications that want to send or receive Tweets have the option of using Twitters HTTP based RESTfull API. The ActiveXperts Twitter Toolkit provides a user friendly wrapper around Twitters own HTTP based API.

The ActiveXperts Twitter API supports the following:

  • Post your Tweets on Twitter using your own software
  • Easy browsing through your own Tweets or the Tweets on any other time-line
  • Easy browsing through friends and followers
  • Integrated OAuth (Open Authorization) supports both both Client and Web use cases
  • Authenticate users in only two steps
  • Access all of the functions that are publicly available on the Twittter HTTP interface
  • Proved an interface to send custom, OAuth signed, requests to the Twitter HTTP interface

This tutorial describes how the Twitter Toolkit can be integrated in Microsoft Visual C++ projects.

Step 1: Download and install the ActiveXperts Twitter Toolkit

Download the Twitter Toolkit from the ActiveXperts web site and start the installation. The installation guides you through the installation process.  Download now »

Step 2: Create a new Visual C++ project

Launch 'Microsoft Visual C++' from the Start menu, and choose 'New' from the 'File Menu'. The 'New' dialog appears.

Select the type of project (for instance: 'Win32 Console Application'), enter a 'Project name' and select the 'Location':

Visual C++

(Click on the picture to enlarge)

Select the kind of project, for instance a 'Hello, world!' application and click 'Finish':

Visual C++

(Click on the picture to enlarge)

Step 3: Refer to the Twitter Toolkit Library and declare the objects

A new Project is created now.

Before you can use Twitter Toolkit, you need to refer to the Twitter Toolkit library. The actually reference files are shipped with the product and are located in the following directory:

C:\Program Files\ActiveXperts\Twitter Toolkit\Examples\Visual C++\Include

Copy all files in the above directory ('twitter-component.h' and 'twitter-component_i.c') to your project directory.

On top of your code, declare the following object:

ITwitter	*pTwitter = NULL;

Step 4: Create the objects

Since the ActiveXperts Twitter Toolkit is a COM object, you must initialize the COM library before they can call COM library functions (e.g. Twitter Toolkit functions):

CoInitialize(NULL);

Create the object in the following way:

CoCreateInstance(CLSID_Twitter, NULL, CLSCTX_INPROC_SERVER, IID_ITwitter, (void**) &pTwitter);

Step 5: Tweet a message

The following code shows how to tweet a message using Microsoft Visual C++

#include <windows.h>
#include <stdio.h>
#include <comdef.h>
#include <atlbase.h>
#include <iostream.h>


#include "..\..\include\twitter-component.h"
#include "..\..\include\twitter-component_i.c"

int main(int argc, char* argv[])
{
  ITwitter			*pTwitter = NULL;
  HRESULT				hr;
  LONG				lLastError			= -1L;
  BSTR				bstrTweetID			= NULL;

  // Initialize COM  
  CoInitialize(NULL);

  // Create objects
  hr = CoCreateInstance(CLSID_Twitter, NULL, CLSCTX_INPROC_SERVER, 
                                    IID_ITwitter, (void**) &pTwitter);
  if( ! SUCCEEDED( hr ) )
  {
    printf( "Unable to create ACTIVEXPERTS:TWITTER object\n" );
    goto _EndMain;
  }
  pTwitter->LoadConsumerKey( _bstr_t( "c:\\consumer.key" ) );
  pTwitter->get_LastError( &lLastError );
  printf( "LoadConsumerKey, result: %ld\n", lLastError );
  if( lLastError != 0L )
    goto _EndMain;

  pTwitter->LoadAccessKey( _bstr_t( "c:\\access.key" ) );
  pTwitter->get_LastError( &lLastError );
  printf( "LoadAccessKey, result: %ld\n", lLastError );
  if( lLastError != 0L )
    goto _EndMain;

  pTwitter->Tweet( _bstr_t( "I'm tweeting using ActiveXperts !" ), &bstrTweetID );
  pTwitter->get_LastError( &lLastError );
  printf( "Tweet, result: %ld\n", lLastError );

_EndMain:

  if( pTwitter != NULL ) 
  {
    pTwitter->Release();
    pTwitter = NULL;
  }

  if( bstrTweetID != NULL )
  {
    SysFreeString( bstrTweetID );
    bstrTweetID = NULL;
  }

  CoUninitialize();

  return 0;
}

Samples

There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/twitter-component


Support Operating Systems

The Twitter Toolkit can be used by any of the following operating systems:

  • Windows XP, x86 (32-bit) and x64 (64-bit)
  • Windows 2003, x86 (32-bit) and x64 (64-bit)
  • Windows 2008, x86 (32-bit) and x64 (64-bit)
  • Windows Vista, x86 (32-bit) and x64 (64-bit)
  • Windows 7, x86 (32-bit) and x64 (64-bit)