This is what I managed to do with regards with interfacing with Skype - I didn't bother with doing too much, as there is no real use for it.
// DBSkype.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "DBSkype.h"
#include "globstruct.h"
#include "skype.hpp"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
GlobStruct *g_pGlob=NULL;
UINT uiGlobal_MsgID_SkypeControlAPIAttach;
UINT uiGlobal_MsgID_SkypeControlAPIDiscover;
HINSTANCE hInit_ProcessHandle;
HWND hInit_MainWindowHandle;
HWND hGlobal_SkypeAPIWindowHandle=NULL;
UINT lResult;
LRESULT APIENTRY WindowProc(HWND hWindow, UINT uiMessage, WPARAM uiParam, LPARAM ulParam);
#define SSTATUS_SKYPENOTAVAILIABLE 0
#define SSTATUS_ACCEPTED 1
#define SSTATUS_FAILED 2
#define SSTATUS_AWAITINGAPPROVAL 3
#define SSTAUS_APIAVAILIABLE 4
enum {
SKYPECONTROLAPI_ATTACH_SUCCESS=0, // Client is successfully attached and API window handle can be found in wParam parameter
SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION=1, // Skype has acknowledged connection request and is waiting for confirmation from the user.
// The client is not yet attached and should wait for SKYPECONTROLAPI_ATTACH_SUCCESS message
SKYPECONTROLAPI_ATTACH_REFUSED=2, // User has explicitly denied access to client
SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE=3, // API is not available at the moment. For example, this happens when no user is currently logged in.
// Client should wait for SKYPECONTROLAPI_ATTACH_API_AVAILABLE broadcast before making any further
// connection attempts.
SKYPECONTROLAPI_ATTACH_API_AVAILABLE=0x8001
};
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
// CDBSkypeApp
BEGIN_MESSAGE_MAP(CDBSkypeApp, CWinApp)
END_MESSAGE_MAP()
// CDBSkypeApp construction
CDBSkypeApp::CDBSkypeApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CDBSkypeApp object
CDBSkypeApp theApp;
// CDBSkypeApp initialization
void Constructor(void)
{
WNDCLASS oWindowClass;
char acInit_WindowClassName[128];
lResult=SSTATUS_SKYPENOTAVAILIABLE;
uiGlobal_MsgID_SkypeControlAPIAttach=RegisterWindowMessage("SkypeControlAPIAttach");
uiGlobal_MsgID_SkypeControlAPIDiscover=RegisterWindowMessage("SkypeControlAPIDiscover");
strcpy( acInit_WindowClassName, "Skype-API-Test-");
oWindowClass.style=CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
oWindowClass.lpfnWndProc=(WNDPROC)&WindowProc;
oWindowClass.cbClsExtra=0;
oWindowClass.cbWndExtra=0;
oWindowClass.hInstance=hInit_ProcessHandle;
oWindowClass.hIcon=NULL;
oWindowClass.hCursor=NULL;
oWindowClass.hbrBackground=NULL;
oWindowClass.lpszMenuName=NULL;
oWindowClass.lpszClassName=acInit_WindowClassName;
RegisterClass(&oWindowClass);
hInit_MainWindowHandle=CreateWindowEx( WS_EX_APPWINDOW|WS_EX_WINDOWEDGE,
acInit_WindowClassName, "", WS_BORDER|WS_SYSMENU|WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, 128, 128, NULL, 0, hInit_ProcessHandle, 0);
}
void Destructor(void)
{
}
void ReceiveCoreDataPtr ( LPVOID pCore )
{
// Get Core Data Pointer here
g_pGlob = (GlobStruct*)pCore;
}
BOOL CDBSkypeApp::InitInstance()
{
CWinApp::InitInstance();
return TRUE;
}
void Global_MessageLoop(void)
{
MSG oMessage;
if(GetMessage( &oMessage, hInit_MainWindowHandle, 0, 0)!=FALSE)
{
TranslateMessage(&oMessage);
DispatchMessage(&oMessage);
}
}
DWORD DBSkype_Connect(void)
{
if (uiGlobal_MsgID_SkypeControlAPIAttach==NULL ||
uiGlobal_MsgID_SkypeControlAPIDiscover==NULL)
{
return (SSTATUS_SKYPENOTAVAILIABLE);
}
if( SendMessage( HWND_BROADCAST, uiGlobal_MsgID_SkypeControlAPIDiscover,
(WPARAM) hInit_MainWindowHandle, 0)!=0 )
{
if (SendMessage( HWND_BROADCAST, uiGlobal_MsgID_SkypeControlAPIDiscover,
(WPARAM) hInit_MainWindowHandle, 0)!=0)
{
while (lResult!=SSTATUS_ACCEPTED &&
lResult!=SSTATUS_FAILED)
{
Global_MessageLoop();
}
return (lResult);
}
}
return (SSTATUS_SKYPENOTAVAILIABLE);
}
void DBSkype_SetUserStatus(LPSTR status)
{
if( SendMessage( HWND_BROADCAST, uiGlobal_MsgID_SkypeControlAPIDiscover,
(WPARAM) hInit_MainWindowHandle, 0)!=0 &&
hGlobal_SkypeAPIWindowHandle!=NULL )
{
COPYDATASTRUCT oCopyData;
char message[1024];
ZeroMemory(&message,sizeof(message));
sprintf(message,"SET USERSTATUS %s",status);
// send command to skype
oCopyData.dwData=0;
oCopyData.lpData=message;
oCopyData.cbData=strlen(message)+1;
if( oCopyData.cbData!=1 )
{
if( SendMessage( hGlobal_SkypeAPIWindowHandle, WM_COPYDATA, (WPARAM)hInit_MainWindowHandle, (LPARAM)&oCopyData)==FALSE )
{
hGlobal_SkypeAPIWindowHandle=NULL;
//printf("!!! Disconnected\n");
}
}
}
}
LRESULT APIENTRY WindowProc(HWND hWindow, UINT uiMessage, WPARAM uiParam, LPARAM ulParam)
{
LRESULT lReturnCode;
bool fIssueDefProc;
lReturnCode=0;
fIssueDefProc=false;
switch(uiMessage) {
case WM_DESTROY:
hInit_MainWindowHandle=NULL;
PostQuitMessage(0);
break;
case WM_COPYDATA:
if( hGlobal_SkypeAPIWindowHandle==(HWND)uiParam )
{
PCOPYDATASTRUCT poCopyData=(PCOPYDATASTRUCT)ulParam;
printf( "Message from Skype(%u): %.*s\n", poCopyData->dwData, poCopyData->cbData, poCopyData->lpData);
lReturnCode=1;
}
break;
default:
if( uiMessage==uiGlobal_MsgID_SkypeControlAPIAttach )
{
switch(ulParam)
{
case SKYPECONTROLAPI_ATTACH_SUCCESS:
//printf("!!! Connected; to terminate issue #disconnect\n");
lResult=SSTATUS_ACCEPTED;
hGlobal_SkypeAPIWindowHandle=(HWND)uiParam;
break;
case SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION:
//printf("!!! Pending authorization\n");
lResult=SSTATUS_AWAITINGAPPROVAL;
break;
case SKYPECONTROLAPI_ATTACH_REFUSED:
lResult=SSTATUS_FAILED;
break;
case SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE:
//printf("!!! Skype API not available\n");
break;
case SKYPECONTROLAPI_ATTACH_API_AVAILABLE:
//printf("!!! Try connect now (API available); issue #connect\n");
break;
}
lReturnCode=1;
break;
}
fIssueDefProc=true;
break;
};
if( fIssueDefProc )
{
lReturnCode=DefWindowProc( hWindow, uiMessage, uiParam, ulParam);
}
// if( fGlobal_DumpWindowsMessages )
{
//printf( "WindowProc: hWindow=0x%08X, MainWindow=0x%08X, Message=%5u, WParam=0x%08X, LParam=0x%08X; Return=%ld%s\n",
// hWindow, hInit_MainWindowHandle, uiMessage, uiParam, ulParam, lReturnCode, fIssueDefProc? " (default)":"");
}
return(lReturnCode);
}
Walk softly... and carry a big gun...