ReactOS 0.4.15-dev-7842-g558ab78
CShellLink.cpp File Reference
#include "precomp.h"
#include <appmgmt.h>
#include "pshpack1.h"
#include "poppack.h"
Include dependency graph for CShellLink.cpp:

Go to the source code of this file.

Classes

struct  LOCATION_INFO
 
struct  LOCAL_VOLUME_INFO
 
struct  volume_info
 

Macros

#define ICON_LINK_WINDOWS_COMPAT
 
#define SHLINK_LOCAL   0
 
#define SHLINK_REMOTE   1
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (shell)
 
static HRESULT ShellLink_UpdatePath (LPCWSTR sPathRel, LPCWSTR path, LPCWSTR sWorkDir, LPWSTR *psPath)
 
static LPWSTR __inline HEAP_strdupAtoW (HANDLE heap, DWORD flags, LPCSTR str)
 
static LPWSTR __inline strdupW (LPCWSTR src)
 
static HRESULT Stream_LoadString (IStream *stm, BOOL unicode, LPWSTR *pstr)
 
static BOOL ShellLink_GetVolumeInfo (LPCWSTR path, CShellLink::volume_info *volume)
 
static HRESULT Stream_ReadChunk (IStream *stm, LPVOID *data)
 
static BOOL Stream_LoadVolume (LOCAL_VOLUME_INFO *vol, CShellLink::volume_info *volume)
 
static LPWSTR Stream_LoadPath (LPCSTR p, DWORD maxlen)
 
static HRESULT Stream_LoadLocation (IStream *stm, CShellLink::volume_info *volume, LPWSTR *path)
 
static HRESULT Stream_WriteString (IStream *stm, LPCWSTR str)
 
static HRESULT Stream_WriteLocationInfo (IStream *stm, LPCWSTR path, CShellLink::volume_info *volume)
 
static BOOL SHELL_ExistsFileW (LPCWSTR path)
 
static LPWSTR shelllink_get_msi_component_path (LPWSTR component)
 
