Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Registry Access WIN 7 2

Status
Not open for further replies.

Bryan - Gendev

Programmer
Jan 9, 2011
408
AU
A user of my software has suggested using a ramdisk to speed up the processing of the 'combined' table I create prior to reporting from the 3rd party app's tables which my app uses.

I have installed a ramdisk and tried this by manually changing my temp folder to the ramdisk. It makes a real difference.

So I need a way write the new drive path and I feel that the registry being always present and can be changed at will would be the way to go.

Thus my original code which creates a folder under ( in my case ) C:\Users\%username%\AppData\Roaming could easily use a new path in it if it can be read from the registry.(I would write my existing temp path as the default and compare when starting my app.)

Is there a code snippet that will show me how to

1 Create a new registry location under HKLM/software/myappname/
2 Write a new key value
3 Read the new key value.

I have already created an option on my options form to enable the user to select a drive letter from those existing on their PC. So I will put the registry writing code there.

Thanks in advance

GenDev
 
Hi GenDev,

A Ramdisk doesn't seem like a good idea under Windows. Back in DOS days, it was an excellent way of putting to use memory that would otherwise be unavailable. But Windows is able to take advantage of all the memory it can find, so a Ramdisk is probably counter-productive.

However, I realise that is not really what you are asking (you might also be interested in: thread184-1564223).

To answer your question, the easiest way of reading and writing the Registry is to use the Visual FoxPro Registry foundation class. There's a good sample form available: RegFox.SCX, in the Samples\Solution\WinAPI\ directory.

The Help topic "Registry Access Foundation Class" also has some useful information.

Hope this helps.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mike,

While I understand the superior memory management in WIN 7, in this instance I am talking about disk I/O.
The 'combined' table will be written to a disk to allow reuse next time the application is run.

This allows 'rapid' entry to the other parts of my application.

GenDev
 
Even disk I/O is so heavily buffered (between Windows and VFP itself) it won't benefit much from a RAM disk. In fact, I'd expect adding yet another buffer to the already buffered I/O stream to slow things down if anything.

If you want to speed things up, exclusive use is a magic elixir.

Since you're reading from 3rd party data to build your own combined data set, presumably you can use your own data exclusively.
 
Notwithstanding the above,I want to give the users a chance to vary the temp folder on their PCs.

I have been able to read the registry from a manually entered path which I have put where I want it in the registry but I cannot, at the moment see how to put that key and value in programmatically.

I learn a lot from examples so if I could be pointed to some clear instructions I would be grateful.

Thanks
Gendev
 
Gendev,

you already have been pointed to sample code by Mike Lewis: RegFox.SCX, in the Samples\Solution\WinAPI\ directory.

The title of the sample is "Read and write VFP Registry values", which can be found in task pane, solution samples.

This is specific about the foxpro options in the registry, but the general read write routines in the registry.prg are used there.

Bye, Olaf.
 
I have attempted to understand the above - as I said I just need a bit of help.

I am looking at the Read and Write Registry values in RegFox,scx. I only see _startup and Talk On or OFF. In the text box.

So I'm confused as to where I can see a code sample otherwise I'm and not any nearer to my need.

Thanks

GenDev
 
You know the debugger?

If you're too lazy to follow the calls within those two clicks, then simply add a breakpoint and single step through code until you get to the point the sample really writes to the registry.

It's always a good way to follow how something is done: use the debugger.

Bye, Olaf.
 
I do use the debugger all the time. Often in these forum messages I find it hard to get past the start post hence my request for help.

For example - why do you say 'If you're too lazy to follow the calls within those two clicks'?

I'm not too lazy to do anything once I know what to do!

So I'll presume the 2 clicks are on that regfox form where I only see _startup and Talk On or OFF.

Hopefully I'll be pointed in the right direction. many times I've been told to ask even the most simple questions here if I'm having problems.

Thanks

GenDev
 
So I'll presume the 2 clicks are on that regfox form where I only see _startup and Talk On or OFF.

If that's all you're seeing in the list then you're dealing with an incomplete Foxpro installation so there's no way anyone else can guess what else is missing.

HOWEVER, if the form runs without error then click the help button. That will take you to a help file entry showing the code -- ALL of the code -- necessary to make the form work, and that code also shows you where to find the PRG file used.

This is pretty basic stuff.
 
Colleague GenDev,

If your goal is to just to have some additional search path, or set the Temp directory - you can very well get by without modifying Windows Registry (the latter, by my own quite woeful experience, inevitably rise fierce ire of the customers' Sys Admins).
Here's the code I usually implement in similar cases:
Code:
IF !PEMSTATUS(_SCREEN, "glDevelop", 5)
   _SCREEN.AddProperty("glDevelop")
ENDIF ()

_SCREEN.glDevelop = (_VFP.StartMode == 0)

IF !PEMSTATUS(_SCREEN, "gsStartDir", 5)
	_SCREEN.AddProperty("gcStartDir")
ENDIF ()

_SCREEN.gcStartDir = ADDBS(SUBSTR(JUSTPATH(SYS(16)), ATC(":\", SYS(16)) - 1))

IF !PEMSTATUS(_SCREEN, "gcPrevPath", 5)
	_SCREEN.AddProperty("gcPrevPath")
ENDIF ()

_SCREEN.gcPrevPath = SET("Path")

IF !PEMSTATUS(_SCREEN, "gcPrevDefault", 5)
	_SCREEN.AddProperty("gcPrevDefault")
ENDIF ()

_SCREEN.gcPrevDefault = FULLPATH('')

IF !PEMSTATUS(_SCREEN, "gcPrevTmpPath", 5)
	_SCREEN.AddProperty("gcPrevTmpPath")
ENDIF (!PEMSTATUS(_SCREEN, "gcPrevTmpPath", 5))

_SCREEN.gcPrevTmpPath = ALLTRIM(GETENV("TMP"))
And then you can set the temp files location to whatever directory you wish.

HTH.

Regards,

Ilya
 
Gendev,

sorry, forget about the accusation. Once you're in the sourcecode of the foxreg sample form, you have all source code this form uses at hand. Yes, it's only about TALK ON/OFF and Refresh, but even only one of these ar a sufficient example on how to read/write the registry.

Are you familiar with the samples project at all? Did you open the sample in code at all?

The interesting line is here:
regfile = HOME(2)+"classes\registry.prg"

Look into that location:
CD HOME(2)+"classes\registry.prg"
MODIFY COMMAND registry.prg

Then you'll see.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top