|
While it is not hurting anything, why do you have the computerspec structure if you are using the member variables individually? I would think you'd want something like:
struct computerspec
{
int compnum;
int ram;
int hdisk;
};
void main( void )
{
computerspec compuspec;
compuspec.compnum = 1;
compuspec.ram = 1024;
compuspec.hdisk = 80;
out << compuspec;
compuspec.compnum = 2;
compuspec.ram = 4096;
compuspec.hdisk = 40;
out << compuspec;
...
compuspec.compnum = -1;
compuspec.ram = 0;
compuspec.hdisk = 0;
out << compuspec;
out.close();
...
do
{
in << compuspec;
} while (compuspec.compnum != -1);
} Note that this is untested and may not be syntactically correct but I am just trying to give you an idea.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Still i m not getting what i want to know!!! plz smebody hlp!!
|
|
|
|
|
rose aashii wrote:
Still i m not getting what i want to know!!!
What is it that you are still wanting to know?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I am farily new to c++ and have been trying to compile something but it is giving errors about converting the two different types of char. Is there anyway that I can actually convert the char to a char* or have I got completley the wrong idea?
|
|
|
|
|
I think that you are off base.... post the code that you are having a problem with so we can help you better.
Artificial intelligence is no match for natural
stupidity.
Never argue with an idiot. They will drag you down to their level where they are an expert.
|
|
|
|
|
CIni ini;
ini.SetPathName(_T("D:\\Programs\\Microsoft Visual Studio\\MyProjects\\Prog12\\Debug\\IniDemo.ini"));
char test = ini.GetChar(_T("History"), _T("Input"), TCHAR("NoneSet"));
char* Program = "";
char* Paramaters = "";
char* workingDirectory = "";
// Now just use ShellExecute to run it
ShellExecute( NULL, "open", Program, Paramaters, workingDirectory, SW_SHOW );
The char test is the one that I need to be char* otherwise the ShellExecute will not work properly. I dont really understand all of that code yet which is probably why I cant do it correctly.
|
|
|
|
|
talkster5 wrote:
The char test is the one that I need
Since test is not being used, why do you need it at all?
What does CIni::GetChar() return? More importantly, what is the third parameter supposed to be? I'm not sure why the class differentiates between getting a char vs. getting a string , but in any case, you need to change your code to the following in order to pacify the compiler:
char test = ini.GetChar(_T("History"), _T("Input"), ' '); Why are you mixing _T() and TCHAR() ? That in itself doesn't hurt anything but it does make your code hard to read.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
The information for the shellexecute is going to be stored in an ini file so at the moment I am just testing getting the information from an ini file which is why the char test is there but now I need it to be a char* so I can actually use it in the shellexecute as when I compile it says shellexecute can only use char* and not char.
|
|
|
|
|
You cannot use the GetChar() method to retrieve a char* value. Which parameter of ShellExecute() is in error?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
The Program, Paramaters and working directory all do not work if its just char.
|
|
|
|
|
Right. ShellExecute() does not use any char parameters. Without seeing the code that is in error, I can't provide anything useful.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
What do you mean the code that is in error? The code I posted above is the only code I have in the program at the moment. Do you want the actual error message from the compiler?
|
|
|
|
|
talkster5 wrote:
Do you want the actual error message from the compiler?
That would help tell us what exactly the error you are getting is.
|
|
|
|
|
There is nothing wrong with the call to ShellExecute() . The error, as I've already pointed out, is in the call to GetChar() . Correct that and you'll be on your way.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Yes, but what over way can I get a char* from an ini file as that was the only function that I thought would work seen as I am storing characters in my ini file.
|
|
|
|
|
OK, then try GetPrivateProfileString
This returns a string from the ini file. I hope this will solve ur problem.
"I would luv to change the world, but they wont give me the source code"
My Articles
|
|
|
|
|
Unless you have a compelling reason to use the CIni class, why not simplify things and use GetPrivateProfileString() instead? Something like:
char szBuffer[128];
GetPrivateProfileString("History", "Input", "", szBuffer, sizeof(szBuffer),
"D:\\Programs\\Microsoft Visual Studio\\MyProjects\\Prog12\\Debug\\IniDemo.ini");
...
ShellExecute(...);
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thanks for the code David. In my ShellExecute where I want the value to go to I put szBuffer or what do I put please?
|
|
|
|
|
talkster5 wrote:
In my ShellExecute where I want the value to go to I put szBuffer or what do I put please?
I do not know enough about the problem to answer this. For example, what does the .ini file look like?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
My ini is like this but I have changed it from History and Input to the correct settings when getting the information.
[Settings]
Path=notepad.exe
Paramaters=
WorkingDirectory=
So in the ShellExecute I would want to get all 3 values and put them into the ShellExecute so it can run it.
|
|
|
|
|
char szPath[_MAX_PATH],
szParameters[_MAX_PATH],
szWorkingDir[_MAX_PATH];
GetPrivateProfileString("Settings", "Path", "", szPath, sizeof(szPath),
"D:\\Programs\\Microsoft Visual Studio\\MyProjects\\Prog12\\Debug\\IniDemo.ini");
GetPrivateProfileString("Settings", "Parameters", "", szParameters, sizeof(szParameters),
"D:\\Programs\\Microsoft Visual Studio\\MyProjects\\Prog12\\Debug\\IniDemo.ini");
GetPrivateProfileString("Settings", "WorkingDirectory", "", szWorkingDir, sizeof(szWorkingDir),
"D:\\Programs\\Microsoft Visual Studio\\MyProjects\\Prog12\\Debug\\IniDemo.ini");
ShellExecute(NULL, "open", szPath, szParameters, szWorkingDir, SW_SHOW);
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thanks for the help I really appreciate it and it works great.
|
|
|
|
|
One last thing actually. Is there a way that instead of having the ini path hard coded I can just make it look where the project exe is being run from and then just //IniDemo.ini?
|
|
|
|
|
Assuming that GetChar() returns a character and takes 3 char* as arguments, then the third argument is wrong. Of course the third argument would be wrong any way.
TCHAR('C') is equivalent to char('C') or (UNICODE) wchar_t('C')
_T('C') is equivalent to 'C' or (UNICODE) L'C'
_T("String") is equivalent to "String" or (UNICODE) L"String"
TCHAR("String") is invalid; because you are trying to convert a char* into a char.
Of course if your intention is to take the low-byte of the address of the string "NoneSet", then my assumptions are all wrong and there is nothing wrong with that line of code.
I am a day late, but I hope that helps.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Question on How SetTimer() Works:
When the Timer goes off and it calls the OnTimer() function, does it wait until that function ends and the program returns to the OS before the Timer starts its countdown again or does it automatically restart the countdown once the OnTimer() function is called?
My Reason for asking is this:
I made a Multithreaded MFC serial communication program where the flow of data is continuous. Thus the way I have it is I use an Infinite loop of (Read data, do something with data and loopback to read more data), however this causes the cpu time to be completely used (99-100%). Now since the program is much faster then the flow of data what I want to do is: Read data, do something with it, then return to the OS then go back to the read routine and do it again so the cpu is used as minimally as possible.
This is where my question comes in: How could I go about being able to recall the read function once I return to the OS. As per my first question I was thinking of using SetTimer() but I dont know if it is the best possible solution to the problem. Maybe some type of event could work, but I dont think it could be monitored if the program control is with the OS.
Does anyone have any advice or answers to my 2 questions?
Thanks
|
|
|
|