|
This is declaration of that class:
class CRegKey
{
public:
CRegKey();
~CRegKey();
// Attributes
public:
operator HKEY() const;
HKEY m_hKey;
// Operations
public:
LONG SetValue(DWORD dwValue, LPCTSTR lpszValueName);
LONG QueryValue(DWORD& dwValue, LPCTSTR lpszValueName);
LONG QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount);
LONG QueryValue(BYTE *pbValue, LPCTSTR lpszValueName, DWORD* pdwCount);
LONG SetValue(LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
LONG SetValue(BYTE *pbValue, DWORD dwLength, LPCTSTR lpszValueName = NULL);
LONG SetKeyValue(LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
static LONG WINAPI SetValue(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass = REG_NONE, DWORD dwOptions = REG_OPTION_NON_VOLATILE, REGSAM samDesired = KEY_ALL_ACCESS, LPSECURITY_ATTRIBUTES lpSecAttr = NULL, LPDWORD lpdwDisposition = NULL);
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired = KEY_ALL_ACCESS);
LONG Close();
HKEY Detach();
void Attach(HKEY hKey);
LONG DeleteSubKey(LPCTSTR lpszSubKey);
LONG RecurseDeleteKey(LPCTSTR lpszKey);
LONG DeleteValue(LPCTSTR lpszValue);
};
and you can do this:
CRegKey reg;
reg.Open(HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Internet Settings");
and then
reg.QueryValue(...); //to read value
reg.SetValue(...) //to write value
|
|
|
|
|
I hope im not being a pain. I tryed this and it worked fine:
char* text;
//unsigned long* buffer;
DWORD* buffer;
unsigned long PerServer;
unsigned long Per1_0Server;
CRegKey reg;
reg.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
reg.QueryValue(PerServer,"MaxConnectionsPerServer");
but when i try to read a string (the windows version name) with:
reg.Open(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion");
reg.QueryValue(text,"ProductName",buffer);
i get an assertation error on the line "pdwCount!=null;" (in CRegKey) if i change buffer to anything using "buffer=(unsigned long*)999;" i dont get the error but i get no data.
Am i being stupid? I cant see where im going wrong.
An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
|
|
|
|
|
Lucky the code machine wrote:
Date:13:17 29 May '02
You had posted your answer to my message two minutes before I posted it.
|
|
|
|
|
Nice! Im in England so i guess something to do with that? Thanks a lot for that on registrys, i will try that. Looks good. Thanks
An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
|
|
|
|
|
I'm a fairly new Windows Programmer (C++). I was wondering if anyone had any good ideas on how saving of results work. For example, if I want to run a loop where a result is achieved every time, how could I save this data so that I could view and print all of the results together?
Trevor
|
|
|
|
|
Anonymous wrote:
For example, if I want to run a loop where a result is achieved every time, how could I save this data so that I could view and print all of the results together?
You can use an array. If your data is complicated, you can have an array of structs.
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
What I am trying to do may be considered mental mastrubation, but here is the question:
can I programmatically:
- count the number of items in a structure;
- get access to any of the items by its index (but not by its name) while presersing the names of these items.
The following example should make it clear:
I have a struct:
struct BBG_SECURITIES {
long nRecords; // Number of Entries
CStringArray sName; // Security Name
CStringArray sTicker; // Security Ticker
CStringArray sMarket; // Security Market
CStringArray sIssuer; // Issuer
CStringArray sCoupon; // Coupon
CStringArray sFrequency; // Frequency
CStringArray sMaturity; // Maturity Date
CStringArray sCurrency; // Currency
CStringArray sCountry; // Country
CStringArray sDBRS; // DBRS Bond Rating
CStringArray sSP; // S&P Bond Rating
CStringArray sMoody; // Moody's Bond Rating
CStringArray sBloomberg; // Bloomberg Composite Bond Rating
};
And I am lazy to write all of that each time:
m_strCurrentUniverse
.nRecords = NULL
.sName.SetSize(0)
.sTicker.SetSize(0)
.sMarket.SetSize(0)
.sIssuer.SetSize(0)
.sCoupon.SetSize(0)
.sFrequency.SetSize(0)
.sMaturity.SetSize(0)
.sCurrency.SetSize(0)
.sCoutry.SetSize(0)
.sDBRS.SetSize(0)
.sSP.SetSize(0)
.sMoody.SetSize(0)
.sBloomberg.SetSize(0);
What I want to set up some kind of a loop:
int nItems = GET ITEM COUNT IN THE STRUCT
for (i = 0; i < nItems; i++) {
xxx = GET STRUCT ITEM
xxx.SetSize(0);
}
Any thoughts?
Thank you.
|
|
|
|
|
Here are your options
1. Change to array
struct BBG_SECURITIES {
long nRecords; // Number of Entries
CStringArray* entries; // Security Name
BBG_SECURITIES()
{
entries = new CStringArray[13];
}
};
Looping then would be straight forward.
2. Unstructured and unsafe method
BBG_SECURITIES sec;
int nItems = (sizeof(BBG_SECURITIES) - sizeof(long))/sizeof(CStringArray);
CStringArray* pIter = (CStringArray*)&sec.sName;
for(int i = 0; i < nItems; i++)
{
pIter->SetSize(0);
pIter++;
}
|
|
|
|
|
Thanks for your reply:
* Wouldn't this fail if the structure is NOT empty (e.g., I have 5 elements in each CStringArray):
int nItems = (sizeof(BBG_SECURITIES) - sizeof(long))/sizeof(CStringArray);
* I am not quite sure what you are doing here:
CStringArray* pIter = (char*)&sec.sName;
sName is supoposed to be unknown.
* Any other reasons for calling this an unsafe method?
Thanks
|
|
|
|
|
Anton A. Loukine wrote:
CStringArray* pIter = (char*)&sec.sName;
Sorry a typo it should be,
CStringArray* pIter = &sec.sName;
|
|
|
|
|
Actually best thing for you would be to write a devstudio macro.
|
|
|
|
|
Can you elaborate on this a little bit. I am not familiar with macros and how they affect performance
|
|
|
|
|
Although others have posted very smart ways to have the task you're asking for accomplisedh automatically, please let me warn you'd better stay away of nifty tricks and stick to the boring sequence of resettings. If you ever add another item to your struct, you'd probably have to remember all the places scattered in your code where you put that. Instead, add a method to your struct like this:
struct BBG_SECURITIES {
...
void Reset()
{
nRecords = 0;
sName.SetSize(0);
...
}
}; and use it accordingly. You can do it even better: as CString s are constructed to the empty string by default, you can have it like:
struct BBG_SECURITIES {
...
BBG_SECURITIES()
{
nRecords = 0;
}
void Reset()
{
BBG_SECURITIES clean_struct;
(*this)=clean_struct;
}
}; The ability to inspect the contents of a class (its members, methods, etc.) is called reflection and alas is lacking in C++ (altough Java and C# do have it and it's magical for some uses.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Write a Reset() function that does all those calls. Then you can write:
m_strCurrentUniverse.Reset();
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
|
|
|
|
|
I'm experimenting with threads and I've found an example article here on codeproject.
The example I've found:
UINT CMyClass::threading(LPVOID p)
{
CMyClass * me = (CMyClass *)p;
me->threading();
return 0;
}
void CMyClass::threading()
{
}
I assume I've to add the functionality in threading() . It works fine.
But! this thread is inside CMyDialog. When I call UpdateData(TRUE/FALSE) the app crashes (calling ShowWindow for example, doesn't crash the app...)
Is there something I've overlooked? I'm new to c++threads.
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
frisco wrote:
UpdateData(TRUE/FALSE)
UpdateData should not be called from a different thread.
|
|
|
|
|
Should I change the controls directly then? And a ValidateWindow() afterwards?
Or is there another standard procedure for this?
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
Don't try UI stuff from a thread that does not own the window. Instead post or send a message to the main thread for the window and handle the message in that thread and do your stuff.
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Of course...
tnx, that should work fine
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
I have a list control in my dialog, call m_listctrl
How can I scroll it down 20 lines ?
How about this: ScrollWindow(0,20) ?
Hung Son
A student
i-g.hypermart.net
dlhson2001@yahoo.com
|
|
|
|
|
Use EnsureVisible( int nItem, BOOL bPartialOK );
|
|
|
|
|
Hi,
when you create a modal dialog, it looks like this:
<br />
CAboutDialog dlg;<br />
dlg.DoModal();<br />
Somewhere in the MFC code of the dialog there is a RunModalLoop() which looks like a PumpMessage loop. When I start a modal dialog with DoModal() , does this mean:
a) it will block in the RunModalLoop() loop until modal dialog is done,
b) and it will keep the message handling for the thread alive, b/c the modal dialog does take the role of the message pump?
I try to understand how it works, thx for help.
|
|
|
|
|
Both a) and b) are correct.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
the message loop will also reflect ( or send back ) some messages to the parent windows so the redraw can be done. ( i think )
max.
|
|
|
|
|
Yep, that's it. For instance, timer messages ar also fed to the main app even if it is blocked.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|