Wer kann mir sagen, was an folgender Übersetzung aus C falsch ist, bzw. warum Sie nicht funktioniert, bereits die Zeile hres := psl.QueryInterface(IID_IPersistFile,ppf); gibt einen Fehler zurück, vielleicht kann mir auch jemand sagen wie man den übesetzten kann (-2147221008)! Hier die funktion:
<p>
<pre>
//HRESULT CreateLink(LPCSTR lpszPathObj,
// LPSTR lpszPathLink, LPSTR lpszDesc)
function CreateLink(lpszPathObj : LPCSTR; lpszPathLink, lpszDesc : LPSTR):Boolean;
VAR
// HRESULT hres;
hres : HRESULT;
// IShellLink* psl;
psl : IShellLinkA;
ppf : IPersistFile;
//WORD wsz[MAX_PATH];
wsz : ARRAY[0..max_path] OF Word;
begin
result := false;
// Get a pointer to the IShellLink interface.
//hres = CoCreateInstance(&CLSID_ShellLink, NULL,
// CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
hres := CoCreateInstance(CLSID_ShellLink, Nil,
CLSCTX_INPROC_SERVER, IID_IShellLinkA, psl);
//if (SUCCEEDED(hres)) [
scode(
if SUCCEEDED(hres) then begin
// IPersistFile* ppf; s.o.
// Set the path to the shortcut target, and add the
// description.
//psl->lpVtbl->SetPath(psl, lpszPathObj);
psl.SetPath(lpszPathObj);
//psl->lpVtbl->SetDescription(psl, lpszDesc);
psl.SetDescription(lpszDesc);
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
//hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, &ppf);
hres := psl.QueryInterface(IID_IPersistFile,ppf);
//if (SUCCEEDED(hres)) [
if SUCCEEDED(hres) then begin
//WORD wsz[MAX_PATH];
// Ensure that the string is ANSI.
//MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1,
// wsz, MAX_PATH);
MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1,
@wsz, MAX_PATH);
// Save the link by calling IPersistFile::Save.
//hres = ppf->lpVtbl->Save(ppf, wsz, TRUE);
hres := ppf.Save(@wsz,True);
//ppf->lpVtbl->Release(ppf);
ppf._Release;
//???????????????
// ]
end;
//psl->lpVtbl->Release(psl);
psl._Release;
//???????????????????
// ]
end;
// return hres;
result := hres = 0;
end;
//zum testen
var
prog,
ziel,
desc : String;
initialization
prog := 'C:\test\EasyCalc.exe'+#0;
ziel := 'c:\test.LNK'+#0;//ob mit oder ohne .LNK gehts nich.
desc := 'Dies ist ein Wunder'+#0;
createLink(@prog[1],@ziel[1],@desc[1]);
</pre>
</p>
P.S. Es geht sicherlich auch anders, das ganze soll aber so klein wie möglich werden, ich möchte die bisher 34 KB für einen Sfx-Header nicht versauen ;-)
<p>
<pre>
//HRESULT CreateLink(LPCSTR lpszPathObj,
// LPSTR lpszPathLink, LPSTR lpszDesc)
function CreateLink(lpszPathObj : LPCSTR; lpszPathLink, lpszDesc : LPSTR):Boolean;
VAR
// HRESULT hres;
hres : HRESULT;
// IShellLink* psl;
psl : IShellLinkA;
ppf : IPersistFile;
//WORD wsz[MAX_PATH];
wsz : ARRAY[0..max_path] OF Word;
begin
result := false;
// Get a pointer to the IShellLink interface.
//hres = CoCreateInstance(&CLSID_ShellLink, NULL,
// CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
hres := CoCreateInstance(CLSID_ShellLink, Nil,
CLSCTX_INPROC_SERVER, IID_IShellLinkA, psl);
//if (SUCCEEDED(hres)) [
scode(
if SUCCEEDED(hres) then begin
// IPersistFile* ppf; s.o.
// Set the path to the shortcut target, and add the
// description.
//psl->lpVtbl->SetPath(psl, lpszPathObj);
psl.SetPath(lpszPathObj);
//psl->lpVtbl->SetDescription(psl, lpszDesc);
psl.SetDescription(lpszDesc);
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
//hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, &ppf);
hres := psl.QueryInterface(IID_IPersistFile,ppf);
//if (SUCCEEDED(hres)) [
if SUCCEEDED(hres) then begin
//WORD wsz[MAX_PATH];
// Ensure that the string is ANSI.
//MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1,
// wsz, MAX_PATH);
MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1,
@wsz, MAX_PATH);
// Save the link by calling IPersistFile::Save.
//hres = ppf->lpVtbl->Save(ppf, wsz, TRUE);
hres := ppf.Save(@wsz,True);
//ppf->lpVtbl->Release(ppf);
ppf._Release;
//???????????????
// ]
end;
//psl->lpVtbl->Release(psl);
psl._Release;
//???????????????????
// ]
end;
// return hres;
result := hres = 0;
end;
//zum testen
var
prog,
ziel,
desc : String;
initialization
prog := 'C:\test\EasyCalc.exe'+#0;
ziel := 'c:\test.LNK'+#0;//ob mit oder ohne .LNK gehts nich.
desc := 'Dies ist ein Wunder'+#0;
createLink(@prog[1],@ziel[1],@desc[1]);
</pre>
</p>
P.S. Es geht sicherlich auch anders, das ganze soll aber so klein wie möglich werden, ich möchte die bisher 34 KB für einen Sfx-Header nicht versauen ;-)
Comment