Click here to Skip to main content
Click here to Skip to main content

SendTo mail recipient

By , 31 Mar 2003
 
sendtomail_src.zip
sendtomail_srccode.zip
SendMail.dsp
SendMail.dsw
static const IID CLSID_SendMail = { 0x9E56BE60, 0xC50F, 0x11CF, 
   { 0x9A, 0x2C, 0x00, 0xA0, 0xC9, 0x0A, 0x90, 0xCE } 
};

  ::OpenClipboard(NULL);

  // 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 
  ::GlobalUnlock(hglbCopy); 

  ::SetClipboardData(CF_HDROP, hglbCopy);

  ::CloseClipboard();


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

  if (!pDataObject)
  {
    ::CloseClipboard();
    return FALSE;
  }


  ::CoInitialize(NULL);

  IDropTarget *pDropTarget = NULL;

  // create an instance, and mimic drag-and-drop
  hr = CoCreateInstance( CLSID_SendMail, 
                         NULL, CLSCTX_ALL,
                         IID_IDropTarget, 
                         (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);

    ::Sleep(6*1000);

    pDropTarget->Release();
  }

  ::CoUninitialize();

By viewing downloads associated with this article you agree to the Terms of use 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.

License

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

Stephane Rodriguez.
France France
Member
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.
 

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