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

Function PathCreateDeskLnk

src/Helpers.c:1083–1129  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// Name: PathCreateDeskLnk() Purpose: Modified to create a desktop link to Notepad2 Manipulates:

Source from the content-addressed store, hash-verified

1081// Manipulates:
1082//
1083BOOL PathCreateDeskLnk ( LPCWSTR pszDocument )
1084{
1085 WCHAR tchExeFile[MAX_PATH];
1086 WCHAR tchDocTemp[MAX_PATH];
1087 WCHAR tchArguments[MAX_PATH + 16];
1088 WCHAR tchLinkDir[MAX_PATH];
1089 WCHAR tchDescription[64];
1090 WCHAR tchLnkFileName[MAX_PATH];
1091 IShellLink *psl;
1092 BOOL bSucceeded = FALSE;
1093 BOOL fMustCopy;
1094 if ( !pszDocument || lstrlen ( pszDocument ) == 0 ) {
1095 return TRUE;
1096 }
1097 // init strings
1098 GetModuleFileName ( NULL, tchExeFile, COUNTOF ( tchExeFile ) );
1099 lstrcpy ( tchDocTemp, pszDocument );
1100 PathQuoteSpaces ( tchDocTemp );
1101 lstrcpy ( tchArguments, L"-n " );
1102 lstrcat ( tchArguments, tchDocTemp );
1103 SHGetSpecialFolderPath ( NULL, tchLinkDir, CSIDL_DESKTOPDIRECTORY, TRUE );
1104 GetString ( IDS_LINKDESCRIPTION, tchDescription, COUNTOF ( tchDescription ) );
1105 // Try to construct a valid filename...
1106 if ( !SHGetNewLinkInfo ( pszDocument, tchLinkDir, tchLnkFileName, &fMustCopy, SHGNLI_PREFIXNAME ) ) {
1107 return ( FALSE );
1108 }
1109 if ( SUCCEEDED ( CoCreateInstance ( &CLSID_ShellLink, NULL,
1110 CLSCTX_INPROC_SERVER,
1111 &IID_IShellLink, &psl ) ) ) {
1112 IPersistFile *ppf;
1113 if ( SUCCEEDED ( psl->lpVtbl->QueryInterface ( psl, &IID_IPersistFile, &ppf ) ) ) {
1114 WORD wsz[MAX_PATH];
1115 /*MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,
1116 tchLnkFileName,-1,wsz,MAX_PATH);*/
1117 lstrcpy ( wsz, tchLnkFileName );
1118 psl->lpVtbl->SetPath ( psl, tchExeFile );
1119 psl->lpVtbl->SetArguments ( psl, tchArguments );
1120 psl->lpVtbl->SetDescription ( psl, tchDescription );
1121 if ( SUCCEEDED ( ppf->lpVtbl->Save ( ppf, wsz, TRUE ) ) ) {
1122 bSucceeded = TRUE;
1123 }
1124 ppf->lpVtbl->Release ( ppf );
1125 }
1126 psl->lpVtbl->Release ( psl );
1127 }
1128 return ( bSucceeded );
1129}
1130
1131
1132///////////////////////////////////////////////////////////////////////////////

Callers 1

MsgCommandFunction · 0.85

Calls 3

QueryInterfaceMethod · 0.80
SaveMethod · 0.80
ReleaseMethod · 0.45

Tested by

no test coverage detected