Delphi Pages Forums

Delphi Pages Forums (http://www.delphipages.com/forum/index.php)
-   VCL (http://www.delphipages.com/forum/forumdisplay.php?f=4)
-   -   Dealing with PWChar (http://www.delphipages.com/forum/showthread.php?t=217720)

lex 01-13-2018 09:37 AM

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;


Norrit 01-15-2018 11:12 AM

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.

lex 01-15-2018 12:30 PM

Can you give me a help page and DLL that SHGetFolderPath belongs to please

Norrit 01-15-2018 01:01 PM

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

lex 01-15-2018 09:00 PM

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;

Norrit 01-16-2018 09:34 AM

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...

lex 01-17-2018 01:36 AM

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


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

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