Archive

Posts Tagged ‘function’

How to Get the Windows Directory

December 15th, 1999 m3Rlin No comments

To found out the name of the Windows directory it’s best to use the Windows API GetWindowsDirectory() function.

Here’s the Delphi implementation:

uses Windows;
...
function GetWindowsDir: string;
const
(* The length of the directory buffer. Usually 64 or even 16 is enough :-)
**
** Must be DWORD type.
*)
  dwLength: DWORD = 255;
var
  pcWinDir: PChar;
begin
  GetMem(pcWinDir, dwLength);
  GetWindowsDirectory(pcWinDir, dwLength);
  Result := string(pcWinDir);
  FreeMem(pcWinDir, dwLength);
end;

How to Stop Your Program for a Period of Time

December 15th, 1999 m3Rlin No comments

The easiest way to stop execution of your program is to use the Windows API Sleep() function. The function stops the program for n milliseconds. The only problem is that this function does not properly support multitasking, so during this time your program will not process any Windows messages, so you may want to check out tip 4.17. This function can be very useful in shareware and demo programs ;-)

uses
  Windows;
...
  Sleep(10000); { Stops program for 10 seconds }