MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / PathCreateFavLnk

Function PathCreateFavLnk

src/Helpers.c:1141–1173  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// Name: PathCreateFavLnk() Purpose: Modified to create a Notepad2 favorites link Manipulates:

Source from the content-addressed store, hash-verified

1139// Manipulates:
1140//
1141BOOL PathCreateFavLnk ( LPCWSTR pszName, LPCWSTR pszTarget, LPCWSTR pszDir )
1142{
1143 WCHAR tchLnkFileName[MAX_PATH];
1144 IShellLink *psl;
1145 BOOL bSucceeded = FALSE;
1146 if ( !pszName || lstrlen ( pszName ) == 0 ) {
1147 return TRUE;
1148 }
1149 lstrcpy ( tchLnkFileName, pszDir );
1150 PathAppend ( tchLnkFileName, pszName );
1151 lstrcat ( tchLnkFileName, L".lnk" );
1152 if ( PathFileExists ( tchLnkFileName ) ) {
1153 return FALSE;
1154 }
1155 if ( SUCCEEDED ( CoCreateInstance ( &CLSID_ShellLink, NULL,
1156 CLSCTX_INPROC_SERVER,
1157 &IID_IShellLink, &psl ) ) ) {
1158 IPersistFile *ppf;
1159 if ( SUCCEEDED ( psl->lpVtbl->QueryInterface ( psl, &IID_IPersistFile, &ppf ) ) ) {
1160 WORD wsz[MAX_PATH];
1161 /*MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,
1162 tchLnkFileName,-1,wsz,MAX_PATH);*/
1163 lstrcpy ( wsz, tchLnkFileName );
1164 psl->lpVtbl->SetPath ( psl, pszTarget );
1165 if ( SUCCEEDED ( ppf->lpVtbl->Save ( ppf, wsz, TRUE ) ) ) {
1166 bSucceeded = TRUE;
1167 }
1168 ppf->lpVtbl->Release ( ppf );
1169 }
1170 psl->lpVtbl->Release ( psl );
1171 }
1172 return ( bSucceeded );
1173}
1174
1175
1176//=============================================================================

Callers 1

AddToFavDlgFunction · 0.85

Calls 3

QueryInterfaceMethod · 0.80
SaveMethod · 0.80
ReleaseMethod · 0.45

Tested by

no test coverage detected