HOWTO: Cause EFD Forms to Display Named Props Set from Ext. MAPI

ID: Q178319

The information in this article applies to:

SUMMARY

A Form created by the Electronic Forms Designer (EFD) creates properties on its messages. It also sets a property that the developer of the form does not know about. This property is often called MS_EXCHANGE_01. As long as the message is being composed and sent by the form there is no problem because the form knows about this property and sets it appropriately.

However, when sending a message from Extended MAPI, you must include code to set this property in order for other custom properties in your message to be read into their fields on the form.

MORE INFORMATION

The following code works for one named property. You can modify it for more then one property. This code calls separate functions to set the standard properties on the message and to set the recipients of the message. You may substitute your own functions for these.

The key to making this work is the MS_EXCHANGE_01 property. If you look at the VB source to your Form you will find that it checks for this property to be set on the message. If this property is not set, your other properties will not be read into their fields.

This code does not free all its memory or release its objects. You should of course add this as would be appropriate to your application:

    HRESULT SendMapiMessage()
    {
       HRESULT            hr;
       LPMESSAGE          lpMsg = NULL;
       MAPINAMEID         NamedID;
       LPMAPINAMEID       lpNmid = &NamedID;
       LPMAPIFORMINFO     lpFormInfo = NULL;
       LPMAPIFORMMGR      lpMgr = NULL;
       SPropValue         pProp;
       LPSPropTagArray    lpNamedPropTags = NULL;
       SMAPIFormPropArray *lpFrmPropAry =NULL;

       // Create a new message
       hr=lpFolder->CreateMessage(NULL,MAPI_DEFERRED_ERRORS,&lpMsg);
       if(FAILED(hr)) goto oops;

       // Open Forms Manager
       hr=MAPIOpenFormMgr(poSession,&lpMgr);
       if(FAILED(hr)) goto oops;

       // Get the Forms Info object
       hr=lpMgr->ResolveMessageClass("IPM.NOTE.MyNote",
                      MAPIFORM_EXACTMATCH,lpFolder,&lpFormInfo);
       if(FAILED(hr)) goto oops;

       // Get all the published properties of the form
       hr = lpFormInfo->CalcFormPropSet(0,&lpFrmPropAry );
       if (FAILED(hr)) goto oops;

       // Set First Property for demonstration purposes
       // You could set all the properties here if you wished
       // by using each element in the aFormProp array
       NamedID = lpFrmPropAry ->aFormProp[0].nmid;

       // Get Tags for these properties
       hr = lpMsg->GetIDsFromNames(1, &lpNmid, MAPI_CREATE,
                                   &lpNamedPropTags);
       if(hr) goto oops;

       // Create a typed property tag
       pProp.ulPropTag = PROP_TAG(PT_STRING8,
                   PROP_ID(lpNamedPropTags->aulPropTag[0]));
       pProp.dwAlignPad = 0L;
       pProp.Value.lpszA = "Your string here";

       // Set the property
       hr = HrSetOneProp(lpMsg, &pProp);

       // Set EFD property to allow EFD to read and set fields.
       // You should check your VB code to ensure that this is
       // the correct name of the field in your project
       NamedID.lpguid = (LPGUID) &PS_PUBLIC_STRINGS;
       NamedID.ulKind = MNID_STRING;
       NamedID.Kind.lpwstrName = L"MS_EXCHANGE_01";

       // Once again, get the ID
       hr = lpMsg->GetIDsFromNames(1, &lpNmid , MAPI_CREATE,
                                   &lpNamedPropTags);
       if(hr) goto oops;

       // Once again create a typed property tag
       pProp.ulPropTag = PROP_TAG(PT_BOOLEAN,
                   PROP_ID(lpNamedPropTags->aulPropTag[0]));
       pProp.dwAlignPad = 0L;
       pProp.Value.b    = 1;

       // And once again set the property
       // Normally you would want to use one call to SetProps
       // with an array of propeties to set
       hr = HrSetOneProp(lpMsg, &pProp);

       // Set Message Class - this could be set with other props
       // Setting here for illustration purposes
       pProp.ulPropTag = PR_MESSAGE_CLASS;
       pProp.dwAlignPad = 0L;
       pProp.Value.lpszA = "IPM.NOTE.MyNote";

       hr = HrSetOneProp(lpMsg, &pProp);
       if (hr) goto oops;

       // Here you would set all other outgoing Message props
       hr = SetOutgoingProps(lpMsg);
       if (hr) goto oops;

       // Here you would set the recipients of your message
       hr = SetRecips(lpMsg);
       if (hr) goto oops;

       // Finally, sumbit the message
       hr = lpMsg->SubmitMessage(0);
       if (hr) goto oops;

    oops:
       // Normally you would free up your memory and
       // Release your objects

       return S_OK;
    }

Additional query words: Form forms EFD designer exchange display named property
Keywords          : kbcode kbMsg kbMAPI100 MAPIFORM 
Version           : WINDOWS:1.0,5.0
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: January 10, 1998