Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > Аналог GetWindowsDirectory


Автор: NiJazz 3.1.2004, 13:16
Как средствами Delphi можно узнать директорию Windows?

Автор: Смайлик 3.1.2004, 15:11
Есть библиотека RxLib там есть такая функция.
Есть еще API функия (ниже ее описание) Если надо могу выдрать из RxLib их функцию.

Код
The GetWindowsDirectory function retrieves the path of the Windows directory. The Windows directory contains such files as Windows-based applications, initialization files, and Help files.

UINT GetWindowsDirectory(

   LPTSTR lpBuffer, // address of buffer for Windows directory
   UINT uSize  // size of directory buffer
  );


Parameters

lpBuffer

Points to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the Windows directory is the root directory. For example, if the Windows directory is named WINDOWS on drive C, the path of the Windows directory retrieved by this function is C:\WINDOWS. If Windows was installed in the root directory of drive C, the path retrieved is C:\.

uSize

Specifies the maximum size, in characters, of the buffer specified by the lpBuffer parameter. This value should be set to at least MAX_PATH to allow sufficient room in the buffer for the path.



Return Values

If the function succeeds, the return value is the length, in characters, of the string copied to the buffer, not including the terminating null character.
If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path.



PS Первый раз не ту функцию выдрал

Автор: NiJazz 3.1.2004, 15:18
Цитата
Есть еще API функия (ниже ее описание) Если надо могу выдрать из RxLib их функцию.

Ты тему поста читал?

Автор: p0s0l 3.1.2004, 15:29
NiJazz, а чем тебе GetWindowsDirectory не нравится ?
Код
var
 Buf : PChar;
begin
 GetMem (Buf, 1024);
 GetWindowsDirectory(Buf, 1024);
 Form1.Caption := Buf;
 FreeMem (Buf);
end;


Автор: Смайлик 3.1.2004, 15:33
Кстати, посмотрел в RxLib - там тоже через API. smile.gif см. выше

Автор: NiJazz 3.1.2004, 18:25
p0s0l, да всем нравится. В VC им пользовался. Не очень люблю API смешивать с функциями Delphi. И к тому же аналога malloc'а в делфе не знал. smile.gif

Автор: <Spawn> 3.1.2004, 18:25
Например, прочитать в реестре smile.gif :

Код
procedure TForm1.Button1Click(Sender: TObject);
var
 Reg : TRegistry;
begin
 Reg := TRegistry.Create;
 try
   Reg.RootKey := HKEY_LOCAL_MACHINE;
   if Reg.OpenKey('Software\Microsoft\Windows NT\CurrentVersion', False) then
     if Reg.ValueExists('SystemRoot') then
       ShowMessage(Reg.ReadString('SystemRoot'));
 finally
   FreeAndNil(Reg);
 end;
end;

Автор: NiJazz 3.1.2004, 18:27
Цитата
Например, прочитать в реестре  :

Ой, так слишком трудно... smile.gif Но всё равно спасибо за помощь. smile.gif
Так всё же нет в делфе такого средства?

Автор: Vit 3.1.2004, 21:12
В нвшем Faq есть функция нахождения всех системных папок, по поводу смешивания VCL и API - смешивай на здоровье, проблем нет.

Автор: NiJazz 3.1.2004, 22:50
Цитата
по поводу смешивания VCL и API - смешивай на здоровье, проблем нет.

Это понятно. Просто не люблю. Такое своеобразное "ФИ". smile.gif

Автор: <Spawn> 3.1.2004, 23:39
NiJazz Напиши себе функцию, в которой инкапсулируй вызов GetWindowsDirectory и забудь про эту АПИ smile.gif

Автор: Смайлик 4.1.2004, 14:55
Кроме как через API или реестр другого пути нет... }:&

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)