static HRESULT SHELL_PidlGetIconLocationW (PCIDLIST_ABSOLUTE pidl, UINT uFlags, PWSTR pszIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
 
static LPWSTR GetAdvertisedArg (LPCWSTR str)
 
INT_PTR CALLBACK ExtendedShortcutProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
LPWSTR SH_GetTargetTypeByPath (LPCWSTR lpcwFullPath)
 
HRESULT WINAPI IShellLink_ConstructFromPath (WCHAR *path, REFIID riid, LPVOID *ppv)
 
HRESULT WINAPI IShellLink_ConstructFromFile (IShellFolder *psf, LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv)
 

Macro Definition Documentation

◆ ICON_LINK_WINDOWS_COMPAT

#define ICON_LINK_WINDOWS_COMPAT

Definition at line 152 of file CShellLink.cpp.

◆ SHLINK_LOCAL

#define SHLINK_LOCAL   0

Definition at line 154 of file CShellLink.cpp.

◆ SHLINK_REMOTE

#define SHLINK_REMOTE   1

Definition at line 155 of file CShellLink.cpp.

Function Documentation

◆ ExtendedShortcutProc()

INT_PTR CALLBACK ExtendedShortcutProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 2666 of file CShellLink.cpp.

2668{
2669 switch(uMsg)
2670 {
2671 case WM_INITDIALOG:
2672 if (lParam)
2673 {
2674 HWND hDlgCtrl = GetDlgItem(hwndDlg, IDC_SHORTEX_RUN_DIFFERENT);
2675 SendMessage(hDlgCtrl, BM_SETCHECK, BST_CHECKED, 0);
2676 }
2677 return TRUE;
2678 case WM_COMMAND:
2679 {
2680 HWND hDlgCtrl = GetDlgItem(hwndDlg, IDC_SHORTEX_RUN_DIFFERENT);
2681 if (LOWORD(wParam) == IDOK)
2682 {
2683 if (SendMessage(hDlgCtrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
2684 EndDialog(hwndDlg, 1);
2685 else
2686 EndDialog(hwndDlg, 0);
2687 }
2688 else if (LOWORD(wParam) == IDCANCEL)
2689 {
2690 EndDialog(hwndDlg, -1);
2691 }
2693 {
2694 if (SendMessage(hDlgCtrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
2695 SendMessage(hDlgCtrl, BM_SETCHECK, BST_UNCHECKED, 0);
2696 else
2697 SendMessage(hDlgCtrl, BM_SETCHECK, BST_CHECKED, 0);
2698 }
2699 }
2700 }
2701 return FALSE;
2702}
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define LOWORD(l)
Definition: pedump.c:82
#define IDC_SHORTEX_RUN_DIFFERENT
Definition: shresdef.h:478
#define IDCANCEL
Definition: winuser.h:831
#define BST_UNCHECKED
Definition: winuser.h:199
#define WM_COMMAND
Definition: winuser.h:1740
#define WM_INITDIALOG
Definition: winuser.h:1739
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:830
#define BM_SETCHECK
Definition: winuser.h:1921
#define SendMessage
Definition: winuser.h:5843
#define BST_CHECKED
Definition: winuser.h:197
#define BM_GETCHECK
Definition: winuser.h:1918
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)

Referenced by CShellLink::OnCommand().

◆ GetAdvertisedArg()

static LPWSTR GetAdvertisedArg ( LPCWSTR  str)
static

Definition at line 2020 of file CShellLink.cpp.

2021{
2022 if (!str)
2023 return NULL;
2024
2025 LPCWSTR p = wcschr(str, L':');
2026 if (!p)
2027 return NULL;
2028
2029 DWORD len = p - str;
2030 LPWSTR ret = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (len + 1));
2031 if (!ret)
2032 return ret;
2033
2034 memcpy(ret, str, sizeof(WCHAR)*len);
2035 ret[len] = 0;
2036 return ret;
2037}
#define NULL
Definition: types.h:112
#define wcschr
Definition: compat.h:17
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
unsigned long DWORD
Definition: ntddk_ex.h:95
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define L(x)
Definition: ntvdm.h:50
const WCHAR * str
int ret
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by CShellLink::SetAdvertiseInfo().

◆ HEAP_strdupAtoW()

static LPWSTR __inline HEAP_strdupAtoW ( HANDLE  heap,
DWORD  flags,
LPCSTR  str 
)
static

Definition at line 194 of file CShellLink.cpp.

195{
196 INT len;
197 LPWSTR p;
198
199 assert(str);
200
201 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
202 p = (LPWSTR)HeapAlloc(heap, flags, len * sizeof(WCHAR));
203 if (!p)
204 return p;
206 return p;
207}
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
#define assert(x)
Definition: debug.h:53
GLbitfield flags
Definition: glext.h:7161
static HANDLE heap
Definition: heap.c:65
int32_t INT
Definition: typedefs.h:58

Referenced by CShellLink::Extract(), CShellLink::SetArguments(), CShellLink::SetDescription(), CShellLink::SetIconLocation(), CShellLink::SetPath(), CShellLink::SetRelativePath(), and CShellLink::SetWorkingDirectory().

◆ IShellLink_ConstructFromFile()

HRESULT WINAPI IShellLink_ConstructFromFile ( IShellFolder psf,
LPCITEMIDLIST  pidl,
REFIID  riid,
LPVOID ppv 
)

Definition at line 3145 of file CShellLink.cpp.

3146{
3148 if (!ILGetDisplayNameExW(psf, pidl, path, 0))
3149 return E_FAIL;
3150
3152}
#define E_FAIL
Definition: ddrawi.h:102
#define MAX_PATH
Definition: compat.h:34
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
BOOL ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
Definition: pidl.c:91

◆ IShellLink_ConstructFromPath()

HRESULT WINAPI IShellLink_ConstructFromPath ( WCHAR path,
REFIID  riid,
LPVOID ppv 
)

Definition at line 3131 of file CShellLink.cpp.

3132{
3134 HRESULT hr = CShellLink::_CreatorClass::CreateInstance(NULL, IID_PPV_ARG(IPersistFile, &ppf));
3135 if (FAILED(hr))
3136 return hr;
3137
3138 hr = ppf->Load(path, 0);
3139 if (FAILED(hr))
3140 return hr;
3141
3142 return ppf->QueryInterface(riid, ppv);
3143}
#define FAILED(hr)
Definition: intsafe.h:51
HRESULT hr
Definition: shlfolder.c:183
#define IID_PPV_ARG(Itype, ppType)

Referenced by CFSDropTarget::_DoDrop(), IShellLink_ConstructFromFile(), and SHAddToRecentDocs().

◆ SH_GetTargetTypeByPath()

LPWSTR SH_GetTargetTypeByPath ( LPCWSTR  lpcwFullPath)

Definition at line 2709 of file CShellLink.cpp.

2710{
2711 LPCWSTR pwszExt;
2712 static WCHAR wszBuf[MAX_PATH];
2713
2714 /* Get file information */
2715 SHFILEINFOW fi;
2716 if (!SHGetFileInfoW(lpcwFullPath, 0, &fi, sizeof(fi), SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES))
2717 {
2718 ERR("SHGetFileInfoW failed for %ls (%lu)\n", lpcwFullPath, GetLastError());
2719 fi.szTypeName[0] = L'\0';
2720 fi.hIcon = NULL;
2721 }
2722
2723 pwszExt = PathFindExtensionW(lpcwFullPath);
2724 if (pwszExt[0])
2725 {
2726 if (!fi.szTypeName[0])
2727 {
2728 /* The file type is unknown, so default to string "FileExtension File" */
2729 size_t cchRemaining = 0;
2730 LPWSTR pwszEnd = NULL;
2731
2732 StringCchPrintfExW(wszBuf, _countof(wszBuf), &pwszEnd, &cchRemaining, 0, L"%s ", pwszExt + 1);
2733 }
2734 else
2735 {
2736 /* Update file type */
2737 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"%s (%s)", fi.szTypeName, pwszExt);
2738 }
2739 }
2740
2741 return wszBuf;
2742}
#define ERR(fmt,...)
Definition: debug.h:110
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path, DWORD dwFileAttributes, SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
Definition: shell32_main.c:415
#define SHGFI_TYPENAME
Definition: shellapi.h:167
#define SHGFI_USEFILEATTRIBUTES
Definition: shellapi.h:181
#define _countof(array)
Definition: sndvol32.h:68
STRSAFEAPI StringCchPrintfExW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:585
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
WCHAR szTypeName[80]
Definition: shellapi.h:376
HICON hIcon
Definition: shellapi.h:372
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by CShellLink::OnInitDialog().

◆ SHELL_ExistsFileW()

static BOOL SHELL_ExistsFileW ( LPCWSTR  path)
static

Definition at line 1008 of file CShellLink.cpp.

1009{
1011 return FALSE;
1012
1013 return TRUE;
1014}
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23

Referenced by ShellLink_UpdatePath().

◆ SHELL_PidlGetIconLocationW()

static HRESULT SHELL_PidlGetIconLocationW ( PCIDLIST_ABSOLUTE  pidl,
UINT  uFlags,
PWSTR  pszIconFile,
UINT  cchMax,
int piIndex,
UINT pwFlags 
)
static

Definition at line 1698 of file CShellLink.cpp.

1700{
1701 LPCITEMIDLIST pidlLast;
1703
1704 HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psf), &pidlLast);
1706 return hr;
1707
1709 hr = psf->GetUIObjectOf(0, 1, &pidlLast, IID_NULL_PPV_ARG(IExtractIconW, &pei));
1711 return hr;
1712
1713 hr = pei->GetIconLocation(uFlags, pszIconFile, cchMax, piIndex, pwFlags);
1715 return hr;
1716
1717 return S_OK;
1718}
UINT cchMax
UINT uFlags
Definition: api.c:59
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
#define S_OK
Definition: intsafe.h:52
HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
Definition: pidl.c:1352
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
#define IID_NULL_PPV_ARG(Itype, ppType)

