Description
Logs in and prints messages received.
// Bone sample program #1
#include "bone.h"
#include <stdio.h>
#include "windows.h"
// windows.h is required since Bone requires the program
// to have a Windows message loop (see below)
BONEHANDLE bhnd;
// callback_login is called if a login attempt was successful or returned
an error
void callback_login(BONEHANDLE bhnd, int errorcode)
{
// let send a text message to "testuser"
// the message pingpongs back to us if we are the one being logged
on as "testuser"
if (errorcode == 0)
bone_sendtext(bhnd, "testuser", "Welcome to the Bone Console
Sample");
else
{
printf("Bone logon failed with code %d.\n",
errorcode);
}
}
// callback_text is called on an incoming text message
void callback_text(BONEHANDLE bhnd, const char *origin, const char
*message)
{
// a text message was sent to us, just print it out on the screen
printf("Message from %s: %s\n", origin, message);
}
int main(int argc, char* argv[])
{
//Initialize the Bone SDK so we can use it
if(bone_init(BONEBUILD))
{
printf("Unable to initialize the Bone SDK.\n");
}
// lets handle login results and incoming text here
bone_setcallback(BONE_CALLBACK_LOGIN, callback_login);
bone_setcallback(BONE_CALLBACK_TEXT, callback_text);
bhnd = bone_create();
if (bhnd)
{
bone_login(bhnd, "testuser","pass");
}
else printf("Unable to create BONEHANDLE.\n");
// the Bone SDK was made for Windows programs, which usually
// have a windows message loop.
// Console applications usually do not need one, but for Bone,
// a message loop is required.
// This message loop is needed in console applications only.
// so here it comes:
{
MSG msg;
while (GetMessage(&msg, NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}