Win32 Api functios

Visitors counter:

 

Function name

Library

Description

GetComputerName

kernel32.dll

Retrieve computer system name

Sleep

kernel32.dll

Stop processing (sleep process) for specified number of miliseconds

GetSystemDirectory

kernel32.dll

Retrieve path to the system directory

GetTempPath

kernel32.dll

Retrieve temporary folder path

GetTempFileName

kernel32.dll

Generate unique temporary filename

GetUserName

advapi32.dll

Get logged user name

GetWindowsDirectory

kernel32.dll

Get windows directory

SHAddToRecentDoc

shell32.dll

Add last edited document into “Recent documents” folder

SHBrowseForFolder

shell32.dll

Open “browse for folder” dialog screen used to choose folder.

ShellExecute

shell32.dll

Execute program or file using windows mechanizm

FindFirstFile

kernel32.dll

Find first matching file in single directory

FindNextFile

kernel32.dll

Find next file using expresions

FindClose

kernel32.dll

Close handle opened by FindFirstFile function

GetDiskFreeSpace

kernel32.dll

Get user quota , free disk and total space on any disk

GetFullPathName

kernel32.dll

Append filename to the current directory

RemoveDirectory

kernel32.dll

Remove empty folder

GetEnvironmentVariable

kernel32.dll

Read system variable

SetEnvironmentVariable

kernel32.dll

Set system variable

 

 

 

 

 

 

GetComputerName

Returns computer system name as you seen it in Network Neighborhood

Declare:
//computer name
Function long GetComputerName(ref String lpBuffer , long nSize ) Library "kernel32.dll" Alias for "GetComputerNameA"


Sleep

Sleep process for specified number of miliseconds

Declare:
//sleep
Subroutine Sleep( long dwMilliseconds ) Library "kernel32.dll"

Execution:
//sleep process for 1 second
Sleep(1000)


GetSystemDirectory

Retrieve windows system directory eq. c:\WINNT\system32

Declare:
//system directory
Function long GetSystemDirectory(ref string lpBuffer , long ByVal )  Library "kernel32.dll" Alias for "GetSystemDirectoryA"

Execution:
ls_buffer= space(50)
li_ret = GetSystemDirectory( ls_buffer, 50 )
MessageBox("system directory", trim( ls_buffer ) )


GetTempPath

Retrieve path to the temporary folder of the system

Declare:
//temp path
Function long GetTempPath(long nBufferLength, ref string lpBuffer )  Library "kernel32.dll" Alias For "GetTempPathA"



GetTempFileName

Generate temporary and unique filename

Declare:
//temporary random file
Function long GetTempFileName(string lpszPath, string lpPrefixString, long wUnique, ref String lpTempFileName) Library "kernel32.dll" Alias for "GetTempFileNameA"
 

Execution:
//temporary file
li_ret = GetTempFileName(trim(ls_temppath), 'tmp', 0, ls_buffer)
MessageBox("temporary file", trim(ls_buffer))


GetUserName

Get user name that is currently logged to the system

Declare:
//user name
Function long GetUserName(ref string lpBuffer, ref long nSize )  Library "advapi32.dll" Alias for "GetUserNameA"
 

Execution:
//user name
ls_buffer = space(100)
li_ret = GetUserName(ref ls_buffer, 100 )
MessageBox("user name", trim(ls_buffer))


GetWindowsDirectory

Get windows directory eq. c:\WINNT

Declare:
//windows directory
Function long GetWindowsDirectory(ref String lpBuffer , long nSize ) Library "kernel32.dll" Alias For "GetWindowsDirectoryA"
 

Execution:
ls_buffer = space(50)
li_ret = GetWindowsDirectory( ls_buffer , 50 )
MessageBox("windows directory", trim(ls_buffer))


SHAddToRecentDocs

Declare:
//add last used document into document history
subroutine SHAddToRecentDocs( Long uFlags, String pv ) Library "shell32.dll"

Execution:
//add document to the last edited documents
SHAddToRecentDocs(2 , 'c:\custdata.txt' )


SHBrowseForFolder

Open system dialog for selecting dialog screen

Declare:
type BROWSEINFO from structure
long hwndOwner
long pidlRoot
string pszDisplayName
string lpszTitle
long ulFlags
long lpfn
long lParam
long iImage
end type

//browse for folder
Function long SHBrowseForFolder(ref BROWSEINFO lpbi )  Library "shell32.dll" Alias for "SHBrowseForFolderA"