Referenced by CShellLink::GetIconLocation().

◆ shelllink_get_msi_component_path()

static LPWSTR shelllink_get_msi_component_path ( LPWSTR  component)
static

Definition at line 1376 of file CShellLink.cpp.

1377{
1378 DWORD Result, sz = 0;
1379
1380 Result = CommandLineFromMsiDescriptor(component, NULL, &sz);
1381 if (Result != ERROR_SUCCESS)
1382 return NULL;
1383
1384 sz++;
1385 LPWSTR path = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, sz * sizeof(WCHAR));
1386 Result = CommandLineFromMsiDescriptor(component, path, &sz);
1387 if (Result != ERROR_SUCCESS)
1388 {
1390 path = NULL;
1391 }
1392
1393 TRACE("returning %s\n", debugstr_w(path));
1394
1395 return path;
1396}
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD WINAPI CommandLineFromMsiDescriptor(WCHAR *szDescriptor, WCHAR *szCommandLine, DWORD *pcchCommandLine)
Definition: msi.c:22
#define HeapFree(x, y, z)
Definition: compat.h:735
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by CShellLink::Resolve().

◆ ShellLink_GetVolumeInfo()

static BOOL ShellLink_GetVolumeInfo ( LPCWSTR  path,
CShellLink::volume_info volume 
)
static

Definition at line 473 of file CShellLink.cpp.

474{
475 WCHAR drive[4] = { path[0], ':', '\\', 0 };
476
477 volume->type = GetDriveTypeW(drive);
478 BOOL bRet = GetVolumeInformationW(drive, volume->label, _countof(volume->label), &volume->serial, NULL, NULL, NULL, 0);
479 TRACE("ret = %d type %d serial %08x name %s\n", bRet,
480 volume->type, volume->serial, debugstr_w(volume->label));
481 return bRet;
482}
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
BOOL WINAPI GetVolumeInformationW(IN LPCWSTR lpRootPathName, IN LPWSTR lpVolumeNameBuffer, IN DWORD nVolumeNameSize, OUT LPDWORD lpVolumeSerialNumber OPTIONAL, OUT LPDWORD lpMaximumComponentLength OPTIONAL, OUT LPDWORD lpFileSystemFlags OPTIONAL, OUT LPWSTR lpFileSystemNameBuffer OPTIONAL, IN DWORD nFileSystemNameSize)
Definition: volume.c:226
unsigned int BOOL
Definition: ntddk_ex.h:94

Referenced by CShellLink::SetTargetFromPIDLOrPath().

◆ ShellLink_UpdatePath()

static HRESULT ShellLink_UpdatePath ( LPCWSTR  sPathRel,
LPCWSTR  path,
LPCWSTR  sWorkDir,
LPWSTR psPath 
)
static

Definition at line 1020 of file CShellLink.cpp.

