Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Gráficos (https://www.clubdelphi.com/foros/forumdisplay.php?f=8)
-   -   Problema con procedimiento y paso de parametros (https://www.clubdelphi.com/foros/showthread.php?t=58704)

MaMu 29-07-2008 15:38:47

Problema con procedimiento y paso de parametros
 
En la sección Trucos, me topé con este interesante truco para obtener cualquier thumbnail de la Shell, funciona perfecto, pero no logro adaptar un string a PWideChar, como para pasarle los parametros por variables, siempre me tira error, alguna idea?

Código Delphi [-]
 
uses ActiveX, ShlObj, ComObj;
type
 IExtractImage = interface ['{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}'] // http://msdn2.microsoft.com/en-us/lib...48(VS.85).aspx
  function GetLocation(pszPathBuffer: LPWSTR; cchMax: DWORD; 
 var pdwPriority: DWORD; const prgSize: SIZE; dwRecClrDepth: DWORD; 
 var pdwFlags: DWORD): HRESULT; stdcall;
  function Extract(var phBmpImage: HBITMAP): HRESULT; stdcall;
 end;
function GetThumbnail(lpPathName, lpFileName: PWideChar; Width, Height: Integer): TBitmap;
var
 Desktop, Folder: IShellFolder;
 ItemIDList: PItemIDList;
 Flags, Priority: Cardinal;
 ExtractImage: IExtractImage;
 Res: HRESULT;
 hBitmap: Windows.HBITMAP;
 Buffer: array[0..MAX_PATH-1] of WideChar;
 Size: TSize;
begin
 Result := nil;
 SHGetDesktopFolder(Desktop);
 if LongBool(Desktop.ParseDisplayName(0, nil, lpPathName, PDWORD(0)^, ItemIDList, PDWORD(0)^)) then Exit;
 Desktop.BindToObject(ItemIDList, nil, IShellFolder, Folder);
 CoTaskMemFree(ItemIDList);
 if LongBool(Folder.ParseDisplayName(0, nil, lpFileName, PDWORD(0)^, ItemIDList, PDWORD(0)^)) then Exit;
 Folder.GetUIObjectOf(0, 1, ItemIDList, IExtractImage, nil, ExtractImage);
 CoTaskMemFree(ItemIDList);
 if not Assigned(ExtractImage) then Exit; // TODO
 Size.cx := Width; Size.cy := Height; Priority := 0;
 Flags := $28{IEIFLAG_SCREEN+IEIFLAG_OFFLINE};
 Res := ExtractImage.GetLocation(Buffer, SizeOf(Buffer), Priority, Size, 24{pf32bit}, Flags);
 if (Res = NOERROR) or (Res = E_PENDING{IEIFLAG_ASYNC}) then
  begin
   if not LongBool(ExtractImage.Extract(hBitmap)) then
    begin
     Result := TBitmap.Create;
     Result.Handle := hBitmap;
    end;
  end;
end;

dec 29-07-2008 15:52:18

Hola,

Cuando hablemos de errores, es bien que se especifiquen los mensajes de error correspondientes, porque, esto ayudará, como se sabe, a encontrar una posible solución al problema. En este caso, y, si se trata sólo de convertir un "string" a "WideChar", si no me equivoco, es posible usar un "cast", sencillamente:

Código Delphi [-]
var
  s: string;
  wc: PWideChar;
begin
  s := 'This is a string';
  wc := PWideChar(s);
  (* ... *)
end;

MaMu 29-07-2008 22:48:24

SOLUCIONADO

El problema estaba en que en la funcion para obtener el thumbnails, el parametro esta apuntado hacia un pointer, por lo que la unica forma de poder pasarle los parametros correctamente, fue trabajando sobre el vector:

Código Delphi [-]
var MiWideChar:array[0..255] of WideChar;
     a,d,ruta:string;
     ar,di:PWideChar;
begin
   a:=ExtractFileName(Lista.Strings[w]);
   ar:=StringToWideChar((a),archivo,255);
   d:=ExtractFilePath(Lista.Strings[w]);
   di:=StringToWideChar(d,directorio,255);
   Image1.Picture.Assign(GetThumbnail(di,ar, 96, 96));
end;


La franja horaria es GMT +2. Ahora son las 03:37:57.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi