Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Writing to INI file
How to obtain Content-Type value for a file type from the System Registry
Using the heap of the calling process to allocate memory blocks
Winsock: how to retrieve a service information corresponding to a port
Winsock: initializing the service in the VFP application
How to retrieve network parameters for the local computer (including Host name, Domain name, and DNS Server)
Testing serial ports
Class library providing access to the System Registry
Customizing the frame of top-level form: removing the standard frame (VFP9, Vista)
Enumerating network resources
How to enumerate terminal servers within the specified Windows domain
How to Start a Process as Another User (NT/XP/2K)
Obtaining addresses for the adapters on the local computer (Win XP/2003/Vista)
Shortcut Menu Class
URL: splitting into its component parts
GDI+: retrieving list of available image encoders and image decoders
Locking and unlocking file of a VFP table
Locking mouse and keyboard input for the VFP application
Placing an arbitrary rectangular area of main VFP window on the Clipboard
Simple MAPI: how to pick an email recipient from Outlook Express address book
Using Path functions from Shell Lightweight Utility APIs (shlapi.dll)
Adding and deleting User Accounts
CryptoAPI: Collection of Providers class
Displaying standard progress dialog box when copying files
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: 122  
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 (50.16.132.180)
3 sec.Example: 'Retrieving the name of the network resource associated with a local device'
4 sec.Function: 'SetBkMode'
45.67 min.Example: 'How to display advanced Task Dialog (Vista)'
2.37 hrs.Function: 'AssignProcessToJobObject'
Function group: 'Process and Thread'
3.36 hrs.Example: 'Retrieving local computer and user names'
 Example: 'Sending email messages with Simple MAPI'
 Function: 'CreateWindow'
4.33 hrs.Example: 'Using the LoadImage function to have a bitmap file loaded and displayed on VFP main window'
 Example: 'Creating the Save dialog box to specify the drive, directory, and name of a file to save'
 Example: 'Class library providing access to the System Registry'
Language: 'Visual Basic'
Google
Advertise here!