19 static WORD shFlags = 0;
20 #define SHF_INITIALIZED 0x0001 21 #define SHF_USE_OLE 0x0002 22 #define SHF_SHMALLOC 0x0004 29 static HRESULT _initShMalloc()
31 HRESULT rc = CoGetMalloc( MEMCTX_TASK, &
ShMalloc );
44 rc = OleInitialize( NULL );
50 rc = CoInitializeEx( NULL, coFlag );
60 if (FAILED( rc )) SetLastError( rc );
61 return SUCCEEDED( rc );
74 else CoUninitialize();
107 IShellFolder* pShell;
109 LPITEMIDLIST pidl = NULL;
111 if (SUCCEEDED( SHGetDesktopFolder( &pShell )))
114 #define wPath (PWSTR)Dir 116 WCHAR wPath[ MAX_PATH ];
117 MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, Dir,-1, wPath, MAX_PATH );
121 pShell->ParseDisplayName(
122 (HWND)NULL, (IBindCtx*)NULL, wPath, &chUsed, &pidl, pAttrib
124 if (!ok) pidl = NULL;
133 IF_DEBUG( memset( &fop, 0,
sizeof(fop) ));
135 fop.wFunc = FO_DELETE;
140 fop.pFrom = Single ?
newStr( Name ) : Name;
141 if (!fop.pFrom)
return false;
143 fop.fFlags = FOF_ALLOWUNDO| FOF_FILESONLY| FOF_NO_CONNECTED_ELEMENTS;
144 if (!Confirm) fop.fFlags |= FOF_NOCONFIRMATION;
147 int rc = SHFileOperation( &fop );
150 if (rc) SetLastError( rc );
151 return ((rc == 0) && !fop.fAnyOperationsAborted);
159 HINSTANCE hlib = LoadLibrary( FName );
162 HRESULT (CALLBACK *DllGetVersion)( DLLVERSIONINFO* );
163 (FARPROC&) DllGetVersion = GetProcAddress( hlib,
"DllGetVersion" );
166 DLLVERSIONINFO vi;
IF_DEBUG( memset( &vi, 0,
sizeof(vi) ));
167 vi.cbSize =
sizeof(DLLVERSIONINFO);
168 bool ok = SUCCEEDED( DllGetVersion( &vi ));
169 if (ok) ver =
PACKVERSION( vi.dwMajorVersion, vi.dwMinorVersion );
186 if (!
IsString( LinkFilePathname ) || !pd || !pd->Pathname)
190 if (!_inited) hres = CoInitialize( NULL );
194 hres = CoCreateInstance (
195 CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
196 IID_IShellLink, (
void**)&ShLink
198 if (SUCCEEDED( hres ))
200 ShLink->SetPath( pd->Pathname );
202 if (pd->Flags &
LDF_ARGS) ShLink->SetArguments( pd->Args );
203 if (pd->Flags &
LDF_DESC) ShLink->SetDescription( pd->Desc );
204 if (pd->Flags &
LDF_SHOWCMD) ShLink->SetShowCmd( pd->ShowCmd );
205 if (pd->Flags &
LDF_HOTKEY) ShLink->SetHotkey( pd->Hotkey );
206 if (pd->Flags &
LDF_PIDL) ShLink->SetIDList( pd->IdList );
209 ShLink->SetIconLocation( pd->IconPath, pd->IconIndex );
212 ShLink->SetWorkingDirectory( pd->WorkingDir );
216 hres = ShLink->QueryInterface( IID_IPersistFile, (
void**)&File );
217 if (SUCCEEDED( hres ))
220 hres = File->Save( LinkFilePathname,
true );
221 #else // Convert the ANSI path to a Unicode path 222 WCHAR wzPath[ MAX_PATH ] = {0};
223 MultiByteToWideChar( CP_ACP,0, LinkFilePathname,-1, wzPath,MAX_PATH );
224 hres = File->Save( wzPath,
true );
231 if (!_inited) CoUninitialize();
252 if (!_inited) hres = CoInitialize( NULL );
254 hres = CoCreateInstance(
255 CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
256 IID_IShellLink, (
void**)&ShLink
258 if (SUCCEEDED( hres ))
260 hres = ShLink->QueryInterface( IID_IPersistFile, (
void**)&File );
261 if (SUCCEEDED( hres ))
264 #define wszLink LinkFile 266 WCHAR wszLink[ MAX_PATH ];
267 MultiByteToWideChar( CP_ACP, 0, LinkFile,-1, wszLink, MAX_PATH );
270 hres = File->Load( wszLink, STGM_READ );
271 if (SUCCEEDED( hres ))
274 hres = ShLink->Resolve( hWnd, 0 );
275 if (SUCCEEDED( hres ))
277 hres = ShLink->GetPath(
278 pd->Pathname, MAX_PATH, &fd, SLGP_SHORTPATH
280 if (SUCCEEDED( hres ))
283 hres = ShLink->GetDescription(
287 hres = ShLink->GetArguments(
291 hres = ShLink->GetIconLocation(
292 pd->IconPath, MAX_PATH, &pd->IconIndex
295 hres = ShLink->GetWorkingDirectory(
296 pd->WorkingDir, MAX_PATH
300 hres = ShLink->GetIDList( &pd->IdList );
302 hres = ShLink->GetHotkey( &pd->Hotkey );
304 hres = ShLink->GetShowCmd( &pd->ShowCmd );
313 if (!_inited) CoUninitialize();
372 static HRESULT (NTAPI *_ShowShareFolderUI)( HWND hParent, LPCWSTR wzPath );
373 if (!_ShowShareFolderUI)
375 HMODULE hMod = LoadLibraryA(
"ntshrui.dll" );
376 if (hMod) (FARPROC&)_ShowShareFolderUI = GetProcAddress( hMod,
"ShowShareFolderUI" );
377 TRACE(
DP_DEBUG,
_F(
"_ShowShareFolderUI = %p\n"), _ShowShareFolderUI );
379 if (!_ShowShareFolderUI) hres = E_FAIL;
385 WCHAR wzPath[ MAX_PATH ];
386 MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, Path, -1, wzPath,
dimof(wzPath) );
388 hres = _ShowShareFolderUI( hParent, wzPath );
397 ULARGE_INTEGER fsize;
405 memset( &mems, 0,
sizeof(mems) );
406 mems.dwLength =
sizeof(mems);
407 if (!GlobalMemoryStatusEx( &mems )) mems.ullAvailPhys = 0;
409 hFile = CreateFile( FName,
GENERIC_RW, 0,0, OPEN_EXISTING, 0,0 );
411 hr = HRESULT_FROM_WIN32( GetLastError() );
414 fsize.LowPart = GetFileSize( hFile, &fsize.HighPart );
421 mems.ullAvailPhys /= 2;
422 if (fsize.HighPart || (fsize.QuadPart > mems.ullAvailPhys))
426 dwSize = fsize.LowPart;
427 if (pSize) *pSize = dwSize;
429 hGlb = GlobalAlloc( GMEM_MOVEABLE| GMEM_SHARE, dwSize );
430 if (!hGlb) hr = E_OUTOFMEMORY;
433 pGlb = GlobalLock( hGlb );
434 if (!pGlb) hr = E_HANDLE;
437 if (!ReadFile( hFile, pGlb, dwSize, &cbRd, 0 ) || (cbRd != dwSize))
438 hr = HRESULT_FROM_WIN32( GetLastError() );
440 GlobalUnlock( hGlb );
443 hr = CreateStreamOnHGlobal( hGlb, TRUE, ppStrm );
449 if (SUCCEEDED( hr )) hr = (*ppStrm)->SetSize( fsize );
451 if (FAILED( hr )) GlobalFree( hGlb );
454 CloseHandle( hFile );
459 #if 0 // In the odd case you need an IStream on an HMAPFILE (I can't really see why). 466 IStream* CreateStreamOnMappedFile(
CSTR FName,
DWORD PageAccess,
HMAPFILE* phFile )
468 IStream* pStream = NULL;
474 #if (_WIN32_IE >= 0x600) 475 if (pData) pStream = SHCreateMemStream( pData, cbData );
483 static IStream* (__stdcall *_SHCreateMemStream)(
const PBYTE pInit, UINT cbInit );
484 if (!_SHCreateMemStream)
486 HMODULE hLib = LoadLibrary( _T(
"SHLWAPI.DLL") );
487 if (hLib) (FARPROC&)_SHCreateMemStream = GetProcAddress( hLib,
CSTR( 12 ));
489 if (_SHCreateMemStream) pStream = _SHCreateMemStream( pData, cbData );
493 if (phFile) *phFile = hFile;
499 void ReleaseMappedFileStream( IStream* pStm,
HMAPFILE hFile )
506 #if USE_VISUALSTYLE_HACK 508 bool EnableVisualStyles(
bool Enable )
510 static ULONG_PTR actCookie;
511 static const UINT_PTR shellManifestId = 124;
516 if (actCookie) ok = TRUE;
519 TCHAR sysDir[ MAX_PATH ];
522 ACTCTX_FLAG_RESOURCE_NAME_VALID
523 | ACTCTX_FLAG_SET_PROCESS_DEFAULT
524 | ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID,
525 _T(
"shell32.dll"), 0,0,
526 sysDir, (
CSTR)shellManifestId, NULL, NULL
528 UINT cch = GetSystemDirectory( sysDir,
dimof(sysDir) );
529 if (cch <
dimof(sysDir)) {
531 HANDLE hActCtx =
CheckHandle( CreateActCtx( &actCtx ));
532 ok = hActCtx ? ActivateActCtx( hActCtx, &actCookie ) : FALSE;
538 #ifdef HAVE_STRUCTURED_EH 540 ok = DeactivateActCtx( 0, actCookie );
541 if (ok) actCookie = 0;
544 DWORD xCode = GetExceptionCode();
549 #else // __GNUC__; No SEH 550 ok = DeactivateActCtx( 0, actCookie );
551 if (ok) actCookie = 0;
564 #if 0 // This omission have been already been mended by MinGW. 566 #if (WINVER >= 0x601) 567 #error("FIXME: MinGW's user32 lib lacks ChangeWindowMessageFilter") // See below... 569 WINUSERAPI
BOOL WINAPI
570 ChangeWindowMessageFilter( UINT message,
DWORD dwFlag );
572 #define MSGFLT_REMOVE 2 589 TRACE(
DP_DEBUG, _T(
"Windows 7++ : Unblocking WM_TaskbarCreated.\n") );
590 CHANGEFILTERSTRUCT cfs = {
sizeof(CHANGEFILTERSTRUCT), 0 };
597 #if (WINVER >= 0x600) && !defined(__GNUC__) // MinGW's user32 lib lacks this API 599 TRACE(
DP_DEBUG, _T(
"Windows Vista++ : Unblocking WM_TaskbarCreated.\n") );
608 UINT Action, HWND hNfy, UINT Id, HICON hIcon,
CSTR Hint, UINT cbkMsg
613 nic.cbSize =
sizeof(nic);
622 nic.uCallbackMessage = cbkMsg;
623 nic.uFlags = NIF_ICON | NIF_MESSAGE;
626 _tcscpy_s( nic.szTip,
dimof(nic.szTip), Hint );
627 nic.uFlags |= NIF_TIP;
635 return Shell_NotifyIcon( Action, &nic );
DWORD GetDLLVersion(CSTR FName)
HANDLE CheckHandle(HANDLE Hnd)
void InitTaskbarSupport()
bool InitShellFunc(bool useOle, DWORD coFlag)
void __cdecl DPrint(int Level, CSTR Fmt,...)
HRESULT ShowShareFolderUI(HWND hParent, CSTR Path)
Transmutable wrap for the strictly dynamic ntshrui.dll function.
HRESULT CreateStreamOnFile(_in CSTR FName, _out IStream **ppStrm, _out DWORD *pSize)
HRESULT Shell_CreateLink(CSTR LinkFilePathname, const PLINKDATA pd)
bool ShellFuncInitialized()
#define PACKVERSION(maj, min)
BOOL(WINAPI *SysImgList::Shell_GetImageLists)(HIMAGELIST *pimlLarge
struct _LINKDATA * PLINKDATA
CSTR SysErrorMsg(DWORD Err=0, TSTR Buf=NULL, UINT Length=0)
PVOID ShellFreeEx(PVOID pBlk)
BOOL UnloadMappedFile(HMAPFILE hMap)
bool __forceinline bool_cast(BOOL B52)
LPITEMIDLIST GetPathNamePIDL(CSTR Dir, ULONG *pAttrib)
#define BITS_SET(bits, x)
Debug and error handling support.
HRESULT Shell_ResolveLink(HWND hWnd, CSTR LinkFile, PLINKDATA pd)
Common include; Added types, small "ubiquitous" utilities, et c.
HMAPFILE LoadAndMapFile(CSTR FName, DWORD PageAccess, PBYTE *ppData)
bool RecycleFile(CSTR Name, bool Confirm, bool Single)
BOOL SetTrayIconNotification(UINT Action, HWND hNfy, UINT Id, HICON hIcon, CSTR Hint, UINT cbkMsg)
bool __forceinline IsString(CSTR Str)