Einzelnen Beitrag anzeigen

MiKaEr
(Gast)

n/a Beiträge
 
#8

AW: Typumwandlung string -> PAnsiChar

  Alt 7. Mär 2012, 12:56
ich versuche gerade mit folgender funktion eine destkopverknüpfung zu speichern. jedoch geht meine pfadangabe bis auf ein simpes "C" komplett verloren.
wie erreiche ich es, dass die verknüpfung erstellt wird und der pfad erhlten bleibt?

Delphi-Quellcode:
function TGenFunctions.createLink(const AFileName, AParameter: string): Boolean;
var
 psl: IShellLink;
 ppf: IPersistFile;
 wsz: PWideChar;
begin
 Result := False;

 if SUCCEEDED(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_inPROC_SERVER, IID_IShellLinkA, psl)) then
  begin
   psl.SetPath(PWideChar(AFileName));
   psl.SetArguments(PChar(AParameter));
   psl.SetWorkingDirectory(PChar(ExtractFilePath(AFileName)));

   if SUCCEEDED(psl.QueryInterface(IPersistFile, ppf)) then
    begin
     GetMem(wsz, max_path * 2);
     try
      MultiByteToWideChar(CP_ACP, 0, 'C:\Users\testaccount\Desktop\test.lnk'), -1, wsz, max_path); // hier tritt der fehler auf und der hinweis "bedenkliche umwandlung"
      ppf.Save(wsz, True);
      Result := True;
     finally
      FreeMem(wsz, max_path * 2);
     end;
    end;
  end;
end;
  Mit Zitat antworten Zitat