Click here to Skip to main content
13,093,097 members (65,665 online)
Click here to Skip to main content


43 bookmarked
Posted 21 Mar 2003

SendTo mail recipient

, 31 Mar 2003
Programmatically use the SendTo mail recipient shortcut
static const IID CLSID_SendMail = { 0x9E56BE60, 0xC50F, 0x11CF, 
   { 0x9A, 0x2C, 0x00, 0xA0, 0xC9, 0x0A, 0x90, 0xCE } 


  // let's send c:\346.jpg and c:\readme.doc by email
  LPTSTR szFile = "c:\\346.jpg\0c:\\readme.doc";
  int cch = _tcslen(szFile);

  HGLOBAL hglbCopy = ::GlobalAlloc(GMEM_MOVEABLE, 
                       sizeof(DROPFILES) + (cch + 2) * sizeof(TCHAR)); 
  LPDROPFILES pDropFiles = (LPDROPFILES) ::GlobalLock(hglbCopy);
  pDropFiles->pFiles = sizeof(DROPFILES);
  pDropFiles->pt.x = pDropFiles->pt.y = 0;
  pDropFiles->fNC = TRUE;
  pDropFiles->fWide = FALSE; // ANSI charset
  LPTSTR lptstrCopy = (LPTSTR) pDropFiles;
  lptstrCopy += pDropFiles->pFiles;
  memcpy(lptstrCopy, szFile, cch * sizeof(TCHAR)); 
  lptstrCopy[cch] = (TCHAR) '\0';    // null character 
  lptstrCopy[cch+1] = (TCHAR) '\0';    // null character 

  ::SetClipboardData(CF_HDROP, hglbCopy);


  // get an IDataObject from this code
  HRESULT hr = ::OleGetClipboard(&pDataObject);

  if (!pDataObject)
    return FALSE;


  IDropTarget *pDropTarget = NULL;

  // create an instance, and mimic drag-and-drop
  hr = CoCreateInstance( CLSID_SendMail, 
                         NULL, CLSCTX_ALL,
                         (void **)&pDropTarget);
  if (SUCCEEDED(hr))
    POINTL pt = {0,0};
    DWORD dwEffect = 0;
    pDropTarget->DragEnter(pDataObject, MK_LBUTTON, pt, &dwEffect);
    pDropTarget->Drop(pDataObject, MK_LBUTTON, pt, &dwEffect);




By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Addicted to reverse engineering. At work, I am developing business intelligence software in a team of smart people (independent software vendor).

Need a fast Excel generation component? Try xlsgen.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 1 Apr 2003
Article Copyright 2003 by Stephane Rodriguez.
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid