Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to enumerate sessions and processes on a specified terminal server
Obtaining Shell32.dll version
Using the FindMediaType function
How to assemble an array of strings and pass it to external function
Scanning the hierarchy of child windows down from the main VFP window
Passing data records between VFP applications via the Clipboard
Reading parameters of streams in AVI file
Retrieving names for the registered clipboard formats
Using InternetSetFilePointer when resuming interrupted download from the Internet
Winsock: retrieving directory listing from an FTP server using passive data connection (FTP, port 21)
Writing to INI file
Drawing Windows predefined bitmaps using the LoadBitmap functions
Exporting DLL icon resources as .ICO files
Extended MessageBox Class
GDI+: sending image of FoxPro form to printer
Placing On-screen Alert on top of all windows
Starting a dialog box for connecting to network resources (mapping network drive)
Starting an external application in VFP using WinExec
Time in milliseconds represented as string (e.g. 1 hour 24 min 36 sec)
Windows Shell Icons displayed and exported to ICO files (Vista)
Downloading files from the FTP server using InternetReadFile
How to delete IE cookies, clear IE history and delete files in Temporary Internet Files directory
How to find the application associated with a file name
Programmatically removing submenus from VFP main menu
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: 83  
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 (107.22.156.205)
3 sec.Example: 'Class library providing access to the System Registry'
54.93 min.Function: 'ShowHTMLDialog'
54.97 min.Function: 'CountClipboardFormats'
Function group: 'Clipboard'
3.8 hrs.Function: 'NetMessageBufferSend'
 Example: 'Changing pitch and speed of a wave file'
5.44 hrs.Function: 'GetProfileString'
 Example: 'How to view icons stored in executable files (Icon Viewer)'
12.25 hrs.Example: 'Copying picture of the active form to the Clipboard using Enhanced Metafile API functions'
14.22 hrs.Example: 'How to run FoxPro application under different user name (impersonating user)'
 Example: 'Creating an Open dialog box to specify the drive, directory, and name of a file to open (Shell32 version)'
Google
Advertise here!