Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Finding the path to the VFP executable running
Obtaining names and positions for shortcuts located on the Windows Desktop
Obtaining provider name for a specific type of network
Reading and setting system access privileges for the current process
Using GetFileSize
Winsock: creating a socket that is bound to a specific service provider
A client for testing non-blocking Winsock server
Drawing a rectangle using Windows regular edges and borders
A procedure for setting file times
Converting an HTTP time/date string to a SYSTEMTIME structure
Drawing Windows frame controls using the DrawFrameControl function
Enumerating the subkeys of a user-specific key
Enumerating Volumes and Volume Mounting Points (NTFS)
How to browse and connect to printers on a network (WinNT)
How to retrieve version information for the specified file
Printing text on the main VFP window
Retrieving country-specific dialing information from the Windows Telephony list of countries
The DetectAutoProxyUrl function identifies the auto-config script location
Using mailslots to send messages on the network
WAV file player
Customizing the frame of top-level form: removing the standard frame (VFP9, Vista)
Drawing standard Windows icons
Finding out if the current user is the Guest account
GetFocus returns a HWND value
Loading a string resource from an executable file

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
 
DO declare
 
LOCAL lcSysDir, hModule, lFreeModule, lcBuffer, lnBufsize, ii, loPChar
lcSysDir = GetSysDir()
lFreeModule = .F.
hModule = GetHandle(lcSysDir + "\wininet.dll", @lFreeModule)
 
* try also:
* lcSysDir + "\mshtml.dll"
* lcSysDir + "\vbrun500.dll"
* lcSysDir + "\mapi32.dll"
* lcSysDir + "\comdlg32.dll"
* lcSysDir + "\syssetup.dll"
* lcSysDir + "\userenv.dll"
 
IF hModule <> 0
    CREATE CURSOR cs (id N(6), txt C(250))
    loPChar = CreateObject("PChar", Repli(Chr(0), 256))
 
    FOR ii=0 TO 4096
        lnBufsize = LoadString(hModule, ii, loPChar.GetAddr(), 1024)
        IF lnBufsize <> 0
            INSERT INTO cs VALUES (ii, SUBSTR(loPChar.GetValue(), 1, lnBufsize))
        ENDIF
    ENDFOR
 
    IF lFreeModule
        = FreeLibrary(hModule)
    ENDIF
 
    GO TOP
    BROWSE NORMAL NOWAIT
ENDIF
 
FUNCTION GetHandle(lcModuleName, lRelease)
    LOCAL hModule
    hModule = GetModuleHandle(lcModuleName)
    IF hModule <> 0
        lRelease = .F.
    ELSE
        lRelease = .T.
        hModule = LoadLibrary(lcModuleName)
    ENDIF
RETURN hModule
 
FUNCTION GetSysDir
    DECLARE INTEGER GetSystemDirectory IN kernel32;
        STRING @lpBuffer, INTEGER nSize
 
    LOCAL lcBuffer, lnResult
    lcBuffer = SPACE(250)
    lnResult = GetSystemDirectory(@lcBuffer, Len(lcBuffer))
RETURN Left(lcBuffer, lnResult)
 
IF nSizeRet <> 0
    lpBuffer = SUBSTR(lpBuffer, 1, nSizeRet)
    ? lpBuffer
ENDIF
 
PROCEDURE declare
    DECLARE INTEGER LoadString IN user32;
        INTEGER hInstance, INTEGER uID,;
        INTEGER lpBuffer, INTEGER nBufferMax
 
    DECLARE INTEGER LoadLibrary IN kernel32 STRING lpLibFileName 
    DECLARE INTEGER FreeLibrary IN kernel32 INTEGER hLibModule 
    DECLARE INTEGER GetModuleHandle IN kernel32 STRING lpModuleName
 
DEFINE CLASS PChar As Custom
    PROTECTED hMem
 
PROCEDURE Init(lcString)
    THIS.hMem = 0
    THIS.SetValue(lcString)
 
PROCEDURE Destroy
    THIS.ReleaseString
 
FUNCTION getAddr  && returns a pointer to the string
RETURN THIS.hMem
 
FUNCTION GetValue && returns string value
    LOCAL lnSize, lcBuffer
    lnSize = THIS.GetAllocSize()
    lcBuffer = SPACE(lnSize)
 
    IF THIS.hMem <> 0
        DECLARE RtlMoveMemory IN kernel32 As Heap2Str;
            STRING @, INTEGER, INTEGER
        = Heap2Str(@lcBuffer, THIS.hMem, lnSize)
    ENDIF
RETURN lcBuffer
 
FUNCTION GetAllocSize  && returns allocated memory size (string length)
    DECLARE INTEGER GlobalSize IN kernel32 INTEGER hMem
RETURN Iif(THIS.hMem=0, 0, GlobalSize(THIS.hMem))
 
PROCEDURE SetValue(lcString) && assigns new string value
#DEFINE GMEM_FIXED   0 
    THIS.ReleaseString
 
    DECLARE INTEGER GlobalAlloc IN kernel32 INTEGER, INTEGER
    DECLARE RtlMoveMemory IN kernel32 As Str2Heap;
        INTEGER, STRING @, INTEGER
 
    LOCAL lnSize
    lcString = lcString + Chr(0)
    lnSize = Len(lcString)
    THIS.hMem = GlobalAlloc(GMEM_FIXED, lnSize)
    IF THIS.hMem <> 0
        = Str2Heap(THIS.hMem, @lcString, lnSize)
    ENDIF
 
PROCEDURE ReleaseString  && releases allocated memory
    IF THIS.hMem <> 0
        DECLARE INTEGER GlobalFree IN kernel32 INTEGER
        = GlobalFree(THIS.hMem)
        THIS.hMem = 0
    ENDIF
ENDDEFINE
 
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
3032 bytes  
Created: 2001-12-13 21:01:00  
Modified: 2005-12-06 10:14:04  
Visits in 7 days: 82  
Listed functions:
FreeLibrary
GetModuleHandle
GetSystemDirectory
GlobalAlloc
GlobalFree
GlobalSize
LoadLibrary
LoadString
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 (54.226.5.29)
13.62 min.Example: 'Creating a window using CreateWindowEx function'
13.7 min.Example: 'Displaying bitmap using the AlphaBlend function'
17.42 hrs.Example: 'Playing WAV sounds simultaneously'
 Function: 'AttachVirtualDisk'
17.56 hrs.Function: 'SetDlgItemInt'
21.01 hrs.Example: 'How to extract frames from AVI files'
 
Function group: 'Shell Functions'
1 day(s)Example: 'How to delete IE cookies, clear IE history and delete files in Temporary Internet Files directory'
 Example: 'StrDup returns a pointer to the duplicate of a source VFP string'
 Function: 'NetGetDCName'
Google
Advertise here!