Open AIM SDK Custom Session C++ Sample
I just released a sample written in C++ that demonstrates the custom session feature in the Open AIM SDK 1.8.2. This code works in both Windows and Linux (tested on Ubuntu and CentOS). This sample is called acccssample, and you can download the source code here. The source code is cross platform, you can choose to build it in Windows using acccsample.vcproj, or use Makefile with g++ under Linux. This sample basically signs on and then allows the user to initiate the Custom Session as follows:
Usage:
acccssample.exe screenname password initiateflag where initiateflag = true or omit parameter.
You can run two instances of this app one to initiate a custom session and one which auto accepts the custom session to test this.
On the initiating side, when you see the below prompt, initiate a custom session with a buddy who is set to receive the custom session:
Enter c:s screenname to initiate a custom session with a buddy
Here are some code snips with some explanation:
// First, assert capability, which is a GUID of your choice that both the initiator and the recipient recognize
// You can do this as soon as your client goes online.
void OnStateChange(IAccSession* piSession, AccSessionState state, AccResult hr)
{
if (state == AccSessionState_Online)
{
HRESULT hr = piSession->AddCapabilities(CAccVariant(kCSCapability));
printf(“AddCapabilities, hr=%08X\n”, hr);
}
}
// start a custom session with the buddy
void StartCustomSession(xp_str buddy)
{
// for demo purposes we only support one session at a time
if (m_customSess == NULL)
{
printf(“Start Custom Session”);
CAccVariant val = 0;
val.vt = VT_INT;
val.intVal = 0;
const CAccBstr uuid_CAccBstr(“{39BB91C6-5134-4662-AFB3-188D42FD95AC}”);
xp_str uuid1(uuid_CAccBstr);
HRESULT hr = m_sp->CreateCustomSession(uuid1, &m_customSess);
m_customSess->put_Property(AccCustomSessionProp_Mode, val);
m_customSess->Invite(buddy, OLESTR(“Join me in this custom session”), &m_transid);
}
else
printf(“Custom Session already exists…”);
}
// Accept the Custom Session at the receiving end.
void OnSecondarySessionStateChange(IAccSession* piSession, IAccSecondarySession* piSecSession, AccSecondarySessionState state, AccResult hr)
{
// always accept incoming custom sessions
if (state == AccSecondarySessionState_ReceivedProposal)
{
CAccVariant v;
piSecSession->get_Property(AccSecondarySessionProp_RemoteUserName, &v);
AccSecondarySessionServiceId id;
piSecSession->get_ServiceId(&id);
CAccBstr x = CAccBstr(v.bstrVal);
char tmp[255];
x.GetUtf8(tmp, 255);
printf(“{%s} has sent you a custom session proposal\n”, tmp);
printf(“We are auto accepting the proposal for testing purposes…\n”);
piSecSession->Accept();
}
}
// send a test message to the buddy
void SendCustomMessage(xp_kstr msg)
{
// since this session is a message only session
// we can just send an IM.
CAccPtr
HRESULT hr = m_sp->CreateIm(msg, OLESTR(“text/plain”), &im);
m_customSess->SendData(NULL, 0, im);
}

Thanks for sharing the custom session feature in the Open AIM SDK 1.8.2.