[BLACKBOX] Getting the User\Local Settings\Application Data\ path

From: [at]} <Marc>
Date: Thu, 24 Jan 2008 15:13:12 -0800

----boundary-LibPST-iamunique-1184923476_-_-
Content-type: text/plain

Hi all,

Occasionally I find that WinApi is missing some standard
Windows API functions and constants. For example, today
I wanted to get the path to the User's Local Settings\Application Data
folder. I couldn't find the relevant functions or constants in
WinApi, so I had to do some Google searches and figure out
how to make my own. For the benefit of anyone who wants to do
the same thing, the following works:


STEP 1: DEFINE THE CONSTANTS and FUNCTION ----------------------

MODULE MoreApi ["KERNEL32.dll"];

IMPORT WinApi;

CONST
  CSIDL_LOCAL_APPDATA* = 1CH;
  CSIDL_FLAG_CREATE* = 8000H;
  SHGFP_TYPE_CURRENT* = 0;
  SHGFP_TYPE_DEFAULT* = 1;

PROCEDURE SHGetFolderPath* ["SHELL32.dll", "SHGetFolderPathW"]
( hwndOwner: WinApi.HWND;
  nFolder: INTEGER;
  hToken: WinApi.HANDLE;
  dwFlags: INTEGER;
  VAR [nil] pszPath: ARRAY [untagged] OF CHAR ):
  INTEGER;

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

STEP 2: CALL THE NEW FUNCTION ----------------------------------

PROCEDURE Do*;
VAR
  result: INTEGER;
  path: ARRAY [untagged] WinApi.MAX_PATH OF CHAR;
BEGIN
  result := MoreApi.SHGetFolderPath
  ( WinApi.NULL,
    StatApi.CSIDL_LOCAL_APPDATA + StatApi.CSIDL_FLAG_CREATE,
    WinApi.NULL,
    StatApi.SHGFP_TYPE_CURRENT,
    path );

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

This was more difficult than I would have expected, because
I expected the functions and constants to be predefined!

Marc


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1184923476_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBc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yDQog
ICAgU3RhdEFwaS5DU0lETF9MT0NBTF9BUFBEQVRBICsgU3RhdEFwaS5DU0lETF9GTEFHX0NSRUFU
RSwgIFxwYXINCiAgICBXaW5BcGkuTlVMTCwgXHBhcg0KICAgIFN0YXRBcGkuU0hHRlBfVFlQRV9D
VVJSRU5ULFxwYXINCiAgICBwYXRoICk7XHBhcg0KXHBhcg0KLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLVxwYXINClxwYXINClRo
aXMgd2FzIG1vcmUgZGlmZmljdWx0IHRoYW4gSSB3b3VsZCBoYXZlIGV4cGVjdGVkLCBiZWNhdXNl
XHBhcg0KSSBleHBlY3RlZCB0aGUgZnVuY3Rpb25zIGFuZCBjb25zdGFudHMgdG8gYmUgcHJlZGVm
aW5lZCFccGFyDQpccGFyDQpNYXJjXHBhcg0KXHBhcg0KXHBhcg0KLS0tLVxwYXINClRvIHVuc3Vi
c2NyaWJlLCBzZW5kIGEgbWVzc2FnZSB3aXRoIGJvZHkgIlNJR05PRkYgQkxBQ0tCT1giIHRvIExJ
U1RTRVJWQExJU1RTLk9CRVJPTi5DSH19ACBMSVM=
----boundary-LibPST-iamunique-1184923476_-_---
Received on Fri Jan 25 2008 - 00:13:12 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:31:07 UTC