ReactOS 0.4.16-dev-1049-g378a335
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 BOOL PathEnvSubstIsDirectory (LPCWSTR pszPath)
 
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)
 
static void GetTypeDescriptionByPath (PCWSTR pszFullPath, DWORD fAttributes, PWSTR szBuf, UINT cchBuf)
 
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 2699 of file CShellLink.cpp.

2701{
2702 switch(uMsg)
2703 {
2704 case WM_INITDIALOG:
2705 if (lParam)
2706 {
2707 HWND hDlgCtrl = GetDlgItem(hwndDlg, IDC_SHORTEX_RUN_DIFFERENT);
2708 SendMessage(hDlgCtrl, BM_SETCHECK, BST_CHECKED, 0);
2709 }
2710 return TRUE;
2711 case WM_COMMAND:
2712 {
2713 HWND hDlgCtrl = GetDlgItem(hwndDlg, IDC_SHORTEX_RUN_DIFFERENT);
2714 if (LOWORD(wParam) == IDOK)
2715 {
2716 if (SendMessage(hDlgCtrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
2717 EndDialog(hwndDlg, 1);
2718 else
2719 EndDialog(hwndDlg, 0);
2720 }
2721 else if (LOWORD(wParam) == IDCANCEL)
2722 {
2723 EndDialog(hwndDlg, -1);
2724 }
2726 {
2727 if (SendMessage(hDlgCtrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
2728 SendMessage(hDlgCtrl, BM_SETCHECK, BST_UNCHECKED, 0);
2729 else
2730 SendMessage(hDlgCtrl, BM_SETCHECK, BST_CHECKED, 0);
2731 }
2732 }
2733 }
2734 return FALSE;
2735}
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:507
#define IDCANCEL
Definition: winuser.h:842
#define BST_UNCHECKED
Definition: winuser.h:199
#define WM_COMMAND
Definition: winuser.h:1751
#define WM_INITDIALOG
Definition: winuser.h:1750
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:841
#define BM_SETCHECK
Definition: winuser.h:1932
#define SendMessage
Definition: winuser.h:5863
#define BST_CHECKED
Definition: winuser.h:197
#define BM_GETCHECK
Definition: winuser.h:1929
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)

Referenced by CShellLink::OnCommand().

◆ GetAdvertisedArg()

static LPWSTR GetAdvertisedArg ( LPCWSTR  str)
static

Definition at line 2061 of file CShellLink.cpp.

2062{
2063 if (!str)
2064 return NULL;
2065
2066 LPCWSTR p = wcschr(str, L':');
2067 if (!p)
2068 return NULL;
2069
2070 DWORD len = p - str;
2071 LPWSTR ret = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (len + 1));
2072 if (!ret)
2073 return ret;
2074
2075 memcpy(ret, str, sizeof(WCHAR)*len);
2076 ret[len] = 0;
2077 return ret;
2078}
#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().

◆ GetTypeDescriptionByPath()

static void GetTypeDescriptionByPath ( PCWSTR  pszFullPath,
DWORD  fAttributes,
PWSTR  szBuf,
UINT  cchBuf 
)
static

Definition at line 2737 of file CShellLink.cpp.

2738{
2739 if (fAttributes == INVALID_FILE_ATTRIBUTES && !PathFileExistsAndAttributesW(pszFullPath, &fAttributes))
2740 fAttributes = 0;
2741
2742 SHFILEINFOW fi;
2743 if (!SHGetFileInfoW(pszFullPath, fAttributes, &fi, sizeof(fi), SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES))
2744 {
2745 ERR("SHGetFileInfoW failed for %ls (%lu)\n", pszFullPath, GetLastError());
2746 fi.szTypeName[0] = UNICODE_NULL;
2747 }
2748
2749 BOOL fFolder = (fAttributes & FILE_ATTRIBUTE_DIRECTORY);
2750 LPCWSTR pwszExt = fFolder ? L"" : PathFindExtensionW(pszFullPath);
2751 if (pwszExt[0])
2752 {
2753 if (!fi.szTypeName[0])
2754 StringCchPrintfW(szBuf, cchBuf, L"%s", pwszExt + 1);
2755 else
2756 StringCchPrintfW(szBuf, cchBuf, L"%s (%s)", fi.szTypeName, pwszExt);
2757 }
2758 else
2759 {
2760 StringCchPrintfW(szBuf, cchBuf, L"%s", fi.szTypeName);
2761 }
2762}
#define ERR(fmt,...)
Definition: precomp.h:57
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
BOOL WINAPI PathFileExistsAndAttributesW(LPCWSTR lpszPath, DWORD *dwAttr)
Definition: path.c:1838
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define UNICODE_NULL
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path, DWORD dwFileAttributes, SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
Definition: shell32_main.c:430
#define SHGFI_TYPENAME
Definition: shellapi.h:168
#define SHGFI_USEFILEATTRIBUTES
Definition: shellapi.h:182
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
WCHAR szTypeName[80]
Definition: shellapi.h:377
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by CShellLink::OnInitDialog().

◆ 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 3237 of file CShellLink.cpp.

3238{
3240 if (!ILGetDisplayNameExW(psf, pidl, path, 0))
3241 return E_FAIL;
3242
3244}
#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:100

◆ IShellLink_ConstructFromPath()

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

Definition at line 3223 of file CShellLink.cpp.

3224{
3226 HRESULT hr = CShellLink::_CreatorClass::CreateInstance(NULL, IID_PPV_ARG(IPersistFile, &ppf));
3227 if (FAILED(hr))
3228 return hr;
3229
3230 hr = ppf->Load(path, 0);
3231 if (FAILED(hr))
3232 return hr;
3233
3234 return ppf->QueryInterface(riid, ppv);
3235}
#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().

◆ PathEnvSubstIsDirectory()

static BOOL PathEnvSubstIsDirectory ( LPCWSTR  pszPath)
static

Definition at line 219 of file CShellLink.cpp.

220{
221 // Note: Don't call SHExpandEnvironmentStringsW here, we need the required length
222 WCHAR szStack[MAX_PATH];
223 DWORD cch = ExpandEnvironmentStringsW(pszPath, szStack, _countof(szStack));
224 if (cch <= _countof(szStack))
225 return cch && PathIsDirectory(szStack);
226
227 PWSTR szHeap = (PWSTR)SHAlloc(cch);
228 if (!szHeap)
229 return FALSE;
230 BOOL bResult = ExpandEnvironmentStringsW(pszPath, szHeap, cch) && PathIsDirectory(szHeap);
231 SHFree(szHeap);
232 return bResult;
233}
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:326
LPVOID WINAPI SHAlloc(SIZE_T len)
Definition: shellole.c:304
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
#define PathIsDirectory
Definition: shlwapi.h:970
#define _countof(array)
Definition: sndvol32.h:70
uint16_t * PWSTR
Definition: typedefs.h:56

Referenced by CShellLink::DoOpen().

◆ SHELL_ExistsFileW()

static BOOL SHELL_ExistsFileW ( LPCWSTR  path)
static

Definition at line 1056 of file CShellLink.cpp.

1057{
1059 return FALSE;
1060
1061 return TRUE;
1062}
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652

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 1746 of file CShellLink.cpp.

1748{
1752 return hr;
1753 hr = pei->GetIconLocation(uFlags, pszIconFile, cchMax, piIndex, pwFlags);
1755 return hr;
1756
1757 return S_OK;
1758}
UINT cchMax
UINT uFlags
Definition: api.c:59
#define FAILED_UNEXPECTEDLY(hr)
Definition: debug.h:83
EXTERN_C HRESULT SHELL_GetUIObjectOfAbsoluteItem(_In_opt_ HWND hWnd, _In_ PCIDLIST_ABSOLUTE pidl, _In_ REFIID riid, _Out_ void **ppvObj)
Definition: utils.cpp:380
#define S_OK
Definition: intsafe.h:52

Referenced by CShellLink::GetIconLocation().

◆ shelllink_get_msi_component_path()

static LPWSTR shelllink_get_msi_component_path ( LPWSTR  component)
static

Definition at line 1424 of file CShellLink.cpp.

1425{
1426 DWORD Result, sz = 0;
1427
1428 Result = CommandLineFromMsiDescriptor(component, NULL, &sz);
1429 if (Result != ERROR_SUCCESS)
1430 return NULL;
1431
1432 sz++;
1433 LPWSTR path = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, sz * sizeof(WCHAR));
1434 Result = CommandLineFromMsiDescriptor(component, path, &sz);
1435 if (Result != ERROR_SUCCESS)
1436 {
1438 path = NULL;
1439 }
1440
1441 TRACE("returning %s\n", debugstr_w(path));
1442
1443 return path;
1444}
#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 488 of file CShellLink.cpp.

489{
490 WCHAR drive[4] = { path[0], ':', '\\', 0 };
491
492 volume->type = GetDriveTypeW(drive);
493 BOOL bRet = GetVolumeInformationW(drive, volume->label, _countof(volume->label), &volume->serial, NULL, NULL, NULL, 0);
494 TRACE("ret = %d type %d serial %08x name %s\n", bRet,
495 volume->type, volume->serial, debugstr_w(volume->label));
496 return bRet;
497}
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

Referenced by CShellLink::SetTargetFromPIDLOrPath().

◆ ShellLink_UpdatePath()

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

Definition at line 1068 of file CShellLink.cpp.

1069{
1070 if (!path || !psPath)
1071 return E_INVALIDARG;
1072
1073 if (!*psPath && sPathRel)
1074 {
1075 WCHAR buffer[2*MAX_PATH], abs_path[2*MAX_PATH];
1076 LPWSTR final = NULL;
1077
1078 /* first try if [directory of link file] + [relative path] finds an existing file */
1079
1080 GetFullPathNameW(path, MAX_PATH * 2, buffer, &final);
1081 if (!final)
1082 final = buffer;
1083 wcscpy(final, sPathRel);
1084
1085 *abs_path = '\0';
1086
1088 {
1089 if (!GetFullPathNameW(buffer, MAX_PATH, abs_path, &final))
1090 wcscpy(abs_path, buffer);
1091 }
1092 else
1093 {
1094 /* try if [working directory] + [relative path] finds an existing file */
1095 if (sWorkDir)
1096 {
1097 wcscpy(buffer, sWorkDir);
1098 wcscpy(PathAddBackslashW(buffer), sPathRel);
1099
1101 if (!GetFullPathNameW(buffer, MAX_PATH, abs_path, &final))
1102 wcscpy(abs_path, buffer);
1103 }
1104 }
1105
1106 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1107 if (!*abs_path)
1108 wcscpy(abs_path, sPathRel);
1109
1110 *psPath = strdupW(abs_path);
1111 if (!*psPath)
1112 return E_OUTOFMEMORY;
1113 }
1114
1115 return S_OK;
1116}
wcscpy
#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

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 569 of file CShellLink.cpp.

571{
572 char *p = NULL;
573 HRESULT hr = Stream_ReadChunk(stm, (LPVOID*) &p);
574 if (FAILED(hr))
575 return hr;
576
577 LOCATION_INFO *loc = reinterpret_cast<LOCATION_INFO *>(p);
578 if (loc->dwTotalSize < sizeof(LOCATION_INFO))
579 {
581 return E_FAIL;
582 }
583
584 /* if there's valid local volume information, load it */
585 if (loc->dwVolTableOfs &&
586 ((loc->dwVolTableOfs + sizeof(LOCAL_VOLUME_INFO)) <= loc->dwTotalSize))
587 {
589
592 }
593
594 /* if there's a local path, load it */
595 DWORD n = loc->dwLocalPathOfs;
596 if (n && n < loc->dwTotalSize)
597 *path = Stream_LoadPath(&p[n], loc->dwTotalSize - n); // FIXME: Unicode offset (if present)
598
599 TRACE("type %d serial %08x name %s path %s\n", volume->type,
600 volume->serial, debugstr_w(volume->label), debugstr_w(*path));
601
603 return S_OK;
604}
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 552 of file CShellLink.cpp.

553{
554 UINT len = 0;
555
556 while (len < maxlen && p[len])
557 len++;
558
559 UINT wlen = MultiByteToWideChar(CP_ACP, 0, p, len, NULL, 0);
560 LPWSTR path = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wlen + 1) * sizeof(WCHAR));
561 if (!path)
562 return NULL;
563 MultiByteToWideChar(CP_ACP, 0, p, len, path, wlen);
564 path[wlen] = 0;
565
566 return path;
567}
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 431 of file CShellLink.cpp.

