Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > VCL

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-13-2018, 09:37 AM
lex lex is offline
Junior Member
 
Join Date: Feb 2012
Posts: 7
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
  #2  
Old 01-15-2018, 11:12 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,236
Default

I always used the SHGetFolderPath implementation.
Something like described here:
http://delphiprogrammingdiary.blogsp...rectories.html
And with this you pass de CSIDL (int) of the path you desire.
Reply With Quote
  #3  
Old 01-15-2018, 12:30 PM
lex lex is offline
Junior Member
 
Join Date: Feb 2012
Posts: 7
Default

Can you give me a help page and DLL that SHGetFolderPath belongs to please
Reply With Quote
  #4  
Old 01-15-2018, 01:01 PM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,236
Default

Have you read the link?
It's all explained there, including what using to add...

And even the SHGetFolderPath is a link where you can get more information about it
Not sure why you ask about a dll though
Reply With Quote
  #5  
Old 01-15-2018, 09:00 PM
lex lex is offline
Junior Member
 
Join Date: Feb 2012
Posts: 7
Default

For some reason its not supported on Delphi 7 I think its a new window 7 and up instrction

I do not have documentation from the net of: - CSIDL_COMMON_DOCUMENTS

I was able to read
SHGetFolderPath(HWND: hwndOwner; CSIDL: nFolder; hToken: THANDLE; dwFlags: DWORD; Out pszPath: PChar): HRESULT;

Last edited by lex; 01-15-2018 at 09:42 PM. Reason: update
Reply With Quote
  #6  
Old 01-16-2018, 09:34 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,236
Default

The definition for Delphi 7 could be something like:
Code:
function SHGetFolderPath(hwnd: HWND; csidl: Integer; hToken: THandle; dwFlags: DWORD; pszPath: PChar): HResult; stdcall; external 'shfolder.dll' name 'SHGetFolderPathA';
And the CSIDL_COMMON_DOCUMENTS can be found in the link I gave you
Quote:
CSIDL_COMMON_DOCUMENTS = $002e; { All Users\Documents }
Just define a const with this value

But I never expected a D7 user, since it's a dinosaur version, perhaps it's time to upgrade...
Reply With Quote
  #7  
Old 01-17-2018, 01:36 AM
lex lex is offline
Junior Member
 
Join Date: Feb 2012
Posts: 7
Default

seeing I'm writing my own method into windows the last data value I changed to pszPath: array of char):, rather than a PChar and this removes conflicts nicely. Thanks
Reply With Quote
Reply

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 10:32 PM.


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