src/Helpers.c
bool PathCreateDeskLnk(LPCWSTR pszDocument)
{
  WCHAR tchExeFile[MAX_PATH] = { L'\0' };
  WCHAR tchDocTemp[MAX_PATH] = { L'\0' };
  WCHAR tchArguments[MAX_PATH+16] = { L'\0' };
  WCHAR tchLinkDir[MAX_PATH] = { L'\0' };
  WCHAR tchDescription[64] = { L'\0' };

  WCHAR tchLnkFileName[MAX_PATH] = { L'\0' };

  IShellLink *psl;
  bool bSucceeded = false;
  BOOL fMustCopy;

  if (StrIsEmpty(pszDocument)) { return true; }

  // init strings
  GetModuleFileName(NULL,tchExeFile,COUNTOF(tchExeFile));
  PathCanonicalizeEx(tchExeFile, COUNTOF(tchExeFile));

  StringCchCopy(tchDocTemp,COUNTOF(tchDocTemp),pszDocument);
  PathQuoteSpaces(tchDocTemp);

  StringCchCopy(tchArguments,COUNTOF(tchArguments),L"-n ");
  StringCchCat(tchArguments,COUNTOF(tchArguments),tchDocTemp);

  GetKnownFolderPath(&FOLDERID_Desktop, tchLinkDir, COUNTOF(tchLinkDir));

  GetLngString(IDS_MUI_LINKDESCRIPTION,tchDescription,COUNTOF(tchDescription));

  // Try to construct a valid filename...
  if (!SHGetNewLinkInfo(pszDocument,tchLinkDir,tchLnkFileName,&fMustCopy,SHGNLI_PREFIXNAME))
    return false;

  if (SUCCEEDED(CoCreateInstance(&CLSID_ShellLink,NULL,
                                 CLSCTX_INPROC_SERVER,
                                 &IID_IShellLink,(void**)&psl)))
  {
    IPersistFile *ppf;

    if (SUCCEEDED(psl->lpVtbl->QueryInterface(psl,&IID_IPersistFile,(void**)&ppf)))
    {
      WORD wsz[MAX_PATH] = { L'\0' };

      /*MultiByteToWideCharEx(CP_ACP,MB_PRECOMPOSED,tchLnkFileName,-1,wsz,MAX_PATH);*/
      StringCchCopy(wsz,COUNTOF(wsz),tchLnkFileName);

      psl->lpVtbl->SetPath(psl,tchExeFile);
      psl->lpVtbl->SetArguments(psl,tchArguments);
      psl->lpVtbl->SetDescription(psl,tchDescription);

      if (SUCCEEDED(ppf->lpVtbl->Save(ppf,wsz,true)))
        bSucceeded = true;

      ppf->lpVtbl->Release(ppf);
    }
    psl->lpVtbl->Release(psl);
  }

  return(bSucceeded);

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


PathCreateDeskLnk () Purpose : Modified to create a desktop link to Notepad2
bool PathCreateDeskLnk(LPCWSTR pszDocument)
{
  WCHAR tchExeFile[MAX_PATH] = { L'\0' };
  WCHAR tchDocTemp[MAX_PATH] = { L'\0' };
  WCHAR tchArguments[MAX_PATH+16] = { L'\0' };
  WCHAR tchLinkDir[MAX_PATH] = { L'\0' };
  WCHAR tchDescription[64] = { L'\0' };
  WCHAR tchLnkFileName[MAX_PATH] = { L'\0' };
  IShellLink *psl;
  bool bSucceeded = false;
  BOOL fMustCopy;
  if (StrIsEmpty(pszDocument)) { return true; }
  GetModuleFileName(NULL,tchExeFile,COUNTOF(tchExeFile));
  PathCanonicalizeEx(tchExeFile, COUNTOF(tchExeFile));
  StringCchCopy(tchDocTemp,COUNTOF(tchDocTemp),pszDocument);
  PathQuoteSpaces(tchDocTemp);
  StringCchCopy(tchArguments,COUNTOF(tchArguments),L"-n ");
  StringCchCat(tchArguments,COUNTOF(tchArguments),tchDocTemp);
  GetKnownFolderPath(&FOLDERID_Desktop, tchLinkDir, COUNTOF(tchLinkDir));
  GetLngString(IDS_MUI_LINKDESCRIPTION,tchDescription,COUNTOF(tchDescription));
  if (!SHGetNewLinkInfo(pszDocument,tchLinkDir,tchLnkFileName,&fMustCopy,SHGNLI_PREFIXNAME))
    return false;
  if (SUCCEEDED(CoCreateInstance(&CLSID_ShellLink,NULL,
                                 CLSCTX_INPROC_SERVER,
                                 &IID_IShellLink,(void**)&psl)))
  {
    IPersistFile *ppf;
    if (SUCCEEDED(psl->lpVtbl->QueryInterface(psl,&IID_IPersistFile,(void**)&ppf)))
    {
      WORD wsz[MAX_PATH] = { L'\0' };
      StringCchCopy(wsz,COUNTOF(wsz),tchLnkFileName);
      psl->lpVtbl->SetPath(psl,tchExeFile);
      psl->lpVtbl->SetArguments(psl,tchArguments);
      psl->lpVtbl->SetDescription(psl,tchDescription);
      if (SUCCEEDED(ppf->lpVtbl->Save(ppf,wsz,true)))
        bSucceeded = true;
      ppf->lpVtbl->Release(ppf);
    }
    psl->lpVtbl->Release(psl);
  }
  return(bSucceeded);
}
bool PathCreateDeskLnk ( LPCWSTR pszDocument ) { WCHAR tchExeFile [ MAX_PATH ] = { L' \0 ' } ; WCHAR tchDocTemp [ MAX_PATH ] = { L' \0 ' } ; WCHAR tchArguments [ MAX_PATH + 16 ] = { L' \0 ' } ; WCHAR tchLinkDir [ MAX_PATH ] = { L' \0 ' } ; WCHAR tchDescription [ 64 ] = { L' \0 ' } ; WCHAR tchLnkFileName [ MAX_PATH ] = { L' \0 ' } ; IShellLink * psl ; bool bSucceeded = false ; BOOL fMustCopy ; if ( StrIsEmpty ( pszDocument ) ) { return true ; } GetModuleFileName ( NULL , tchExeFile , COUNTOF ( tchExeFile ) ) ; PathCanonicalizeEx ( tchExeFile , COUNTOF ( tchExeFile ) ) ; StringCchCopy ( tchDocTemp , COUNTOF ( tchDocTemp ) , pszDocument ) ; PathQuoteSpaces ( tchDocTemp ) ; StringCchCopy ( tchArguments , COUNTOF ( tchArguments ) , L" " ) ; StringCchCat ( tchArguments , COUNTOF ( tchArguments ) , tchDocTemp ) ; GetKnownFolderPath ( & FOLDERID_Desktop , tchLinkDir , COUNTOF ( tchLinkDir ) ) ; GetLngString ( IDS_MUI_LINKDESCRIPTION , tchDescription , COUNTOF ( tchDescription ) ) ; if ( ! SHGetNewLinkInfo ( pszDocument , tchLinkDir , tchLnkFileName , & fMustCopy , SHGNLI_PREFIXNAME ) ) return false ; if ( SUCCEEDED ( CoCreateInstance ( & CLSID_ShellLink , NULL , CLSCTX_INPROC_SERVER , & IID_IShellLink , ( void * * ) & psl ) ) ) { IPersistFile * ppf ; if ( SUCCEEDED ( psl -> lpVtbl -> QueryInterface ( psl , & IID_IPersistFile , ( void * * ) & ppf ) ) ) { WORD wsz [ MAX_PATH ] = { L' \0 ' } ; StringCchCopy ( wsz , COUNTOF ( wsz ) , tchLnkFileName ) ; psl -> lpVtbl -> SetPath ( psl , tchExeFile ) ; psl -> lpVtbl -> SetArguments ( psl , tchArguments ) ; psl -> lpVtbl -> SetDescription ( psl , tchDescription ) ; if ( SUCCEEDED ( ppf -> lpVtbl -> Save ( ppf , wsz , true ) ) ) bSucceeded = true ; ppf -> lpVtbl -> Release ( ppf ) ; } psl -> lpVtbl -> Release ( psl ) ; } return ( bSucceeded ) ; }
Name: PathCreateDeskLnk()
Purpose: Modified to create a desktop link to Notepad2
Name : PathCreateDeskLnk () Purpose : Modified to create a desktop link to Notepad2
// init strings // Try to construct a valid filename... /*MultiByteToWideCharEx(CP_ACP,MB_PRECOMPOSED,tchLnkFileName,-1,wsz,MAX_PATH);*/