Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-04

Win32: converting lptstr to string

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Inpromptu

Hi

How do I convert a lptstr var (win32) to a string var ?

Thanks

Inpromptu

_____________________________________________________________ Web-based SMS services available at http://www.operamail.com. From your mailbox to local or overseas cell phones. Powered by Outblaze

Reply by email

Matt Emson
to Inpromptu
Hi How do I convert a lptstr var (win32) to a string var ?

lptstr is just a PChar. Use the usual method you use for PChar...

Y := StrPas( X );
Y := String(X);

Would probably both work in Delphi mode - though StrPas is more universal.

Reply by email

Marco van de Voort
to Matt Emson
Show quoted text 9 lines
> How do I convert a lptstr var (win32) to a string var ? lptstr is just a PChar. Use the usual method you use for PChar... Y := StrPas( X ); Y := String(X); Would probably both work in Delphi mode - though StrPas is more universal.

strpas will introduce a 255 char limit.

Reply by email

Inpromptu

Hi:

I was looking the demo sources, and I found c:\pp\demo\win32\edit.pp VERY interesting. So, i decide to try shBrowseForFolder instead of GetOpenFilename, but I don't know wath I'm doing wrong...

This is my humble little program... be nice with the criticims... !

 {----------begin of program------------}
 program myprogram;
 uses windows;
  const
      COINIT_APARTMENTTHREADED=2;{from
 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/cme_a2d_4oqc.asp }

var
myDir:browseinfo; {from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/structures/browseinfo.asp }

function CoInitializeEx(pvReserved:pointer;dwCoInit:dword):UINT;external 'ole32' name 'CoInitializeEx'; {from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/cmf_a2c_5iyg.asp }

procedure CoTaskMemFree(var pv:pointer);external 'ole32' name 'CoTaskMemFree'; {from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/cmf_a2c_63l1.asp }

 var
    Dir:browseinfo;
    fpath:string;
 {-------------------------------------------------------}
 function SelectDir:string;
 var
    items:lpitemidlist;
    aux:lptstr;
    aux2:string;
    i:integer;
 begin
   with myDir do
     begin
       HWndOwner := 0;{?????}
       pidlRoot :=null;
       ;
       lpszTitle:='Hello...';
       ulFlags:=0;
       {ulFlags:=??;}
       lpfn:=null;
       {bffcallback:=???;}
     end;
 i:=coinitializeex(null,COINIT_APARTMENTTHREADED);{following instructions from shBrowseForFolder}
 items:=shBrowseForFolder(@Dir);{from
 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shbrowseforfolder.asp}
 if not(shGetPathFromIDList(items,@aux)) then begin writeln('failed...');halt; end;
 aux2:=strpas(@aux);{hey !, lptstr to string was not the problem !!!}

{halt;}
{If you don't halt here, you'll get an Access violation...}

CoTaskMemFree(items);{following instructions from shBrowseForFolder example}

 SelectDir:=aux2;
 end;{function}
 {--------------------------------------------------------}
 begin
 writeln('Please, select a dir until this program crash:');
 writeln('You pick ',SelectDir);
 writeln('Please, pick a deeper dir, c:\program files\other\other\... or I will not crash...' );
 end.

{----------end of program------------}

Thank you very, very, very much !!!!!!

Inpromptu

Show quoted text 11 lines
> > How do I convert a lptstr var (win32) to a string var ? > > lptstr is just a PChar. Use the usual method you use for PChar... > > Y := StrPas( X ); > > Y := String(X); > > Would probably both work in Delphi mode - though StrPas is more universal. strpas will introduce a 255 char limit.
_____________________________________________________________ Web-based SMS services available at http://www.operamail.com. From your mailbox to local or overseas cell phones. Powered by Outblaze

Reply by email

Nikolai Zhubr
to Inpromptu

Hi,

Inpromptu wrote 16 lines
Hi: I was looking the demo sources, and I found c:\pp\demo\win32\edit.pp VERY interesting. So, i decide to try shBrowseForFolder instead of GetOpenFilename, but I don't know wath I'm doing wrong... This is my humble little program... be nice with the criticims... ! {----------begin of program------------} program myprogram; uses windows; const COINIT_APARTMENTTHREADED=2;{from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/cme_a2d_4oqc.asp } var myDir:browseinfo; {from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/structures/browseinfo.asp }

[trim]
Ok, enough advertising microsoft.com for now... ;-) See some working example below, hope it helps.
Don't forget to specify -Sd option.

Best regards, Nikolai Zhubr program SelDir; const shell32 = 'shell32.dll'; S_OK = $00000000; MAX_PATH = 260; BIF_RETURNONLYFSDIRS = $0001; type HWND = LongInt; BOOL = LongBool; PItemIDList = pointer; TBrowseinfo = record hwndOwner: HWND; pidlRoot: PItemIDList; pszDisplayName: PAnsiChar; { Return display name of item selected. } lpszTitle: PAnsiChar; { text to go in the banner over the tree. } ulFlags: longint; { Flags that control the return stuff } lpfn: pointer; lParam: longint; { extra info that's passed back in callbacks } iImage: longint; { output var: where to return the Image index. } end; __IMalloc_Alloc = function (__Self: pointer; cb: Longint): Pointer; stdcall; __IMalloc_Realloc = function (__Self: pointer; pv: Pointer; cb: Longint): Pointer; stdcall; __IMalloc_Free = procedure(__Self: pointer; pv: Pointer); stdcall; IMalloc = ^__IMalloc2; __IMalloc2 = ^__IMalloc; __IMalloc = record rsrv1, rsrv2, rsrv3: longint; Alloc: __IMalloc_Alloc; Realloc: __IMalloc_Realloc; Free: __IMalloc_Free; end; function SHBrowseForFolder(var lpbi: TBrowseInfo): PItemIDList; stdcall; external shell32 name 'SHBrowseForFolderA'; function SHGetPathFromIDList(pidl: PItemIDList; pszPath: PChar): BOOL; stdcall; external shell32 name 'SHGetPathFromIDListA'; function SHGetMalloc(var ppMalloc: IMalloc): longint; stdcall; external shell32 name 'SHGetMalloc'; function SelectDirectory(const Caption: string; const Root: String): string; var BrowseInfo: TBrowseInfo; Buffer: PChar; ItemIDList: PItemIDList; ShellMalloc: IMalloc; begin Result := ''; FillChar(BrowseInfo, SizeOf(BrowseInfo), 0); if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc nil) then begin Buffer := ShellMalloc^.Alloc(ShellMalloc, MAX_PATH); try with BrowseInfo do begin pidlRoot := nil; hwndOwner:= 0 ; pszDisplayName := Buffer; lpszTitle := PChar(Caption); ulFlags := BIF_RETURNONLYFSDIRS; end; ItemIDList := ShBrowseForFolder(BrowseInfo); if ItemIDList nil then begin ShGetPathFromIDList(ItemIDList, Buffer); ShellMalloc^.Free(ShellMalloc, ItemIDList); result := Buffer; end; finally ShellMalloc^.Free(ShellMalloc, Buffer); end; end; end; begin writeln ('Started...'); writeln ('Path = ', SelectDirectory('MyCaption', '')); end.

Reply by email