Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > VCL

Lost Password?

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-13-2018, 09:37 AM
lex lex is offline
Junior Member
 
Join Date: Feb 2012
Posts: 27
Default Dealing with PWChar

I'm ruffing this out, note
aShGetKnownFolderPath(CSIDL, 0, 0, PWChar(Result));
I've made result a buffer, and tried to load it.
whats a better way please?


HTML Code:
Function GetDefaultDir: String;
type
 TShGetKnownFolderPath = function(const rfid: TGUID; dwFlags: DWord; hToken: THandle; out ppszPath: PWideChar): HResult; stdcall;

var  ShGetKnownFolderPath: TShGetKnownFolderPath;
     Shell: HModule;
     I: Integer;
     CSIDL: TGuid;
//     Buffer: PWideChar;
CONST SHGFP_TYPE_CURRENT = 0;

 function aShGetKnownFolderPath(const rfid: TGUID; dwFlags: DWord; hToken: THandle; out ppszPath: PWideChar): HResult;
 begin
  Shell := LoadLibrary('shell32.dll');
//  Win32Check(Shell <> 0);
  try
   @ShGetKnownFolderPath := GetProcAddress(Shell, 'SHGetKnownFolderPath');
//   Win32Check(Assigned(ShGetKnownFolderPath));
   Result := ShGetKnownFolderPath(rfid, dwFlags, hToken, ppszPath);
  finally
   FreeLibrary(Shell);
  end;
 end;

 function GetSpecialFolder: string;
 begin
  CSIDL := StringToGuid('{ED4824AF-DCE4-45A8-81E2-FC7965083634}');
  SetLength(Result, MAX_PATH);
  aShGetKnownFolderPath(CSIDL, 0, 0, PWChar(Result));
  I := Pos(#0, Result);
  if I > 0 then SetLength(Result, pred(I));
 end;

begin
 Result := GetSpecialFolder;
End;
Reply With Quote
 

Tags
delphi 7

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:17 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.