Posts Tagged ‘CAccExPreferences’

Reading an AIM SDK Preference via C++

Wednesday, January 14th, 2009

The AIM SDK (AIMcc) has an interface called IAccPreferences that is used for reading and writing preferences. Preferences are associated with a session so they can only be accessed once you have an IAccSession object.

It is up to clients to implement the actual data store behind these preferences by registering an object that implements either IAccPreferencesHook or IAccPreferencesHook2. You can find more information about these interfaces in technote 3 of the AIM SDK.

In this two-part series I will provide some sample code for reading preferences. This first post provides an ATL/C++ example and my next post will provide a JavaScript example.

In the process of making easy to use sample code, I will need to create some helper classes. These classes will be part of an evolving distribution called AccEx which I am hereby placing in the public domain. I will start by distributing these as source files only until I have more classes. AccEx distributions will be available here.

For this post, I created a helper class in AccEx called CAccExPreferences in order to make it easy to read and write preferences in C++. This class has overloaded methods to help you read a preference in various native formats like bool, int, float, etc. and one method to write a preference from a CComVariant.

So let’s use this thing. Like I said above, the IAccPreferences interface is implemented by AIMcc and associated with the IAccSession since they are (mostly) per-user preferences. Therefore, the only thing you need to initialize a CAccExPreferences object is an IAccSession pointer. The class will take care of acquiring the IAccPreferences interface for you. Here is a simple use-case that reads a real AIMcc preference.

// This sample source is public domain
#include <stdafx.h>
#include "AccExPreferences.h"
 
static WCHAR kDisclosePluginsToBuddyFeed[] = 
    OLESTR("aimcc.privacy.disclosePluginsToBuddyFeed");
 
HRESULT CanDisclosePluginsToBuddyFeed(IAccSession *pIAccSession)
{
    bool enabled;
    AccEx::CAccExPreferences prefs(pIAccSession);
 
    if ( SUCCEEDED( 
            prefs.GetPref(kDisclosePluginsToBuddyFeed, enabled) 
         ) && enabled )
    {
        // preference is enabled.
        return S_OK;
    }
    return S_FALSE;
}

Stay tuned for my next post where I will do the same using JavaScript.