Execution:
BROWSEINFO lstr_browserinfo
lstr_browserinfo.hwndOwner = Handle(parent)
lstr_browserinfo.pszDisplayName = space(300)
lstr_browserinfo.lpszTitle='test'
lstr_browserinfo.lpfn=0
SHBrowseForFolder( ref lstr_browserinfo )


|ShellExecute

Execute program attached to the file:

Declare:
//shell execute
Function long ShellExecute(long hwnd, string lpOperation , string lpFile , string lpParameters , string lpDirectory , long nShowCmd) Library "shell32.dll" Alias for "ShellExecuteA" 
 

Execution:
ShellExecute(Handle(parent), "open" , "iexplore" , "" , "" , 3 )


ShFileOperation

Copy, delete, move files using the standard windows dialog boxes (

Declare:
type SHFILEOPSTRUCT from structure
long hwnd
long wFunc
string pFrom
string pTo
integer pFlags
long fAnyOperationsAborted
long hNameMappings
string lpszProgressTitle
end type
//copy, rename, delete files
Function long SHFileOperation(ref SHFILEOPSTRUCT lpFileOp )  Library "shell32.dll" Alias for "SHFileOperationA"

FindFirstFile, FindNextFile

Declare:
type FILETIME from structure
long dwLowDateTime
long dwHighDateTime
end type

type win32_find_data from structure
long dwfileattributes
filetime ftcreationtime
filetime ftlastaccesstime
filetime ftlastwritetime
long nfilesizehigh
long nfilesizelow
long dwreserved0
long dwreserved1
char actercfilename[260]
char actercalternate[14]
end type
//find first file
Function long FindFirstFile(string lpFileName, ref WIN32_FIND_DATA lpFindFileData )  Library "kernel32.dll" Alias for "FindFirstFileA"
 

Execution:
long ll_ret
WIN32_FIND_DATA lstr_find_info , l_empty

ll_ret = FindFirstFile("C:\temp\*.txt", lstr_find_info )
If ll_ret = -1 Then 
  MessageBox("","there are no files C:\temp\*.txt")
  return
End If

MessageBox("first file founded",trim(lstr_find_info.cFileName) )

lstr_find_info = l_empty
//find next file
ll_ret = FindNextFile(ll_ret, lstr_find_info )
If ll_ret = 0 Then
  MessageBox("","there are no more files C:\temp\*.txt")
  return
End If

MessageBox("second file founded",trim(lstr_find_info.cFileName) )

FindClose

Declare:
//close
Function long FindClose(long hFindFile ) library "kernel32.dll"

GetDiskFreeSpaceEx

Declare:
//get disk free space
Function long GetDiskFreeSpaceEx(String lpDirectoryName , ref ULARGE_INTEGER lpFreeBytesAvailableToCaller , ref ULARGE_INTEGER lpTotalNumberOfBytes, ref ULARGE_INTEGER lpTotalNumberOfFreeBytes ) Library "kernel32.dll" Alias For "GetDiskFreeSpaceExA"


GetFileSize

GetFullPathName

Declare:
//get file path
Function long GetFullPathName(string lpFileName , long nBufferLength , ref string lpBuffer , string lpFilePart )   Library "kernel32.dll" Alias for "GetFullPathNameA"

Execution:
//get file path
String ls_buffer = space(255)
GetFullPathName('trala.txt' , 255, ls_buffer, '' )  
MessageBox("", "full path : "+ trim( ls_buffer))

RemoveDirectory:

Declare:
//remove directory
Function long RemoveDirectory(string lpPathName) Library "kernel32.dll" Alias for "RemoveDirectoryA"

GetEnvironmentVariable

Declare:
//get system variable
Function long GetEnvironmentVariable(string lpName , ref string lpBuffer , long nSize )  Library "kernel32.dll" Alias for "GetEnvironmentVariableA"

Execution:
string ls_buffer = space(255)
//get system variable
GetEnvironmentVariable('TEMP' , ls_buffer , 255 )
MessageBox("","temp path "+ trim(ls_buffer))

SetEnvironmentVariable

Declare:
//set system variable
Function long SetEnvironmentVariable(string lpName , string lpValue )  Library "kernel32.dll" Alias for "SetEnvironmentVariableA"

Execution:
string ls_buffer = space(255)

//set system variable
SetEnvironmentVariable('TEST' , 'tralalalal' )
//get system variable
GetEnvironmentVariable('TEST' , ls_buffer , 255 )
MessageBox("","added variable"+ trim(ls_buffer))

 


[Home] [Performance] [PB Tricks] [Resume] [Galery] [Contact] [Links]