|
RegCreateKey [^] or RegCreateKeyEx [^]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks,
Yes, I'm aware of that, but, when I write:
RegCreateKeyEx(HKEY_LOCAL_MACHINE,"Software\\MyCompany\\Product\\,
0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&Key,NULL)
and then
RegSetValue(Key,"Path",REG_SZ,"C:\\MyDir",cbData);
I end up with:
HKEY_LOCAL_MACHINE\\Software\\MyCompany\\Product\\Path\\
Default=C:\\MyDir
I want to end up with:
HKEY_LOCAL_MACHINE\\Software\\MyCompany\\Product\\Path=C:\\MyDir
I.e. I want to create a Leaf named "Path", I get a Branch named Path
Bram van Kampen
|
|
|
|
|
Bram van Kampen wrote: I want to end up with:
HKEY_LOCAL_MACHINE\\Software\\MyCompany\\Product\\Path=C:\\MyDir
I.e. I want to create a Leaf named "Path", I get a Branch named Path
RegCreateKeyEx(HKEY_LOCAL_MACHINE,"Software\\MyCompany\\,
0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&Key,NULL)
RegSetKeyValue(key, "Product", "Path", REG_SZ, "C:\\MyDir",cbData);
|
|
|
|
|
Thanks!
yes, Thats's great! That function is oly four days old.
Requires Vista though. There must be another way which works in XP.
Bram van Kampen
|
|
|
|
|
RegSetValueEx ?
RegCreateKeyEx(HKEY_LOCAL_MACHINE,"Software\\MyCompany\\Product\\,
0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&Key,NULL)
and then
RegSetValueEx (Key,"Path", 0, REG_SZ,"C:\\MyDir", cbData);
|
|
|
|
|
|
how can i capture a id from a clicked button, in a game
i search and found only things for classes and dialogs, but not for a game
i want to captude an id from the Flight Simulator, some buttons and controls
how can i do it?
tks
|
|
|
|
|
u mean ID of control in a game UI? usually games use their own GUI system, i don't think it behaves like dialog controls to give an ID.
|
|
|
|
|
I'm trying to complete the code for the following program, learning switch statements. But my text shows very little in the way of examples, and I just don't know where to go here. I started to try it, but just don't know. Can somebody PLEASE help? Thanks.
// **************************************************************************
//
// Astrology.cpp
//
// Prompts for the user's birthday and returns the user's
// astrological sign.
// **************************************************************************
#include <iostream>
int getMonth();
// Precondition: User will enter birth month
// Postcondition: Returns 1 <= birth month <= 12
int getDay();
// Precondition: User will enter birth day
// Postcondition: Returns 1 <= birth day <= 31
int getSign(int month, int day);
// Precondition: 1 <= month <= 12, 1 <= day <= 31
// Postcondition: Returns integer corresponding to astrological sign for
// given month and day starting with Capricorn = 1.
int main()
{
using namespace std;
int month;
int day;
//
// Get birth month and day.
//
month = getMonth();
day = getDay();
//
// Determine and print the user's sign
//
cout << "Your sign is ";
// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------
switch (getSign)
{
case 1:
if ((month == 1) && (1 <= day <= 19))
cout << "Capricorn.";
break;
}
// --------------------------------
// --------- END USER CODE --------
// --------------------------------
cout << endl;
}
int getMonth()
{
using namespace std;
int month;
cout << "Enter the month of your birthday (1-12): ";
cin >> month;
while ((month < 1) || (month > 12))
{
cout << "Month must be between 1 and 12; please re-enter: ";
cin >> month;
}
return month;
}
int getDay()
{
using namespace std;
int day;
cout << "Enter the day of your birthday (1-31): ";
cin >> day;
while ((day < 0) || (day > 31))
{
cout << "Day must be between 1 and 31; please re-enter: ";
cin >> day;
}
return day;
}
|
|
|
|
|
But I do need some advice on what to do to give the user an option to continue using the program or to exit. My completed code is below. Thanks.
// **************************************************************************
//
// Astrology.cpp
//
// Prompts for the user's birthday and returns the user's
// astrological sign.
// **************************************************************************
#include <iostream>
int getMonth();
// Precondition: User will enter birth month
// Postcondition: Returns 1 <= birth month <= 12
int getDay();
// Precondition: User will enter birth day
// Postcondition: Returns 1 <= birth day <= 31
int getSign(int month, int day);
// Precondition: 1 <= month <= 12, 1 <= day <= 31
// Postcondition: Returns integer corresponding to astrological sign for
// given month and day starting with Capricorn = 1.
int main()
{
using namespace std;
int month;
int day;
//
// Get birth month and day.
//
month = getMonth();
day = getDay();
//
// Determine and print the user's sign
//
cout << "Your sign is ";
// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------
switch (month)
{
case 1:
if (day <= 19)
cout << "Capricorn.";
else
cout <<"Aquarius.";
break;
case 2:
if (day <= 18)
cout << "Aquarius.";
else
cout <<"Pisces.";
break;
case 3:
if (day <= 20)
cout << "Pisces.";
else
cout <<"Aries.";
break;
case 4:
if (day <= 19)
cout << "Pisces.";
else
cout <<"Taurus.";
break;
case 5:
if (day <= 20)
cout << "Taurus.";
else
cout <<"Gemini.";
break;
case 6:
if (day <= 20)
cout << "Gemini.";
else
cout <<"Cancer.";
break;
case 7:
if (day <= 22)
cout << "Cancer.";
else
cout <<"Leo.";
break;
case 8:
if (day <= 22)
cout << "Leo.";
else
cout <<"Virgo.";
break;
case 9:
if (day <= 22)
cout << "Virgo.";
else
cout <<"Libra.";
break;
case 10:
if (day <= 22)
cout << "Libra.";
else
cout <<"Scorpio.";
break;
case 11:
if (day <= 21)
cout << "Scorpio.";
else
cout <<"Sagittarius.";
break;
case 12:
if (day <= 21)
cout << "Sagittarius.";
else
cout <<"Capricorn.";
break;
}
// --------------------------------
// --------- END USER CODE --------
// --------------------------------
cout << endl;
}
int getMonth()
{
using namespace std;
int month;
cout << "Enter the month of your birthday (1-12): ";
cin >> month;
while ((month < 1) || (month > 12))
{
cout << "Month must be between 1 and 12; please re-enter: ";
cin >> month;
}
return month;
}
int getDay()
{
using namespace std;
int day;
cout << "Enter the day of your birthday (1-31): ";
cin >> day;
while ((day < 0) || (day > 31))
{
cout << "Day must be between 1 and 31; please re-enter: ";
cin >> day;
}
return day;
}
|
|
|
|
|
Use an Endles for loop in your main.
Bram van Kampen
|
|
|
|
|
See www.plusplus.com for good info about c++.
|
|
|
|
|
Hi.
I'm running Windows Vista Home Basic and Visual Studio 2005 Team Suite.
Ok.
Now I have started a new MFC project, as usually, where I will connect to a SQL Server database, running in the same PC.
As always I did, I use ADO in the following way:
#import "c:\Program Files\Common\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
The problem is that file is not longer exist in Vista and I read that Windows DAC replace the MSADO libraries (the last one I know is 2.8).
But where is that Windows DAC?? (where I could download it??)
How could I use ADO in my native MFC application here in the fucXXXX Vista???
I'm lost.
Thank you.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
Hi there,
I am trying to open a second form that I created in my main form (add new item...) Now I have a button on my main form that is supposed to launch that form.
I have included it with: include "settings.h"
But I don't really know what code I need on the button to open the form when the button is clicked.
Then I've made a custom shape form that I need to be able to drag around the screen, I would really appreciate it if you could help me with some solution for that too. Thank you.
Please help me!
Visual C++ 2005 Express
|
|
|
|
|
Do you want to open a form of other form?
|
|
|
|
|
I am trying to use ReadFile to read comma delimited text from a file, I am placing the data into a struct using the following code:
ReadFile(hDiskFile, tcInputData, 1, &dwBytesRead, NULL);<br />
if(dwBytesRead == 0)<br />
break;<br />
k = strcmp(tcInputData, ",");<br />
if(k == 1)<br />
strcat(tcCode, tcInputData);<br />
}while(k != 0);<br />
strcat(tcCode, "\0");<br />
DTCodes[i].Code = tcCode;<br />
As you can see the code looks for the comma then copies the data into the struct. I am looking for a cleaner way to read a line of variable length from a file. This method gives me an Unknown Code Exception, my compiler is Lcc-Win32.
As always this newbie is greatful for any help received.
|
|
|
|
|
How are you declared the variables?
Where does it start the do loop? (i.e. post the previous code)
BTW: Since you're reading a character at time, probably using strcmp is a mistake.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
The array declaration is:
struct DTC{<br />
char *Code;<br />
char *Description;<br />
char *Defined;<br />
}DTCodes[0x100];<br />
<br />
The code is:
for(i = 0; i < 100; i++)<br />
{<br />
k = 0;<br />
do{<br />
ReadFile(hDiskFile, tcInputData, 1, &dwBytesRead, NULL);<br />
if(dwBytesRead == 0)<br />
break;<br />
k = strcmp(tcInputData, ",");<br />
if(k == 1)<br />
strcat(tcCode, tcInputData);<br />
}while(k != 0);<br />
strcat(tcCode, "\0");<br />
DTCodes[i].Code = tcCode;<br />
ZeroMemory(tcCode, 0x06);<br />
do{<br />
ReadFile(hDiskFile, tcInputData, 1, &dwBytesRead, NULL);<br />
if(dwBytesRead == 0)<br />
break;<br />
k = strcmp(tcInputData, ",");<br />
if(k == 1);<br />
strcat(tcDescription, tcInputData);<br />
}while(k != 0);<br />
strcat(tcDescription, "\0");<br />
DTCodes[i].Description = tcDescription;<br />
ZeroMemory(tcDescription, 0xff);<br />
tcDescription = "";<br />
do{<br />
ReadFile(hDiskFile, tcInputData, 1, &dwBytesRead, NULL);<br />
if(dwBytesRead == 0)<br />
break;<br />
k = strcmp(tcInputData, "\n");<br />
if(k == 1)<br />
strcat(tcDefined, tcInputData);<br />
}while(k != 0);<br />
strcat(tcDefined, "\0");<br />
DTCodes[i].Defined = tcDefined;<br />
ZeroMemory(tcDefined, 0xff);<br />
tcDefined = "";<br />
}<br />
What would you recommend instead of strcmp?
|
|
|
|
|
I can't see, in the above code, for instance, the declaration of tcInputData .
jonsey29847 wrote: What would you recommend instead of strcmp?
the direct character comparison, for instance (if tcInputData is declared as character array or character pointer):
...
if (tcInputData[0] == ',')
...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Duh? I should have thought a little more, eh?
I can see the data in tcInputData, and I can see data in DTCodes[i].Code etc, when I try to read the data in another function, I get zilch. I seem to have trouble with scoping sometimes, but the struct is declared in the same include file the functions are defined in. The variable declarations are:
TCHAR *tcFileName;<br />
TCHAR *tcCode;<br />
TCHAR *tcDescription;<br />
TCHAR *tcDefined;<br />
TCHAR *tcInputData;<br />
tcFileName = LocalAlloc(LPTR, 0x100);<br />
tcCode = LocalAlloc(LPTR, 0x06);<br />
tcDescription = LocalAlloc(LPTR, 0xff);<br />
tcDefined = LocalAlloc(LPTR, 0xff);<br />
tcInputData = LocalAlloc(LPTR, 0x10);<br />
The struct is declared as follows:
struct DTC{<br />
char *Code;<br />
char *Description;<br />
char *Defined;<br />
}DTCodes[0x10];<br />
|
|
|
|
|
I think you have to be more careful on memory handling, for instance in the following lines
jonsey29847 wrote: DTCodes[i].Description = tcDescription;
ZeroMemory(tcDescription, 0xff);
you first assign tcDescription to DTCodes[i].Description and then erase the content of the memory pointed by both tcDescription and DTCodes[i].Description thus loosing the information.
BTW struct has to be declared in the header file, but is better to define DTCodes[0x10]; in one source file (you can use extern struct DTC DTCodes[0x10]; in the header file to make it visible by all of the source files).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thank you very much, can you explain how DTCodes[i].Description gets cleared after the assignment is made? I thought that I once the assignment was made I no longer needed tcDescription.
I also really appreciate the header file clarification, I have much work to do to straighten my code out.
|
|
|
|
|
jonsey29847 wrote: can you explain how DTCodes[i].Description gets cleared after the assignment is made? I thought that I once the assignment was made I no longer needed tcDescription
Description is a char pointer by definition
struct DTC{
char *Code;
char *Description;
char *Defined;
}DTCodes[0x100];
The following line
DTCodes[i].Description = tcDescription;
Makes DTCodes[i].Description pointing to memory area 'owned' by tcDescription . When you clear that memory area with the line
ZeroMemory(tcDescription, 0xff);
DTCodes[i].Description happens to point to the zeroed memory.
You have to copy the memory area content if you to use it as temporary storage.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
DTCodes[i].Code = tcCode; -> for every i assigning same global pointer tcCode.
ZeroMemory(tcCode, 0x06); -> effectively no data is stored in DTCodes[i].Code.
similarly,
DTCodes[i].Description = tcDescription;
ZeroMemory(tcDescription, 0xff);
DTCodes[i].Defined = tcDefined;
ZeroMemory(tcDefined, 0xff);
And exception can occur on buffer overrun,
strcat(tcCode, tcInputData); // what happens if tcCode string length > 0x06}
while(k != 0);
strcat(tcCode, "\0");
And why need strmp,strcat for single char operation, simple array manipulation is enough isn't it
k = strcmp(tcInputData, ","); -> if (tcInputData[0] != ',')
if(k == 1)
strcat(tcCode, tcInputData); -> tcCode[len++] = tcInputData[0];
|
|
|
|
|
Thank for your reply, my thinking was that once assignment was made I no longer needed tcCode etc, see previous reply. The exception was being thrown in the debug environment because I fat fingered a handle later in the code. tcCode will always be 4 bytes in length, its coming from the ODBII ECU in an automobile, thus I could be conservative with its length.
I will change my code for the single char comparison, you example is much cleaner.
Thanks
|
|
|
|
|