winapi

Is user a member of the Administrators group

Sometimes it's important to know if application is running under account that is a member of the Administrators group. There're a few ways to accomplish that.

Obtaining DLL-specific version information

Most Windows Shell and common controls DLLs implement DllGetVersion function. It allows applications to obtain DLL-specific version information to make sure that required functionality in a DLL is implemented.
The Windows API support class is used to handle Windows API structures.

$SAMPLECODE$


#DEFINE DLLVER_PLATFORM_WINDOWS 1
#DEFINE DLLVER_PLATFORM_NT 2

Generate GUID

UDF below generates 128-bit GUID and returns it as a string in the format 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.

MSDN:

$SAMPLECODE$

FUNCTION GenerateGUID
LOCAL lcGUID, lcStrucGUID, lnSize
lcStrucGUID = SPACE (16)
lcGUID = SPACE (78)
lnSize = LEN(lcGUID)/2

Creating directory preserving name case

MSDN:

$SAMPLECODE$

File operations with Progressbar

It's based on the late Ed Rauh's code around SHFileOperation Win API and requires his Heap allocation class. It supports wild cards and shows standard Windows progress bar.

$SAMPLECODE$


* Copy file to different name
llSuccess = FileOpWithProgressbar("H:\TEMP\tord.dbf", "H:\TMP\TEST.dbf", "Copy")
* Copy with the same name
llSuccess = FileOpWithProgressbar("H:\TEMP\tord.dbf", "H:\TMP\", "Copy")
* Copy all dbf's

Windows limitations on file and path name

The limitations have been pulled from Windows SDK header file

$SAMPLECODE$

* Maximum length of full pathname
#define MAX_PATH 260
* Maximum length of path component
#define MAX_DIR 256
* Maximum length of file name component
#define MAX_FNAME 256
* Maximum length of extension component
#define MAX_EXT 256

Windows API support class

The class below simplifies use of Windows API function by providing methods to convert data between VFP types and Windows API types/structures

Most of the code was borrowed from Heap allocation class (clsheap) by late Ed Rauh.

$SAMPLECODE$

DEFINE CLASS WinApiSupport AS Custom

* Converts VFP number to the Long integer
FUNCTION Num2Long(tnNum)
LOCAL lcStringl
lcString = SPACE(4)

Using Sparse Files sample

Sparse files are only supported under Windows 2000 and later and the file must be on a volume that is NTFS 5.0 or later.

Setting the Backup and Restore Privileges

The backup and restore privileges are required of all backup and restore applications. These privileges can be programmatically set, and the following example can be used to set these privileges. Based on Setting the Backup and Restore Privileges

Pages

Subscribe to RSS - winapi