char    threadID[128] = "N/A";; char    origName[128] = "N/A";; char    origAddress[128] = "N/A";;
char    threadID[128] = "N/A"; char    origName[128] = "N/A"; char    origAddress[128] = "N/A";
DoMAPISendMail(HWND hWnd){  ULONG (FAR PASCAL *lpfnMAPISendMail) (LHANDLE lhSession, ULONG ulUIParam,                   lpMapiMessage lpMessage, FLAGS flFlags, ULONG ulReserved);#ifdef WIN16		  (FARPROC&) lpfnMAPISendMail = GetProcAddress(m_hInstMapi, "MAPISENDMAIL"); #else  (FARPROC&) lpfnMAPISendMail = GetProcAddress(m_hInstMapi, "MAPISendMail"); #endif    if (!lpfnMAPISendMail)  {    ShowMessage(hWnd, "Unable to locate MAPI function.");    return;  }            FLAGS   flFlags = 0;  char    msg[512];  char    file1[_MAX_PATH] = "";  char    file2[_MAX_PATH] = "";  char    file3[_MAX_PATH] = "";  char    file4[_MAX_PATH] = "";  char    toAddr[128];  char    ccAddr[128];  char    bccAddr[128];  char    subject[128];  char    noteText[4096];  char    dateReceived[128] = "N/A";  char    threadID[128] = "N/A";;  char    origName[128] = "N/A";;  char    origAddress[128] = "N/A";;  GetDlgItemText(hWnd, ID_EDIT_TOADDRESS, toAddr, sizeof(toAddr));  GetDlgItemText(hWnd, ID_EDIT_CCADDRESS, ccAddr, sizeof(ccAddr));  GetDlgItemText(hWnd, ID_EDIT_BCCADDRESS, bccAddr, sizeof(bccAddr));  GetDlgItemText(hWnd, ID_EDIT_SUBJECT, subject, sizeof(subject));  GetDlgItemText(hWnd, ID_EDIT_NOTETEXT, noteText, sizeof(noteText));  // Do the one flag we support for this call...  if (BST_CHECKED == Button_GetCheck(GetDlgItem(hWnd, ID_CHECK_SHOWDIALOG)))  {    flFlags |= MAPI_DIALOG;  }  // Build the message to send off...  lpMapiMessage  msgPtr = (MapiMessage *)malloc(sizeof(MapiMessage));  if (msgPtr == NULL)  {    return;  }    memset(msgPtr, 0, sizeof(MapiMessage));   //  // At this point, we need to populate the structure of information  // we are passing in via the *lppMessage  //  // Set all of the general information first!  msgPtr->lpszSubject = strdup(subject);  msgPtr->lpszNoteText = strdup(noteText);  msgPtr->lpszDateReceived = strdup(dateReceived);  msgPtr->lpszConversationID = strdup(threadID);  msgPtr->flFlags = flFlags;  // Now deal with the recipients of this message  DWORD       realRecips = 0;  if (toAddr[0] != '\0')    ++realRecips;  if (ccAddr[0] != '\0')    ++realRecips;  if (bccAddr[0] != '\0')   ++realRecips;  msgPtr->lpRecips = (lpMapiRecipDesc) malloc((size_t) (sizeof(MapiRecipDesc) * realRecips));  if (!msgPtr->lpRecips)  {    FreeMAPIMessage(msgPtr);    return;  }  msgPtr->nRecipCount = realRecips;  memset(msgPtr->lpRecips, 0, (size_t) (sizeof(MapiRecipDesc) * msgPtr->nRecipCount));  DWORD       rCount = 0;  if (toAddr[0] != '\0')  {    msgPtr->lpRecips[rCount].lpszName = strdup(toAddr);    msgPtr->lpRecips[rCount].lpszAddress = strdup(toAddr);    msgPtr->lpRecips[rCount].ulRecipClass = MAPI_TO;    rCount++;  }  if (ccAddr[0] != '\0')  {    msgPtr->lpRecips[rCount].lpszName = strdup(ccAddr);    msgPtr->lpRecips[rCount].lpszAddress = strdup(ccAddr);    msgPtr->lpRecips[rCount].ulRecipClass = MAPI_CC;        rCount++;  }  if (bccAddr[0] != '\0')  {    msgPtr->lpRecips[rCount].lpszName = strdup(bccAddr);    msgPtr->lpRecips[rCount].lpszAddress = strdup(bccAddr);    msgPtr->lpRecips[rCount].ulRecipClass = MAPI_BCC;    rCount++;  }  // Now get the names of the files to attach...  GetDlgItemText(hWnd, ID_EDIT_ATTACH1, file1, sizeof(file1));  GetDlgItemText(hWnd, ID_EDIT_ATTACH2, file2, sizeof(file2));  GetDlgItemText(hWnd, ID_EDIT_ATTACH3, file3, sizeof(file3));  GetDlgItemText(hWnd, ID_EDIT_ATTACH4, file4, sizeof(file4));  DWORD       realFiles = 0;  if (file1[0] != '\0')    ++realFiles;  if (file2[0] != '\0')    ++realFiles;  if (file3[0] != '\0')    ++realFiles;  if (file4[0] != '\0')    ++realFiles;  // Now deal with the list of attachments! Since the nFileCount should be set  // correctly, this loop will automagically be correct  //  msgPtr->nFileCount = realFiles;  if (realFiles > 0)  {    msgPtr->lpFiles = (lpMapiFileDesc) malloc((size_t) (sizeof(MapiFileDesc) * realFiles));    if (!msgPtr->lpFiles)    {      FreeMAPIMessage(msgPtr);      return;    }    memset(msgPtr->lpFiles, 0, (size_t) (sizeof(MapiFileDesc) * msgPtr->nFileCount));  }  rCount = 0;  if (file1[0] != '\0')  {    msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file1);    msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file1);    ++rCount;  }  if (file2[0] != '\0')  {    msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file2);    msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file2);    ++rCount;  }  if (file3[0] != '\0')  {    msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file3);    msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file3);    ++rCount;  }  if (file4[0] != '\0')  {    msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file4);    msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file4);    ++rCount;  }  // Finally, make the call...  LONG  rc = (*lpfnMAPISendMail)           (mapiSession,            (ULONG) hWnd,            msgPtr,            flFlags,            0);  if (rc == SUCCESS_SUCCESS)  {    ShowMessage(hWnd, "Success with MAPISendMail");    SetFooter("MAPISendMail success");  }  else  {    wsprintf(msg, "FAILURE: Return code %d from MAPISendMail\nError=[%s]",                       rc, GetMAPIError(rc));    ShowMessage(hWnd, msg);    SetFooter("MAPISendMail failed");  }  // Now cleanup and move on...  FreeMAPIMessage(msgPtr);}