1021{
1022 if (!path || !psPath)
1023 return E_INVALIDARG;
1024
1025 if (!*psPath && sPathRel)
1026 {
1027 WCHAR buffer[2*MAX_PATH], abs_path[2*MAX_PATH];
1028 LPWSTR final = NULL;
1029
1030 /* first try if [directory of link file] + [relative path] finds an existing file */
1031
1032 GetFullPathNameW(path, MAX_PATH * 2, buffer, &final);
1033 if (!final)
1034 final = buffer;
1035 wcscpy(final, sPathRel);
1036
1037 *abs_path = '\0';
1038
1040 {
1041 if (!GetFullPathNameW(buffer, MAX_PATH, abs_path, &final))
1042 wcscpy(abs_path, buffer);
1043 }
1044 else
1045 {
1046 /* try if [working directory] + [relative path] finds an existing file */
1047 if (sWorkDir)
1048 {
1049 wcscpy(buffer, sWorkDir);
1050 wcscpy(PathAddBackslashW(buffer), sPathRel);
1051
1053 if (!GetFullPathNameW(buffer, MAX_PATH, abs_path, &final))
1054 wcscpy(abs_path, buffer);
1055 }
1056 }
1057
1058 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1059 if (!*abs_path)
1060 wcscpy(abs_path, sPathRel);
1061
1062 *psPath = strdupW(abs_path);
1063 if (!*psPath)
1064 return E_OUTOFMEMORY;
1065 }
1066
1067 return S_OK;
1068}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1106
GLuint buffer
Definition: glext.h:5915
#define PathAddBackslashW
Definition: pathcch.h:301
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)

Referenced by CShellLink::Load(), and CShellLink::SetRelativePath().

◆ strdupW()

static LPWSTR __inline strdupW ( LPCWSTR  src)
static

Definition at line 209 of file CShellLink.cpp.

210{
211 LPWSTR dest;
212 if (!src) return NULL;
213 dest = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wcslen(src) + 1) * sizeof(WCHAR));
214 if (dest)
215 wcscpy(dest, src);
216 return dest;
217}
GLenum src
Definition: glext.h:6340
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static char * dest
Definition: rtl.c:135

Referenced by ShellLink_UpdatePath().

◆ Stream_LoadLocation()

static HRESULT Stream_LoadLocation ( IStream stm,
CShellLink::volume_info volume,
LPWSTR path 
)
static

Definition at line 554 of file CShellLink.cpp.

556{
557 char *p = NULL;
558 HRESULT hr = Stream_ReadChunk(stm, (LPVOID*) &p);
559 if (FAILED(hr))
560 return hr;
561
562 LOCATION_INFO *loc = reinterpret_cast<LOCATION_INFO *>(p);
563 if (loc->dwTotalSize < sizeof(LOCATION_INFO))
564 {
566 return E_FAIL;
567 }
568
569 /* if there's valid local volume information, load it */
570 if (loc->dwVolTableOfs &&
571 ((loc->dwVolTableOfs + sizeof(LOCAL_VOLUME_INFO)) <= loc->dwTotalSize))
572 {
574
577 }
578
579 /* if there's a local path, load it */
580 DWORD n = loc->dwLocalPathOfs;
581 if (n && n < loc->dwTotalSize)
582 *path = Stream_LoadPath(&p[n], loc->dwTotalSize - n);
583
584 TRACE("type %d serial %08x name %s path %s\n", volume->type,
585 volume->serial, debugstr_w(volume->label), debugstr_w(*path));
586
588 return S_OK;
589}
GLdouble n
Definition: glext.h:7729
DWORD dwLocalPathOfs
Definition: CShellLink.cpp:167
DWORD dwVolTableOfs
Definition: CShellLink.cpp:166

Referenced by CShellLink::Load().

◆ Stream_LoadPath()

static LPWSTR Stream_LoadPath ( LPCSTR  p,
DWORD  maxlen 
)
static

Definition at line 537 of file CShellLink.cpp.

538{
539 UINT len = 0;
540
541 while (len < maxlen && p[len])
542 len++;
543
544 UINT wlen = MultiByteToWideChar(CP_ACP, 0, p, len, NULL, 0);
545 LPWSTR path = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wlen + 1) * sizeof(WCHAR));
546 if (!path)
547 return NULL;
548 MultiByteToWideChar(CP_ACP, 0, p, len, path, wlen);
549 path[wlen] = 0;
550
551 return path;
552}
unsigned int UINT
Definition: ndis.h:50

Referenced by Stream_LoadLocation().

◆ Stream_LoadString()

static HRESULT Stream_LoadString ( IStream stm,
BOOL  unicode,
LPWSTR pstr 
)
static

Definition at line 416 of file CShellLink.cpp.

417{
418 TRACE("%p\n", stm);
419
420 USHORT len;
421 DWORD count = 0;
422 HRESULT hr = stm->Read(&len, sizeof(len), &count);
423 if (FAILED(hr) || count != sizeof(len))
424 return E_FAIL;
425
426 if (unicode)
427 len *= sizeof(WCHAR);
428
429 TRACE("reading %d\n", len);
430 LPSTR temp = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len + sizeof(WCHAR));
431 if (!temp)
432 return E_OUTOFMEMORY;
433 count = 0;
434 hr = stm->Read(temp, len, &count);
435 if (FAILED(hr) || count != len)
436 {
438 return E_FAIL;
439 }
440
441 TRACE("read %s\n", debugstr_an(temp, len));
442
443 /* convert to unicode if necessary */
444 LPWSTR str;
445 if (!unicode)
446 {
448 str = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (count + 1) * sizeof(WCHAR));
449 if (!str)
450 {
452 return E_OUTOFMEMORY;
453 }
456 }
457 else
458 {
459 count /= sizeof(WCHAR);
460 str = (LPWSTR)temp;
461 }
462 str[count] = 0;
463
464 *pstr = str;
465
466 return S_OK;
467}
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
GLuint GLuint GLsizei count
Definition: gl.h:1545
HRESULT Read([out, size_is(cb), length_is(*pcbRead)] void *pv, [in] ULONG cb, [out] ULONG *pcbRead)
unsigned short USHORT
Definition: pedump.c:61
static calc_node_t temp
Definition: rpn_ieee.c:38
char * LPSTR
Definition: xmlstorage.h:182

Referenced by CShellLink::Load().

◆ Stream_LoadVolume()

static BOOL Stream_LoadVolume ( LOCAL_VOLUME_INFO vol,
CShellLink::volume_info volume 
)
static

Definition at line 519 of file CShellLink.cpp.

520{
521 volume->serial = vol->dwVolSerial;
522 volume->type = vol->dwType;
523
524 if (!vol->dwVolLabelOfs)
525 return FALSE;
526 if (vol->dwSize <= vol->dwVolLabelOfs)
527 return FALSE;
528 INT len = vol->dwSize - vol->dwVolLabelOfs;
529
530 LPSTR label = (LPSTR)vol;
531 label += vol->dwVolLabelOfs;
533
534 return TRUE;
535}
static const WCHAR label[]
Definition: itemdlg.c:1546

Referenced by Stream_LoadLocation().

◆ Stream_ReadChunk()

static HRESULT Stream_ReadChunk ( IStream stm,
LPVOID data 
)
static

Definition at line 484 of file CShellLink.cpp.

485{
486 struct sized_chunk
487 {
488 DWORD size;
489 unsigned char data[1];
490 } *chunk;
491
492 TRACE("%p\n", stm);
493
494 DWORD size;
495 ULONG count;
496 HRESULT hr = stm->Read(&size, sizeof(size), &count);
497 if (FAILED(hr) || count != sizeof(size))
498 return E_FAIL;
499
500 chunk = static_cast<sized_chunk *>(HeapAlloc(GetProcessHeap(), 0, size));
501 if (!chunk)
502 return E_OUTOFMEMORY;
503
504 chunk->size = size;
505 hr = stm->Read(chunk->data, size - sizeof(size), &count);
506 if (FAILED(hr) || count != (size - sizeof(size)))
507 {
509 return E_FAIL;
510 }
511
512 TRACE("Read %d bytes\n", chunk->size);
513
514 *data = chunk;
515
516 return S_OK;
517}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
uint16_t size
Definition: btrfs_drv.h:563
uint32_t ULONG
Definition: typedefs.h:59

Referenced by Stream_LoadLocation().

◆ Stream_WriteLocationInfo()

static HRESULT Stream_WriteLocationInfo ( IStream stm,
LPCWSTR  path,
CShellLink::volume_info volume 
)
static

Definition at line 820 of file CShellLink.cpp.

822{
824 LOCATION_INFO *loc;
825
826 TRACE("%p %s %p\n", stm, debugstr_w(path), volume);
827
828 /* figure out the size of everything */
829 DWORD label_size = WideCharToMultiByte(CP_ACP, 0, volume->label, -1,
830 NULL, 0, NULL, NULL);
831 DWORD path_size = WideCharToMultiByte(CP_ACP, 0, path, -1,
832 NULL, 0, NULL, NULL);
833 DWORD volume_info_size = sizeof(*vol) + label_size;
834 DWORD final_path_size = 1;
835 DWORD total_size = sizeof(*loc) + volume_info_size + path_size + final_path_size;
836
837 /* create pointers to everything */
838 loc = static_cast<LOCATION_INFO *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, total_size));
839 vol = (LOCAL_VOLUME_INFO*) &loc[1];
840 LPSTR szLabel = (LPSTR) &vol[1];
841 LPSTR szPath = &szLabel[label_size];
842 LPSTR szFinalPath = &szPath[path_size];
843
844 /* fill in the location information header */
845 loc->dwTotalSize = total_size;
846 loc->dwHeaderSize = sizeof(*loc);
847 loc->dwFlags = 1;
848 loc->dwVolTableOfs = sizeof(*loc);
849 loc->dwLocalPathOfs = sizeof(*loc) + volume_info_size;
850 loc->dwNetworkVolTableOfs = 0;
851 loc->dwFinalPathOfs = sizeof(*loc) + volume_info_size + path_size;
852
853 /* fill in the volume information */
854 vol->dwSize = volume_info_size;
855 vol->dwType = volume->type;
856 vol->dwVolSerial = volume->serial;
857 vol->dwVolLabelOfs = sizeof(*vol);
858
859 /* copy in the strings */
860 WideCharToMultiByte(CP_ACP, 0, volume->label, -1,
861 szLabel, label_size, NULL, NULL);
863 szPath, path_size, NULL, NULL);
864 *szFinalPath = 0;
865
866 ULONG count = 0;
867 HRESULT hr = stm->Write(loc, total_size, &count);
868 HeapFree(GetProcessHeap(), 0, loc);
869
870 return hr;
871}
#define WideCharToMultiByte
Definition: compat.h:111
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
HRESULT Write([in, size_is(cb)] const void *pv, [in] ULONG cb, [out] ULONG *pcbWritten)
LPCWSTR szPath
Definition: env.c:37
DWORD dwHeaderSize
Definition: CShellLink.cpp:164
DWORD dwFinalPathOfs
Definition: CShellLink.cpp:169
DWORD dwNetworkVolTableOfs
Definition: CShellLink.cpp:168

Referenced by CShellLink::Save().

◆ Stream_WriteString()

static HRESULT Stream_WriteString ( IStream stm,
LPCWSTR  str 
)
static

Definition at line 785 of file CShellLink.cpp.

786{
788 USHORT len;
789 DWORD count;
790
791 length = wcslen(str) + 1;
792 if (length > MAXUSHORT)
793 {
794 return E_INVALIDARG;
795 }
796
797 len = (USHORT)length;
798 HRESULT hr = stm->Write(&len, sizeof(len), &count);
799 if (FAILED(hr))
800 return hr;
801
802 length *= sizeof(WCHAR);
803
804 hr = stm->Write(str, (ULONG)length, &count);
805 if (FAILED(hr))
806 return hr;
807
808 return S_OK;
809}
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define MAXUSHORT
Definition: typedefs.h:83

Referenced by CShellLink::Save().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( shell  )