432{
433 TRACE("%p\n", stm);
434
435 USHORT len;
436 DWORD count = 0;
437 HRESULT hr = stm->Read(&len, sizeof(len), &count);
438 if (FAILED(hr) || count != sizeof(len))
439 return E_FAIL;
440
441 if (unicode)
442 len *= sizeof(WCHAR);
443
444 TRACE("reading %d\n", len);
445 LPSTR temp = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len + sizeof(WCHAR));
446 if (!temp)
447 return E_OUTOFMEMORY;
448 count = 0;
449 hr = stm->Read(temp, len, &count);
450 if (FAILED(hr) || count != len)
451 {
453 return E_FAIL;
454 }
455
456 TRACE("read %s\n", debugstr_an(temp, len));
457
458 /* convert to unicode if necessary */
459 LPWSTR str;
460 if (!unicode)
461 {
463 str = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (count + 1) * sizeof(WCHAR));
464 if (!str)
465 {
467 return E_OUTOFMEMORY;
468 }
471 }
472 else
473 {
474 count /= sizeof(WCHAR);
475 str = (LPWSTR)temp;
476 }
477 str[count] = 0;
478
479 *pstr = str;
480
481 return S_OK;
482}
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 534 of file CShellLink.cpp.

535{
536 volume->serial = vol->dwVolSerial;
537 volume->type = vol->dwType;
538
539 if (!vol->dwVolLabelOfs)
540 return FALSE;
541 if (vol->dwSize <= vol->dwVolLabelOfs)
542 return FALSE;
543 INT len = vol->dwSize - vol->dwVolLabelOfs;
544
545 LPSTR label = (LPSTR)vol;
546 label += vol->dwVolLabelOfs; // FIXME: 0x14 Unicode
548
549 return TRUE;
550}
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 499 of file CShellLink.cpp.

