Using Win32 functions in Visual FoxPro Image Gallery
System Information
..msdn
ExpandEnvironmentStrings
GetComputerName
GetComputerNameEx
GetComputerObjectName
GetCurrentHwProfile
GetKeyboardType
GetNativeSystemInfo
GetProductInfo
GetSysColor
GetSystemDirectory
GetSystemInfo
GetSystemMetrics
GetSystemRegistryQuota
GetSystemWow64Directory
GetUserName
GetUserNameEx
GetVersion
GetVersionEx
GetWindowsDirectory
IsNetworkAlive
SetComputerName
SetSysColors
SystemParametersInfo
Code examples:
How to display Windows On-Screen Keyboard
How to make application automatically close all documents it opened
Loading a string resource from an executable file
Obtaining the System and Windows folder names
Retrieving a handle to DLL and address of an exported function in it
Running MSDOS Shell as a child process with redirected input and output (smarter RUN command)
Using LoadLibrary
Using Shell for performing operations on 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: 129  
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 (23.22.76.170)
41.42 min.Example: 'Connecting a local device to a network resource'
Google
Advertise here!