Creating Pocket Outlook Plug-ins

All of the Pocket Outlook applications (Calendar, Tasks, and Contacts) enable you to add your own menu items to their individual Tools menu. Adding a new menu item is as simple as creating a DLL that exports your function, and setting up the registry with information about the plug-in (see Figure 10.5). When the user selects your menu item, the Pocket Outlook application will load your DLL and call into the function that you have specified. Pocket Outlook will also pass information about the selected items to your function.

Figure 10.5. A Pocket Outlook plug-in


To add an additional menu item to a Pocket Outlook application, you need to add a new sub-key value for your menu option under the registry key:

 HKEY_LOCAL_MACHINE\Software\Microsoft\PimApps\PimExtension\   PIMAPP\AddIns 

Replace the PIMAPP constant with the name of the application to which you want to add a menu item. This can be set to Contacts, Tasks, or Calendar.

Table 10.25 describes the values that need to be configured for your new menu item.

Table 10.25. Pocket Outlook Plug-in Registry Settings






The full path and name of the DLL that contains your exported plug-in module



The text that will be displayed in the Tools menu

To implement your plug-in, you need to create a DLL that exports the CePimCommand() function, which has the following prototype:

 void CePimCommand(HWND hWnd, PIMTYPE ptData, UINT   uDataCount, HANDLE *rghData, void *pReserved); 

The first parameter that is passed to you is the window handle of the parent Pocket Outlook application. It is followed by ptData, which specifies the application that called into the function. This will be set to PT_CALENDAR, PT_TASKS, or PT_CONTACT.

The uDataCount and rghData parameters refer to the items that are currently selected in the calling Pocket Outlook application. A pointer to an array of Pocket Outlook object identifiers is passed to you in the rghData parameter, and the number of items in the array is specified by uDataCount.

Once you have a specific OID, you can use the IPOutlookApp::GetItemFromOid() method to get the interface for that item.

Let's look at some code for developing a Pocket Outlook plug-in that displays a calendar item. The registry for your new item would look like the following:

 // Registry settings [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PimApps\PimExtensions   \Calendar\AddIns\MyPlugin] "Menu"="My Outlook Plugin" "dll"="myplugin.dll" 

Finally, let's look at the actual code to display the subject of the selected appointment:

 #define INITGUID #include <windows.h> #include <pimstore.h> typedef enum tagPIMTYPE {    PT_CONTACT = 0,    PT_CALENDAR,    PT_TASKS } PIMTYPE; HINSTANCE hInstance = NULL; BOOL WINAPI DllMain(HANDLE hInstDll, DWORD dwReason, LPVOID   lpvReserved){    hInstance = (HINSTANCE)hInstDll;    return TRUE; } void CePimCommand(HWND hWnd, PIMTYPE ptData, UINT   uDataCount, HANDLE *rghData, void *pReserved) {    // Abort if not in the calendar    if(ptData != PT_CALENDAR)       return;    // Abort if no items are selected    if(uDataCount == 0)       MessageBox(hWnd, TEXT("Nothing selected!"), TEXT("My          Plugin"), MB_OK);    // Ok, let's get the first item    CEOID calItemOid = (CEOID)rghData[0];    // Start up and log into poom    HRESULT hr = S_OK;    IPOutlookApp *pOlApp = NULL;    if(FAILED(CoInitializeEx(NULL, 0))) {       MessageBox(hWnd, TEXT("Couldnt start COM"), TEXT("My          Plugin"), MB_OK);       return;    }    // Get a pointer to the IPOutlookApp interface    hr = CoCreateInstance(CLSID_Application, NULL,       CLSCTX_INPROC_SERVER, IID_IPOutlookApp, (LPVOID *)&pOlApp);    if(FAILED(hr)) {       MessageBox(hWnd, TEXT("Couldnt get the IPOutlookApp          Interface"), TEXT("My Plugin"), MB_OK);       return;    }    // Log into Pocket Outlook    hr = pOlApp->Logon((long)hWnd);    if(FAILED(hr)) {       MessageBox(hWnd, TEXT("Couldnt log into POOM"),          TEXT("My Plugin"), MB_OK);       return;    }    // Get the item that was passed in    IAppointment *pIAppoint = NULL;    hr = pOlApp->GetItemFromOid(calItemOid,       (IDispatch **)&pIAppoint);    if(FAILED(hr)) {       MessageBox(hWnd, TEXT("Couldnt get object"), TEXT("My          Plugin"), MB_OK);       pOlApp->Logoff();       pOlApp->Release();       return;    }    // Got it, now display it    BSTR bstrSubject;    pIAppoint->get_Subject(&bstrSubject);    MessageBox(hWnd, bstrSubject, TEXT("My Plugin"), MB_OK);    // Clean up    SysFreeString(bstrSubject);    pIAppoint->Release();    pOlApp->Logoff();    pOlApp->Release();    return; } 

Pocket PC Network Programming
Pocket PC Network Programming
ISBN: 0321133528
EAN: 2147483647
Year: 2005
Pages: 90 © 2008-2017.
If you may any questions please contact us: