You are here:
ActiveXperts.com > Twitter Toolkit > How to Use ActiveXperts Twitter Toolkit > Visual C++
Quicklinks
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:
This tutorial describes how the Twitter Toolkit can be integrated in Microsoft Visual C++ projects.
Download the Twitter Toolkit from the ActiveXperts web site and start the installation. The installation guides you through the installation process. Download now »
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':
(Click on the picture to enlarge)
Select the kind of project, for instance a 'Hello, world!' application and click 'Finish':
(Click on the picture to enlarge)
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;
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);
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;
}
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
The Twitter Toolkit can be used by any of the following operating systems: