Solved

How do I get System Path(Desktop) with Delphi2010?

Posted on 2011-03-22
6
3,961 Views
Last Modified: 2012-05-11
function GetSystemPath(Folder: Integer): string;
var
  PIDL: PItemIDList;
  Path: LPSTR;
  AMalloc: IMalloc;
begin
  Path := StrAlloc(MAX_PATH);
  SHGetSpecialFolderLocation(Application.Handle, Folder, PIDL);

  if SHGetPathFromIDList(PIDL, Path) then Result := Path;

  SHGetMalloc(AMalloc);
  AMalloc.Free(PIDL);
  StrDispose(Path);
end;

Open in new window



Usage:

Showmessage(GetSystemPath(CSIDL_DESKTOPDIRECTORY));

-----------------------------------------------------------------------------

I normaly use function above on Delphi7, How do i convert it into Delphi 2010?

Thanks Expert!

0
Comment
Question by:charin1904
  • 3
  • 3
6 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 35192906
You can use this under Delphi 2010...
function GetSysDir: string;
var
  Buffer: array[0..MAX_PATH + 1] of Char;
begin
  GetSystemDirectory(Buffer, MAX_PATH);
  Result := Buf;
end;

Open in new window

0
 
LVL 19

Assisted Solution

by:Thommy
Thommy earned 500 total points
ID: 35192940
If you absolutely want to use SHGetSpecialFolderLocation(), then try this...


function GetFolderLocation(Handle: HWnd; dir: Integer): string;
var
  pidl: PItemIDList;
  buffer: array[0..MAX_PATH] of Char;
begin
  if Succeeded(SHGetSpecialFolderLocation(Handle, dir, pidl)) then begin
    if SHGetPathFromIDList(pidl, buffer) then
      Result:=buffer;
    CoTaskMemFree(pidl);
  end
  else
    Result:=SysErrorMessage(GetLastError());
end;

Open in new window

0
 

Author Comment

by:charin1904
ID: 35192985
Hi Thommy,

I"m sorry, question not clear, I need a "Desktop" Folder not system's folder :)

It something like:   C:\Users\Charin\Desktop

How do i get it?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Accepted Solution

by:
charin1904 earned 0 total points
ID: 35193128
uses      ShlObj, ComObj, ActiveX,

procedure TForm1.Button1Click(Sender: TObject);
var
  PIDL: PItemIDList;
  Path: array[0..MAX_PATH] of Char;
begin
  SHGetSpecialFolderLocation(Handle, CSIDL_DESKTOP, PIDL);
  SHGetPathFromIDList(PIDL, Path);
  showmessage(StrPas(Path));
end;

Open in new window


OK., I got it!
0
 
LVL 19

Expert Comment

by:Thommy
ID: 35196495
Thank you for the points...

:o)))
0
 

Author Closing Comment

by:charin1904
ID: 35225431
I got solution guided by Thommy.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now