Solved

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

Posted on 2011-03-22
6
4,488 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

752 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