Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1 KiB

  1. #define STRICT
  2. #define UNICODE
  3. #include <windows.h>
  4. #include <shlwapi.h>
  5. #include <shellapi.h>
  6. #include <stdio.h>
  7. #define IID_PPV_ARG(IType, ppType) IID_##IType, reinterpret_cast<void**>(static_cast<IType**>(ppType))
  8. HRESULT CoUnmarshalFromCmdLine(LPCTSTR pszCmdLine, REFIID riid, void **ppv)
  9. {
  10. HRESULT hr = E_FAIL;
  11. *ppv = NULL;
  12. pszCmdLine = StrStr(pszCmdLine, TEXT("/DataObject:"));
  13. if (pszCmdLine)
  14. {
  15. pszCmdLine += lstrlen(TEXT("/DataObject:"));
  16. char buf[255]; // big enough for standard marshall buffer (which is 68 bytes)
  17. for (ULONG cb = 0; *pszCmdLine && (cb < sizeof(buf)); cb++)
  18. {
  19. buf[cb] = (*pszCmdLine - 'A') + ((*(pszCmdLine + 1) - 'A') << 4);
  20. if (*(pszCmdLine + 1))
  21. pszCmdLine += 2;
  22. else
  23. break; // odd # of chars in cmd line, error
  24. }
  25. // _asm { int 3 };
  26. if (cb < sizeof(buf))
  27. {
  28. IStream *pstm;
  29. hr = CreateStreamOnHGlobal(NULL, TRUE, &pstm);
  30. if (SUCCEEDED(hr))
  31. {
  32. // fill the marshall stream
  33. const LARGE_INTEGER li = {0, 0};
  34. pstm->Write(buf, cb, NULL);
  35. // move back to start of stream
  36. pstm->Seek(li, STREAM_SEEK_SET, NULL);
  37. hr = CoUnmarshalInterface(pstm, riid, ppv);
  38. pstm->Release();
  39. }
  40. }
  41. }
  42. return hr;
  43. }
  44. void __cdecl main(void)
  45. {
  46. CoInitializeEx(NULL, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
  47. IDataObject *pdtobj;
  48. if (SUCCEEDED(CoUnmarshalFromCmdLine(GetCommandLine(), IID_PPV_ARG(IDataObject, &pdtobj))))
  49. {
  50. FORMATETC fmte = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  51. STGMEDIUM medium;
  52. if (SUCCEEDED(pdtobj->GetData(&fmte, &medium)))
  53. {
  54. TCHAR szPath[MAX_PATH];
  55. for (int i = 0; DragQueryFile((HDROP)medium.hGlobal, i, szPath, MAX_PATH); i++)
  56. {
  57. MessageBox(NULL, szPath, TEXT("File Name"), MB_OK);
  58. }
  59. ReleaseStgMedium(&medium);
  60. }
  61. pdtobj->Release();
  62. }
  63. CoUninitialize();
  64. }