500{
501 struct sized_chunk
502 {
503 DWORD size;
504 unsigned char data[1];
505 } *chunk;
506
507 TRACE("%p\n", stm);
508
509 DWORD size;
510 ULONG count;
511 HRESULT hr = stm->Read(&size, sizeof(size), &count);
512 if (FAILED(hr) || count != sizeof(size))
513 return E_FAIL;
514
515 chunk = static_cast<sized_chunk *>(HeapAlloc(GetProcessHeap(), 0, size));
516 if (!chunk)
517 return E_OUTOFMEMORY;
518
519 chunk->size = size;
520 hr = stm->Read(chunk->data, size - sizeof(size), &count);
521 if (FAILED(hr) || count != (size - sizeof(size)))
522 {
524 return E_FAIL;
525 }
526
527 TRACE("Read %d bytes\n", chunk->size);
528
529 *data = chunk;
530
531 return S_OK;
532}
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 851 of file CShellLink.cpp.

853{
855 LOCATION_INFO *loc;
856
857 TRACE("%p %s %p\n", stm, debugstr_w(path), volume);
858
859 /* figure out the size of everything */
860 DWORD label_size = WideCharToMultiByte(CP_ACP, 0, volume->label, -1,
861 NULL, 0, NULL, NULL);
862 DWORD path_size = WideCharToMultiByte(CP_ACP, 0, path, -1,
863 NULL, 0, NULL, NULL);
864 DWORD volume_info_size = sizeof(*vol) + label_size;
865 DWORD final_path_size = 1;
866 DWORD total_size = sizeof(*loc) + volume_info_size + path_size + final_path_size;
867
868 /* create pointers to everything */
869 loc = static_cast<LOCATION_INFO *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, total_size));
870 vol = (LOCAL_VOLUME_INFO*) &loc[1];
871 LPSTR szLabel = (LPSTR) &vol[1];
872 LPSTR szPath = &szLabel[label_size];
873 LPSTR szFinalPath = &szPath[path_size];
874
875 /* fill in the location information header */
876 loc->dwTotalSize = total_size;
877 loc->dwHeaderSize = sizeof(*loc);
878 loc->dwFlags = 1;
879 loc->dwVolTableOfs = sizeof(*loc);
880 loc->dwLocalPathOfs = sizeof(*loc) + volume_info_size;
881 loc->dwNetworkVolTableOfs = 0;
882 loc->dwFinalPathOfs = sizeof(*loc) + volume_info_size + path_size;
883
884 /* fill in the volume information */
885 vol->dwSize = volume_info_size;
886 vol->dwType = volume->type;
887 vol->dwVolSerial = volume->serial;
888 vol->dwVolLabelOfs = sizeof(*vol);
889
890 /* copy in the strings */
891 WideCharToMultiByte(CP_ACP, 0, volume->label, -1,
892 szLabel, label_size, NULL, NULL);
894 szPath, path_size, NULL, NULL);
895 *szFinalPath = 0;
896
897 ULONG count = 0;
898 HRESULT hr = stm->Write(loc, total_size, &count);
899 HeapFree(GetProcessHeap(), 0, loc);
900
901 return hr;
902}
#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 816 of file CShellLink.cpp.

817{
819 USHORT len;
820 DWORD count;
821
822 length = wcslen(str) + 1;
823 if (length > MAXUSHORT)
824 {
825 return E_INVALIDARG;
826 }
827
828 len = (USHORT)length;
829 HRESULT hr = stm->Write(&len, sizeof(len), &count);
830 if (FAILED(hr))
831 return hr;
832
833 length *= sizeof(WCHAR);
834
835 hr = stm->Write(str, (ULONG)length, &count);
836 if (FAILED(hr))
837 return hr;
838
839 return S_OK;
840}
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  )