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.

196 lines
4.5 KiB

  1. //
  2. // Copyright 2001 - Microsoft Corporation
  3. //
  4. // Created By:
  5. // Geoff Pease (GPease) 23-JAN-2001
  6. //
  7. // Maintained By:
  8. // Geoff Pease (GPease) 23-JAN-2001
  9. //
  10. #include "pch.h"
  11. #include "shutils.h"
  12. #pragma hdrstop
  13. //
  14. // Borrowed so we can link to STOCK.LIB
  15. //
  16. #define SZ_DEBUGINI "ccshell.ini"
  17. #define SZ_DEBUGSECTION "DOCPROP3"
  18. #define SZ_MODULE "DOCPROP3"
  19. #ifdef DEBUG
  20. #define DECLARE_DEBUG
  21. #endif
  22. #ifdef DECLARE_DEBUG
  23. // (These are deliberately CHAR)
  24. EXTERN_C const CHAR c_szCcshellIniFile[] = SZ_DEBUGINI;
  25. EXTERN_C const CHAR c_szCcshellIniSecDebug[] = SZ_DEBUGSECTION;
  26. EXTERN_C const WCHAR c_wszTrace[] = L"t " TEXTW(SZ_MODULE) L" ";
  27. EXTERN_C const WCHAR c_wszErrorDbg[] = L"err " TEXTW(SZ_MODULE) L" ";
  28. EXTERN_C const WCHAR c_wszWarningDbg[] = L"wn " TEXTW(SZ_MODULE) L" ";
  29. EXTERN_C const WCHAR c_wszAssertMsg[] = TEXTW(SZ_MODULE) L" Assert: ";
  30. EXTERN_C const WCHAR c_wszAssertFailed[] = TEXTW(SZ_MODULE) L" Assert %ls, line %d: (%ls)\r\n";
  31. EXTERN_C const WCHAR c_wszRip[] = TEXTW(SZ_MODULE) L" RIP in %s at %s, line %d: (%s)\r\n";
  32. EXTERN_C const WCHAR c_wszRipNoFn[] = TEXTW(SZ_MODULE) L" RIP at %s, line %d: (%s)\r\n";
  33. // (These are deliberately CHAR)
  34. EXTERN_C const CHAR c_szTrace[] = "t " SZ_MODULE " ";
  35. EXTERN_C const CHAR c_szErrorDbg[] = "err " SZ_MODULE " ";
  36. EXTERN_C const CHAR c_szWarningDbg[] = "wn " SZ_MODULE " ";
  37. EXTERN_C const CHAR c_szAssertMsg[] = SZ_MODULE " Assert: ";
  38. EXTERN_C const CHAR c_szAssertFailed[] = SZ_MODULE " Assert %s, line %d: (%s)\r\n";
  39. EXTERN_C const CHAR c_szRip[] = SZ_MODULE " RIP in %s at %s, line %d: (%s)\r\n";
  40. EXTERN_C const CHAR c_szRipNoFn[] = SZ_MODULE " RIP at %s, line %d: (%s)\r\n";
  41. EXTERN_C const CHAR c_szRipMsg[] = SZ_MODULE " RIP: ";
  42. #endif // DECLARE_DEBUG && DEBUG
  43. #if defined(DECLARE_DEBUG) && defined(PRODUCT_PROF)
  44. EXTERN_C const CHAR c_szCcshellIniFile[] = SZ_DEBUGINI;
  45. EXTERN_C const CHAR c_szCcshellIniSecDebug[] = SZ_DEBUGSECTION;
  46. #endif
  47. //
  48. // Use TraceFree( ) to free the handle returned here
  49. //
  50. // Return Values:
  51. // S_OK
  52. // Successfully extracted and copied the HIDA.
  53. //
  54. // E_OUTOFMEMORY
  55. // Failed to copy the HIDA.
  56. //
  57. // other HRESULTs
  58. //
  59. HRESULT
  60. DataObj_CopyHIDA(
  61. IDataObject * pdtobjIn
  62. , CIDA ** ppidaOut
  63. )
  64. {
  65. TraceFunc( "" );
  66. HRESULT hr;
  67. STGMEDIUM medium;
  68. static CLIPFORMAT g_cfHIDA = 0;
  69. FORMATETC fmte = { 0, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  70. // Check parameters
  71. Assert( NULL != pdtobjIn );
  72. Assert( NULL != ppidaOut );
  73. // Clear out parameter
  74. *ppidaOut = NULL;
  75. //
  76. // Register clip format if not already done.
  77. //
  78. if ( 0 == g_cfHIDA )
  79. {
  80. g_cfHIDA = (CLIPFORMAT) RegisterClipboardFormat( CFSTR_SHELLIDLIST );
  81. }
  82. fmte.cfFormat = g_cfHIDA;
  83. //
  84. // Retrieve HIDA
  85. //
  86. hr = THR( pdtobjIn->GetData( &fmte, &medium ) );
  87. if ( SUCCEEDED( hr ) )
  88. {
  89. SIZE_T sizet = GlobalSize( medium.hGlobal );
  90. if ( (~((DWORD) 0)) > sizet )
  91. {
  92. DWORD cb = (DWORD) sizet;
  93. CIDA * pida = (CIDA *) TraceAlloc( 0, cb );
  94. if ( NULL != pida )
  95. {
  96. void * pv = GlobalLock( medium.hGlobal );
  97. CopyMemory( pida, pv, cb );
  98. GlobalUnlock( medium.hGlobal );
  99. *ppidaOut = pida;
  100. }
  101. else
  102. {
  103. hr = E_OUTOFMEMORY;
  104. }
  105. }
  106. else
  107. {
  108. hr = E_OUTOFMEMORY;
  109. }
  110. ReleaseStgMedium( &medium );
  111. }
  112. HRETURN( hr );
  113. }
  114. //
  115. //
  116. //
  117. HRESULT
  118. BindToObjectWithMode(
  119. LPCITEMIDLIST pidlIn
  120. , DWORD grfModeIn
  121. , REFIID riidIn
  122. , void ** ppvIn
  123. )
  124. {
  125. TraceFunc( "" );
  126. HRESULT hr;
  127. IBindCtx *pbc;
  128. // Check parameters
  129. Assert( NULL != pidlIn );
  130. Assert( NULL != ppvIn );
  131. *ppvIn = 0;
  132. hr = THR( BindCtx_CreateWithMode( grfModeIn, &pbc ) );
  133. if ( SUCCEEDED( hr ) )
  134. {
  135. hr = THR( SHBindToObjectEx( NULL, pidlIn, pbc, riidIn, ppvIn ) );
  136. pbc->Release();
  137. }
  138. HRETURN( hr );
  139. }
  140. //
  141. //
  142. //
  143. STDAPI_(LPITEMIDLIST)
  144. IDA_FullIDList(
  145. CIDA * pidaIn
  146. , UINT idxIn
  147. )
  148. {
  149. TraceFunc( "" );
  150. LPITEMIDLIST pidl = NULL;
  151. LPCITEMIDLIST pidlParent = IDA_GetIDListPtr( pidaIn, (UINT) -1 );
  152. if ( NULL != pidlParent )
  153. {
  154. LPCITEMIDLIST pidlRel = IDA_GetIDListPtr( pidaIn, idxIn );
  155. if ( NULL != pidlRel )
  156. {
  157. pidl = ILCombine( pidlParent, pidlRel );
  158. }
  159. }
  160. RETURN( pidl );
  161. }