[fpc-pascal]Win32: converting lptstr to string

Inpromptu inpromptu at operamail.com
Mon Apr 26 21:25:07 CEST 2004


 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;
       pszDisplayName:=@FPath;
       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, at 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
 
 
 
 
 
 
 > > >  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.


More information about the fpc-pascal mailing list