////////////////////////////////////////////////////////////////////////// Name: PathGetLnkPath() Purpose: Try to get the path to which a lnk-file is linked Manipulates: pszResPath
| 1007 | // Manipulates: pszResPath |
| 1008 | // |
| 1009 | BOOL PathGetLnkPath ( LPCWSTR pszLnkFile, LPWSTR pszResPath, int cchResPath ) |
| 1010 | { |
| 1011 | IShellLink *psl; |
| 1012 | WIN32_FIND_DATA fd; |
| 1013 | BOOL bSucceeded = FALSE; |
| 1014 | if ( SUCCEEDED ( CoCreateInstance ( &CLSID_ShellLink, NULL, |
| 1015 | CLSCTX_INPROC_SERVER, |
| 1016 | &IID_IShellLink, &psl ) ) ) { |
| 1017 | IPersistFile *ppf; |
| 1018 | if ( SUCCEEDED ( psl->lpVtbl->QueryInterface ( psl, &IID_IPersistFile, &ppf ) ) ) { |
| 1019 | WORD wsz[MAX_PATH]; |
| 1020 | /*MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED, |
| 1021 | pszLnkFile,-1,wsz,MAX_PATH);*/ |
| 1022 | lstrcpy ( wsz, pszLnkFile ); |
| 1023 | if ( SUCCEEDED ( ppf->lpVtbl->Load ( ppf, wsz, STGM_READ ) ) ) { |
| 1024 | if ( NOERROR == psl->lpVtbl->GetPath ( psl, pszResPath, cchResPath, &fd, 0 ) ) { |
| 1025 | bSucceeded = TRUE; |
| 1026 | } |
| 1027 | } |
| 1028 | ppf->lpVtbl->Release ( ppf ); |
| 1029 | } |
| 1030 | psl->lpVtbl->Release ( psl ); |
| 1031 | } |
| 1032 | // This additional check seems reasonable |
| 1033 | if ( !lstrlen ( pszResPath ) ) { |
| 1034 | bSucceeded = FALSE; |
| 1035 | } |
| 1036 | if ( bSucceeded ) { |
| 1037 | ExpandEnvironmentStringsEx ( pszResPath, cchResPath ); |
| 1038 | PathCanonicalizeEx ( pszResPath ); |
| 1039 | } |
| 1040 | return ( bSucceeded ); |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | /////////////////////////////////////////////////////////////////////////////// |
no test coverage detected