Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Enumerating data formats currently available on the clipboard
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Winsock: sending email messages (SMTP, port 25)
Mapping and disconnecting network drives
Winsock: retrieving directory listing from an FTP server using passive data connection (FTP, port 21)
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Custom GDI+ class
Converting Unicode data from the Clipboard to a character string using a given code page
Disk in drive A:
How to display the Properties dialog box for a file (ShellExecuteEx)
Enumerating network resources
Detecting changes in connections to removable drives (VFP9)
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
How to download a file from the FTP server using FtpGetFile
Using EnumPrinters function to enumerate locally installed printers
How to play AVI file on the _screen
Retrieving the name of the network resource associated with a local device
Creating a console window for Visual FoxPro application
Custom HttpRequest class (WinHTTP)
Running MSDOS Shell as a child process with redirected input and output (smarter RUN command)
Custom FTP Class for Visual FoxPro application
How to put a horizontal text scrolling on the form (a news line)
Deleting files into the Recycle Bin
Saving HKEY_LOCAL_MACHINE\\Software\\ODBC Registry Entries to an 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: 2009-01-03 15:26:33  
Visits in 7 days: 74  
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-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.17.109.248)
4 sec.Example: 'Enhanced GetFont dialog'
21.72 min.Function: 'CeFindFirstFile'
1.26 hrs.Function: 'SetDlgItemInt'
 Example: 'Reading metrics for the currently selected font'
 Example: 'Obtaining heap handles and enumerating memory blocks for the current VFP session (WinNT only)'
2.76 hrs.Function: 'getsockopt'
8.47 hrs.Example: 'Scanning the hierarchy of child windows down from the main VFP window'
 Example: 'Retrieving local computer and user names'
 Function: 'SQLGetInfo'
20.1 hrs.Function: 'CreateCompatibleBitmap'
Google
Advertise here!