Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8756685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:08:09+00:00 2026-06-13T14:08:09+00:00

I am using Delphi XE2 and importing SHGetFolderPath from Shell32.dll. I am running windows

  • 0

I am using Delphi XE2 and importing SHGetFolderPath from Shell32.dll. I am running windows vista x64. When running SHGetFolderPathA The result is unclear.

I.E.:

uses
  Windows;

function SHGetFolderPath(hwnd: Cardinal; csidl: Integer; hToken: Cardinal; dwFlags: Cardinal; pszPath: PChar): Cardinal; stdcall;external 'Shell32.dll' name 'SHGetFolderPathA';

Var
  Path:Array [0..MAX_PATH] of Char;
  AppData:String;

begin
  SHGetFolderPath(0,$001A,0,0,@path[0]);
  MessageBox(0,Path,'a',0);
end.

The result is:

enter image description here

Versus using SHGetFolderPathW:

uses
Windows;

function SHGetFolderPath(hwnd: Cardinal; csidl: Integer; hToken: Cardinal; dwFlags: Cardinal; pszPath: PChar): Cardinal; stdcall;external 'Shell32.dll' name 'SHGetFolderPathW';

Var
  Path:Array [0..MAX_PATH] of Char;
  AppData:String;

begin
  SHGetFolderPath(0,$001A,0,0,@path[0]);
  MessageBox(0,Path,'a',0);
end.

The result clearly states the path to my AppData folder with no issue.

When running this same code on x32 Vista when using SHGetFolderPathA works just fine.

If someone could shine some light on why this is? I was under the impression the “W” api was usually for use on Unicode machines…?


Edit:

I am now using the following code, with the same error:

uses
  Windows;

function SHGetFolderPath(hwnd: HWND; csidl: Integer; hToken: THandle; dwFlags: DWord; pszPath: PAnsiChar): HRESULT; stdcall; external 'SHFolder.dll' name 'SHGetFolderPathA';

var
  path: array[0..MAX_PATH] of char;
begin
  SHGetFolderPath(0,$001A,0,0, @path[0]);
  MessageBox(0,path,'a',0);
end.

Final Edit:

Thank you all for the responses. The above declaration of SHGetFolderPath is fine. After looking through all responses, and taking in the information in each, I have come up with the following result:

uses
  Windows;

function SHGetFolderPath(hwnd: HWND; csidl: Integer; hToken: THandle; dwFlags: DWord; pszPath: PAnsiChar): HRESULT; stdcall; external 'shell32.dll' name 'SHGetFolderPathA';

var
  path: array[0..MAX_PATH] of ansichar;
  xRes:String;
begin
  If SHGetFolderPath(0,$001A,0,0, @path[0]) = S_OK Then Begin
    xRes := Path;
    MessageBox(0,PWideChar(xRes),'Result',0);
  End Else
    MessageBox(0,'An error has occurred.','Result',0);
end.

The resulting messagebox correctly displays the path to my AppData path.

Thanks again for all of the responses.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:08:10+00:00Added an answer on June 13, 2026 at 2:08 pm

    You declared the final parameter of SHGetFolderPath as having type PChar. In Delphi 2009 and later (which includes your version, Delphi XE2), PChar is an alias for PWideChar, yet you told Delphi to link your declared function to the “A” version, which expects AnsiChar characters.

    When declaring functions that are sensitive to the character type, I recommend not using PChar at all. Explicitly use either PWideChar or PAnsiChar.

    The “A” and “W” suffixes aren’t about which kind of machine the program runs on. All supported versions of Windows are Unicode now — the last non-Unicode version was Windows ME. The “A” and “W” refer to the character type of the arguments.

    As for why your code worked on the 32-bit version of Vista when it fails on the 64-bit version, I have no explanation. Maybe you’re just lucky and the OS did some conversions that happened to work out OK in your case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Delphi XE2 and attempting to upgrade our usb comms dll to
Using Delphi XE on Win7 x64, have Jedi Class Library ver. 3.45, and 7z.dll
I'm using a C dll in a Delphi XE2 program without problem. One of
I'm using Delphi-XE2 Enterprise, SQLServer 2008 R2 on Windows Server 2008 R2. When a
Using Delphi XE2, Indy 10 that ships with it and OpenSSL dll's version 1.0.1c.
Using Delphi XE2 on Win 7 64 bit creating a 32 bit app... In
I'm currently using delphi xe2. well the firemonkey part of it. I use to
I am using Delphi XE2 to communicate with a fairly large SOAP service. I've
I have developed an database application with Delphi XE2 using an Access DB, now
I'm using Delphi 2010 on Windows 7 and have a problem with single quotes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.