HOWTO: Creating an Action for a RuleLast reviewed: January 7, 1998Article ID: Q177210 |
The information in this article applies to:
SUMMARYUnderstanding the ACTIONS and ACTION structures make creating actions for rules much easier. This article describes both of these structures and provides a code example of a properly created ACTIONS and ACTION structure. The code provided is not complete. It assumes that you already have a handle to a MAPI session, a pointer to the message store, a pointer to the folder the rule is to be applied to, and that you will release the appropriate structures before exiting the function.
MORE INFORMATIONThe ACTIONS structure is a collection of ACTION structures. The ACTIONS structure also contains version information and the number of ACTION structures it contains. The ACTION structure contains the action type. The following is a list of some of the valid action types:
Steps to Create an Action for a RuleThe following steps and code show how to create an action for a rule.
Sample Code
// lpActs should defined before the main function. static LPACTIONS lpActs = NULL; HRESULT hr = NULL; hr = CreateAction() HRESULT CreateAction(void) { HRESULT hr = NULL; LPSTR lpszAction = NULL; hr = MAPIAllocateBuffer(sizeof(ACTIONS), (void**)&lpActs); if (FAILED(hr) || lpActs == 0) { MessageBox(NULL, "MAPIAllocateBuffer() for lpActs failed.",NULL,MB_OK); return 1; } memset(lpActs, 0, sizeof(ACTIONS)); lpActs->ulVersion = EDK_RULES_VERSION; lpActs->cActions = 1; lpActs->lpAction = 0; hr = MAPIAllocateMore(sizeof(ACTION), lpActs, (LPVOID*)&lpActs->lpAction); if (FAILED(hr) || lpActs->lpAction == 0) { MessageBox(NULL, "MAPIAllocateBuffer() for lpAct failed.",NULL,MB_OK); return 1; } memset(lpActs->lpAction, 0, sizeof(ACTION)); /* // Example of Reply string. hr = MAPIAllocateBuffer(sizeof("Reply \"Reply Text\""), (void**) &lpszAction); // Example of Forward string. hr = MAPIAllocateBuffer(sizeof("Forward \"<User Name>\""), (void**) &lpszAction); */ // Example of Move String. hr = MAPIAllocateBuffer(sizeof("Move Mailbox - <User Name> \\Top of Information Store\\Deleted Items"), (void**) &lpszAction); if (FAILED(hr)) { MessageBox(NULL,"Memory Allocation Failed",NULL,MB_OK); return 1; } // Reply: //wsprintf(lpszAction,"Reply \"Reply Text\""); // Forward: //wsprintf(lpszAction,"Forward \"<User Name>\""); // Move: wsprintf(lpszAction,"Move Mailbox - <User Name> \\Top of Information Store\\Deleted Items"); hr = HrStringToAction(lpSession, lpFolder, lpszAction, lpActs, &lpActs->lpAction[lpActs->cActions-1]); if (FAILED(hr)) { MessageBox(NULL,"Action Failed",NULL,MB_OK); return 1; } return 0; }In order to use this code, the following libraries and headers are required:
REFERENCESFor more information, please see the following topics in the Microsoft Developer Network Library (MSDN). These topics can be found in the Win32 Messaging Application Program Interface (MAPI) section of the Platform SDK.
Keywords : kbcode XGEN Version : WINDOWS:5.0 Platform : WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |