Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Saving local machine ODBC Registry Entries to XML file
Clipping mouse cursor area
Deleting files into the Recycle Bin
Obtaining addresses for the adapters on the local computer (Win XP/2003/Vista)
Running a regular FoxPro form while main VFP window is minimized
Using Extended MessageBox() Class
Converting Unicode data from the Clipboard to a character string using a given code page
GDI+: custom Slider control
GDI+: Storing DLL icon resources in image files
How to play a waveform sound (a WAV file in particular)
Retrieving the command line for the VFP session
Using FillMemory
An alternative way of setting Form.Closable to False
Creating a mailslot
GDI+: converting image file to another graphics format
Displaying the main Dial-Up Networking dialog box
Generating UUID values from numbers
How to save registry key including its subkeys and values to a file
Reading parameters of streams in AVI file
Retrieving information about all users currently logged on to the workstation (WinNT only)
Converting path to original case
Extracting the name and extension parts of a path string
How to enumerate terminal servers within the specified Windows domain
Using NetWkstaTransportEnum to obtain MAC Address of remote server
Saving local machine ODBC Registry Entries to XML 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
Versions:
click to open
Before you begin:
This is an example of resulting XMl file.
#DEFINE ERROR_SUCCESS       0
#DEFINE KEY_ALL_ACCESS      0xF003F
#DEFINE HKEY_CURRENT_USER   0x80000001
#DEFINE HKEY_LOCAL_MACHINE  0x80000002
#DEFINE HKEY_USERS          0x80000003

#DEFINE REG_SZ        1
#DEFINE REG_EXPAND_SZ 2
#DEFINE REG_BINARY    3
#DEFINE REG_DWORD     4
#DEFINE REG_MULTI_SZ  7

DO decl

LOCAL oReg
oReg = CreateObject("Tregister", HKEY_LOCAL_MACHINE, "Software\ODBC")

IF TYPE("oReg") = "O"
    oReg.SaveToFile("c:\temp\reg.xml")
ENDIF
* end of main

DEFINE CLASS Tregister As Custom
    oXml=.F.

PROCEDURE Init(hParentKey, cSubkey)
    LOCAL hKey, oXml, oKey
    hKey = 0
    IF RegOpenKeyEx(hParentKey, cSubkey, 0, KEY_ALL_ACCESS, @hKey) <> ERROR_SUCCESS
        RETURN .F.
    ENDIF

    THIS.oXml = CreateObject("Microsoft.XMLDOM")
    THIS.oXml.LoadXML(CHR(60) + "Registry" + CHR(47) + CHR(62))

    WITH THIS.oXml.documentElement()
        .SetAttribute("name", cSubkey)
        .SetAttribute("parent", hParentKey)
    ENDWITH

    oKey = CreateObject("Tkey", THIS.oXml, THIS.oXml.documentElement(), hKey)

PROCEDURE SaveToFile(cFilename)
    IF FILE(cFilename)
        DELETE FILE(cFilename)
    ENDIF
    THIS.oXml.Save(cFilename)
    = ShellExecute(0,"open", cFilename, "", "", 3)

ENDDEFINE

DEFINE CLASS Tkey As Custom
    oXml=.F.
    parentnode=.F.
    hKey=0

PROCEDURE Init(oXml, oParentNode, hKey)
    THIS.oXml = oXml
    THIS.parentnode = oParentNode
    THIS.hKey = hKey

    THIS.EnumValues
    THIS.EnumSubKeys

    = RegCloseKey(THIS.hKey)

PROCEDURE EnumValues
    LOCAL nIndex, nNameLen, nDataLen, nType, cName, cData, objProperty
    nIndex = 0
    DO WHILE .T.
        STORE 4096 TO nNameLen, nDataLen
        STORE Repli(Chr(0), nDataLen) TO cName, cData
        nType = 0

        IF RegEnumValue(THIS.hKey, nIndex, @cName, @nNameLen,;
            0, @nType, @cData, @nDataLen) <> ERROR_SUCCESS
            EXIT
        ENDIF

        cName = SUBSTR(cName, 1, AT(Chr(0),cName)-1)
        cData = SUBSTR(cData, 1, AT(Chr(0),cData)-1)

        IF Not EMPTY(cName)
            objProperty = THIS.oXml.CreateElement("Value")
            objProperty.SetAttribute("name", cName)
            objProperty.SetAttribute("type", nType)

            IF nType = REG_DWORD
                cData = buf2dword(PADR(cData,4,Chr(0)))
            ENDIF
            objProperty.SetAttribute("Data", cData)

            THIS.parentnode.AppendChild(objProperty)
        ENDIF
        nIndex = nIndex + 1
    ENDDO

PROCEDURE EnumSubKeys
    LOCAL nIndex, cBuffer, nResult, hKey, objSubnode, oKey
    nIndex = 0
    DO WHILE .T.
        cBuffer = Repli(Chr(0), 512)
        nResult = RegEnumKey(THIS.hKey, nIndex, @cBuffer, Len(cBuffer))
        IF nResult <> ERROR_SUCCESS
            EXIT
        ENDIF

        cBuffer = SUBSTR(cBuffer, 1, AT(Chr(0),cBuffer)-1)
        hKey = 0

        IF RegOpenKeyEx(THIS.hKey, cBuffer, 0, KEY_ALL_ACCESS, @hKey) = ERROR_SUCCESS
            objSubnode = THIS.oXml.CreateElement("Key")
            objSubnode.SetAttribute("name", cBuffer)
            THIS.parentnode.AppendChild(objSubNode)
            oKey = CreateObject("Tkey", THIS.oXml, objSubNode, hKey)
        ENDIF
        nIndex = nIndex + 1
    ENDDO

ENDDEFINE

PROCEDURE decl
    DECLARE INTEGER RegEnumKey IN advapi32;
        INTEGER hKey, INTEGER dwIndex, STRING @lpName,;
        INTEGER cchName

    DECLARE INTEGER RegOpenKeyEx IN advapi32;
        INTEGER hKey, STRING lpSubKey, INTEGER ulOptions,;
        INTEGER samDesired, INTEGER @phkResult

    DECLARE INTEGER RegEnumValue IN advapi32;
        INTEGER hKey, INTEGER dwIndex, STRING @lpValueName,;
        INTEGER @lpcValueName, INTEGER lpReserved, INTEGER @lpType,;
        STRING @lpData, INTEGER @lpcbData

    DECLARE INTEGER ShellExecute IN shell32;
        INTEGER hwnd, STRING lpOperation, STRING lpFile,;
        STRING lpParams, STRING lpDir, INTEGER nShowCmd

    DECLARE INTEGER RegCloseKey IN advapi32 INTEGER hKey

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)



User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
3835 bytes  
Created: 2003-01-30 09:28:53  
Modified: 2013-12-02 11:54:26  
Visits in 7 days: 147  
Listed functions:
RegCloseKey
RegEnumKey
RegEnumValue
RegOpenKeyEx
ShellExecute
Printer friendly API declarations
My comment:
There is no much sense in copying data from one Tree structure to another, except the showing a variety of information being stored in that part of the Windows Registry. Also it can give you an idea about adding new Data Source Names (DSN) programmatically.

An interesting MSDN article: Securing Windows to Prevent ODBC Tracing.

Try also Software\ODBC with a combination with HKEY_CURRENT_USER, and of course other parts of the Registry are available too.
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-2018 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.6.39), 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.240.119)
4 sec.Links
7 sec.Function: 'InternetGetLastResponseInfo'
Function group: 'Internet Functions (WinInet)'
10 sec.Articles
11 sec.Function: 'NetMessageBufferSend'
Function group: 'Network Management'
13 sec.Function: 'CeGetSpecialFolderPath'
Function group: 'Remote Application Programming (RAPI)'
16 sec.Solutions
19 sec.Example: 'How to start the screen saver and how to find whether the screen saver is active'
21 sec.Function: 'CreateWaitableTimer'
Function group: 'Synchronization'
28 sec.Links
31 sec.Function: 'getprotobyname'
Function group: 'Windows Sockets 2 (Winsock)'
Google
Advertise here!