Using Win32 functions in Visual FoxPro Image Gallery
Memory Management
..msdn
CopyMemory
FillMemory
GetProcessHeap
GetProcessHeaps
GlobalAlloc
GlobalFree
GlobalLock
GlobalMemoryStatus
GlobalReAlloc
GlobalSize
GlobalUnlock
HeapAlloc
HeapCompact
HeapFree
HeapLock
HeapReAlloc
HeapSize
HeapUnlock
HeapValidate
HeapWalk
LocalAlloc
LocalFree
LocalSize
VirtualAllocEx
VirtualFreeEx
ZeroMemory
Code examples:
Accessing LSA Policy object (Local Security Authority)
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Adding and deleting User Accounts
Adding printer to the list of supported printers for the specified server
Adding user-defined items to the Control Menu of VFP form (requires VFP9)
Attaching menu to a top-level form
Browsing Windows Known Folders (Special Folders)
Compressing and decompressing files with Windows API Runtime Library routines
Converting command-line string to a set of Unicode argument strings (WinNT only)
Creating the Open dialog box to specify the drive, directory, and name of a file to open
Creating the Save dialog box to specify the drive, directory, and name of a file to save
Custom HttpRequest class (WinHTTP)
Deleting files into the Recycle Bin
Displaying dimmed window behind VFP top-level form
Displaying standard progress dialog box when copying files
Displaying system dialog that selects a folder
Dynamic strings implemented through VFP Custom class
Enumerating data formats currently available on the clipboard
Enumerating files opened on the network
Extensible Storage Engine class library
How to assemble an array of strings and pass it to external function
How to display a user-defined icon in the MessageBox dialog
How to display advanced Task Dialog (Vista)
How to display the Print property sheet
How to display the Properties dialog box for a file (ShellExecuteEx)
How to enumerate sessions and processes on a specified terminal server
How to enumerate terminal servers within the specified Windows domain
How to enumerate, add and delete shares on the local computer (WinNT/XP)
How to extract frames from AVI files
How to ping a remote site using ICMP API calls
How to prevent users from accessing the Windows Desktop and from switching to other applications
How to remove a directory that is not empty
How to write and read Window Properties for the specified window
Loading a string resource from an executable file
MapiSendMail class for Visual FoxPro application
Mapping and disconnecting network drives
Obtaining names of local and global groups for current user (WinNT/XP/2K)
Passing data records between VFP applications via the Clipboard
Printing Image File, programmatically set print page orientation to landscape
Reading and setting explicit Application User Model ID for the current process (Win7)
Reading entries from Event logs
Retrieving configuration information for the specified server (Win2000/XP)
Retrieving the command line for the VFP session
Sending email messages with Simple MAPI
Shortcut Menu Class
Starting a dialog box for connecting to network resources and passing input parameters
Storing the environment strings in cursor
URL: splitting into its component parts
Using Change Notification Objects to monitor changes to the printer or print server
Using WM_COPYDATA for interprocess communication (VFP9)
Windows Shell Icons displayed and exported to ICO files (Vista)
Winsock: connecting to a news server (NNTP, port 119)
Writing entries to custom Event Log
Accessing LSA Policy object (Local Security Authority)

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
 
#DEFINE STATUS_SUCCESS 0
#DEFINE POLICY_GET_PRIVATE_INFORMATION  4
#DEFINE POLICY_VIEW_LOCAL_INFORMATION   1
#DEFINE POLICY_VIEW_AUDIT_INFORMATION   2
#DEFINE POLICY_LOOKUP_NAMES             0x00000800
 
DO decl
 
*|typedef struct _LSA_OBJECT_ATTRIBUTES {
*|  ULONG Length;
*|  HANDLE RootDirectory;
*|  PLSA_UNICODE_STRING ObjectName;
*|  ULONG Attributes;
*|  PVOID SecurityDescriptor;
*|  PVOID SecurityQualityOfService;
*|} LSA_OBJECT_ATTRIBUTES, *PLSA_OBJECT_ATTRIBUTES; 24 bytes
 
LOCAL hPolicy, cAttributes, nResult, nFlag,;
    hSids, nSidCount, hDomains, hNames
hPolicy = 0
cAttributes = PADR(CHR(24), 24, Chr(0))
 
nFlag = POLICY_GET_PRIVATE_INFORMATION +;
    POLICY_VIEW_LOCAL_INFORMATION +;
    POLICY_VIEW_AUDIT_INFORMATION + POLICY_LOOKUP_NAMES
 
nResult = LsaOpenPolicy(Null, @cAttributes, nFlag, @hPolicy)
 
IF nResult <> STATUS_SUCCESS
    ? "LsaOpenPolicy Error code:", LsaNtStatusToWinError(nResult)
    RETURN
ENDIF
 
STORE 0 TO hSids, nSidCount
nResult = LsaEnumerateAccountsWithUserRight(hPolicy,;
    Null, @hSids, @nSidCount)
 
IF nResult <> STATUS_SUCCESS
    ? "Account Enumeration error:", LsaNtStatusToWinError(nResult)
    = LsaClose(hPolicy)
    RETURN
ENDIF
 
= ParseSids(hSids, nSidCount)
 
STORE 0 TO hDomains, hNames
nResult = LsaLookupSids(hPolicy, nSidCount, hSids, @hDomains, @hNames)
 
IF nResult <> STATUS_SUCCESS
    ? "Names Lookup error:", LsaNtStatusToWinError(nResult)
ELSE
    = ParseDomains(hDomains)
    = ParseNames(hNames, nSidCount)
    = LsaFreeMemory(hDomains)
    = LsaFreeMemory(hNames)
ENDIF
 
= LsaFreeMemory(hSids)
= LsaClose(hPolicy)
* end of main
 
PROCEDURE ParseSids(hMem, nCount)
    LOCAL cBuffer, nBufsize, nIndex, hSid, nSidLen
    nBufsize = nCount * 4
    cBuffer = Repli(Chr(0), nBufsize)
    CopyMemory(@cBuffer, hMem, nBufsize)
 
    CREATE CURSOR csSids (sidindex I, sidlen I, sidptr N(12))
    FOR nIndex=0 TO nCount-1
        hSid = buf2dword(SUBSTR(cBuffer, nIndex*4+1, 4))
        cMem = MemToStr(hSid, 4)
        ? buf2dword(cMem)
        nSidLen = GetLengthSid(hSid)
        INSERT INTO csSids VALUES (nIndex, nSidLen, hSid)
    ENDFOR
    GO TOP
    BROWSE NORMAL NOWAIT
    PosWindow("csSids", 1,1, 30, 60)
 
PROCEDURE ParseDomains(hMem)
#DEFINE TRUST_INFO_SIZE 12  && LSA_TRUST_INFORMATION
    LOCAL cBuffer, nCount, hArr, nArrSize, cTrustInfo,;
        nIndex, nOffs, nLen, nMaxlen, hName, hSid, cDomain
 
    cBuffer = MemToStr(hMem)
    nCount = buf2dword(SUBSTR(cBuffer, 1,4))
 
    hArr = buf2dword(SUBSTR(cBuffer, 5,4))
    nArrSize = nCount * TRUST_INFO_SIZE
    cTrustInfo = Repli(Chr(0), nArrSize)
    CopyMemory(@cTrustInfo, hArr, nArrSize)
 
    CREATE CURSOR csDomains (domainid I, domain C(32), sidlen I, sidptr N(12))
    FOR nIndex=0 TO nCount-1
        nOffs = nIndex * TRUST_INFO_SIZE + 1
        nLen = buf2word(SUBSTR(cTrustInfo, nOffs,2))
        nMaxlen = buf2word(SUBSTR(cTrustInfo, nOffs+2,2))
        hName = buf2dword(SUBSTR(cTrustInfo, nOffs+4,4))
        hSid = buf2dword(SUBSTR(cTrustInfo, nOffs+8,4))
        cDomain = Iif(nLen>0, STRCONV(MemToStr(hName, nLen), 6), "")
        nSidLen = GetLengthSid(hSid)
        INSERT INTO csDomains VALUES (nIndex, cDomain, nSidLen, hSid)
    ENDFOR
    GO TOP
    BROWSE NORMAL NOWAIT
    PosWindow("csDomains", 5,5, 20, 150)
 
PROCEDURE ParseNames(hMem, nCount)
#DEFINE TRANSL_NAME_SIZE 16  && LSA_TRANSLATED_NAME
    LOCAL cBuffer, nIndex, nOffs, nSidType, nLen, nMaxlen,;
        hName, cName, nDomainId
    cBuffer = MemToStr(hMem)
 
    CREATE CURSOR csNames (sidindex I, domainid I, sidtype I, sidname C(64))
    FOR nIndex=0 TO nCount-1
        nOffs = nIndex * TRANSL_NAME_SIZE + 1
        nSidType = buf2dword(SUBSTR(cBuffer, nOffs,4))
        nLen = buf2word(SUBSTR(cBuffer, nOffs+4,2))
        nMaxlen = buf2word(SUBSTR(cBuffer, nOffs+6,2))
        hName = buf2dword(SUBSTR(cBuffer, nOffs+8,4))
        nDomainId = buf2dword(SUBSTR(cBuffer, nOffs+12,4))
        cName = Iif(nLen>0, STRCONV(MemToStr(hName, nLen), 6), "")
        INSERT INTO csNames VALUES (nIndex, nDomainId, nSidType, cName)
    ENDFOR
    GO TOP
    BROWSE NORMAL NOWAIT
    PosWindow("csNames", 9, 9, 10, 170)
 
FUNCTION MemToStr(hMem, nBufsize)
    LOCAL cBuffer
    IF VARTYPE(nBufsize) <> "N"
        nBufsize = GlobalSize(hMem)
    ENDIF
    cBuffer = Repli(Chr(0), nBufsize)
    CopyMemory(@cBuffer, hMem, nBufsize)
RETURN cBuffer
 
PROCEDURE decl
    DECLARE INTEGER LsaOpenPolicy IN advapi32;
        STRING SystemName, STRING @ObjectAttributes,;
        INTEGER DesiredAccess, INTEGER @PolicyHandle
 
    DECLARE INTEGER LsaClose IN advapi32 INTEGER ObjectHandle
    DECLARE INTEGER LsaNtStatusToWinError IN advapi32 INTEGER nStatus
    DECLARE INTEGER LsaFreeMemory IN advapi32 INTEGER Buffer
 
    DECLARE INTEGER LsaEnumerateAccountsWithUserRight IN advapi32;
        INTEGER PolicyHandle, STRING UserRights,;
        INTEGER @EnumerationBuffer, INTEGER @CountReturned
 
    DECLARE INTEGER LsaLookupSids IN advapi32;
        INTEGER PolicyHandle, INTEGER nCount, INTEGER Sids,;
        INTEGER @ReferencedDomains, INTEGER @Names
 
    DECLARE RtlMoveMemory IN kernel32 As CopyMemory;
        STRING @Dest, INTEGER Source, INTEGER nLength
 
    DECLARE INTEGER GlobalSize IN kernel32 INTEGER hMem
    DECLARE INTEGER IsValidSid IN advapi32 INTEGER pSid
    DECLARE INTEGER GetLengthSid IN advapi32 INTEGER pSid
 
FUNCTION buf2dword(lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
    BitLShift(Asc(SUBSTR(lcBuffer, 2,1)),  8) +;
    BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +;
    BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)
 
FUNCTION buf2word(lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
       Asc(SUBSTR(lcBuffer, 2,1)) * 256
 
PROCEDURE PosWindow(cWindow, nRow1, nColumn1, nRow2, nColumn2)
    MOVE WINDOW (cWindow) TO nRow1, nColumn1
    SIZE WINDOW (cWindow) TO nRow2, nColumn2
 
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
5595 bytes  
Created: 2003-11-23 11:12:48  
Modified: 2003-11-23 11:16:55  
Visits in 7 days: 109  
Listed functions:
GetLengthSid
GlobalSize
IsValidSid
LsaClose
LsaFreeMemory
LsaLookupSids
LsaOpenPolicy
Printer friendly API declarations
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (50.19.155.235)
3 sec.Example: 'Reading security permissions for NTFS files and folders'
6 sec.Function: 'GlobalAlloc'
8.39 hrs.Function: 'PathIsNetworkPath'
10.32 hrs.Example: 'Obtaining the bounding rectangle for the specified device context'
12.96 hrs.Example: 'GDI+: rotating images using matrix transformations'
16.05 hrs.Example: 'Creating irregularly shaped FoxPro form using transparency color key'
18.21 hrs.Function: 'NetScheduleJobDel'
Function group: 'Network Management'
18.22 hrs.Example: 'Obtaining addresses for the adapters on the local computer (Win XP/2003/Vista)'
18.33 hrs.Function: 'OpenProcess'
Function group: 'Process and Thread'
19.43 hrs.Example: 'Pocket PC: custom RAPI class for operating with the Object Store Databases'
Google
Advertise here!