C++ COM

COM is something that MS don’t seem to be able to demonstrate simply for people that don’t know what they’re doing and don’t care.

Here’s some code that imports KDX.SecureApi and runs authorize() and downloadMonitor() from the Kontiki suite which registers itself correctly as a COM control on install.

#include "stdafx.h"
#import "progid:KDX.SecureApi" named_guids no_namespace

int _tmain(int argc, _TCHAR* argv[])
{
char gAuthToken[] = "iplayer_live | www.bbc.co.uk, *.iplayer.bbc.co.uk | urn:kid:bbc_iplayer_live:";
char gAuthSignature[] = "o+JtR5xUaVS1hzkjS/J7HpqDhcFwjEKP+0Yq0OGA51Ap5Lbg4PU29BhNQfe8gdlJWr2StkIG5nweF6Oz2lDDDtZ3Fz/jDYUbQ/vq3mZMHW8axwGeb5NWLJ3QC553j11dNtc+OjU1icyi00kH/dKIOmRRtvWygIGnHzs1hWJD8sI=";
HRESULT hr = ::CoInitialize(NULL);

CComPtr spSecureApi;
hr = spSecureApi.CoCreateInstance( CLSID_KDXSecureApi, NULL, CLSCTX_LOCAL_SERVER );

if (SUCCEEDED(hr))
{
hr = spSecureApi->authorize(gAuthToken, gAuthSignature, VARIANT_FALSE);
hr = spSecureApi->downloadMonitor(VARIANT_TRUE);
}
if (FAILED(hr))
{
LPVOID MsgBuffer;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,NULL,hr,0,(LPTSTR) &MsgBuffer,0,NULL );
string message = "An error occurred: ";
message += (const char *)MsgBuffer;
MessageBox(0,message.c_str(),"Raw Dispatch Interface Error",MB_OK);
}
return 0;
}

Comments

    Leave a comment