|
Hmm. When i don't declare the variable globally (-> declare it locally in the main() function), it works...
|
|
|
|
|
i am not sure what is in the rest of your code but i would make the following changes.
static bool bStatus = false; // global variable
int somefunction(){////////////make the function int to return values
if (condition){///////////what ever your condition is to turn bStatus true
return true;
}else{
return false;
}
}
void main(){
bStatus = somefunction();//////////////it will now return true or false
}
|
|
|
|
|
I have a save-file from my program so structured:
char id[32];
int blocksize;
:
: <- various data for an amount of 'blocksize' bytes
:
char id[32];
int blocksize;
:
: <- various data for an amount of 'blocksize' bytes
:
char id[32];
int blocksize;
:
: <- various data for an amount of 'blocksize' bytes
:
With a generic number of "DATASET_#"
When I try to load the file, I use code similiar to this:
char id[32];
int blocksize;
FILE* f;
f = fopen(filename, "rb");
while (!feof(f))
{
fread(id,sizeof(char),32,f);
fread(&blocksize,sizeof(int),1,f);
if (strcmp(id,"DATASET_1") == 0)
{
fread( );
}
else if (strcmp(id,"DATASET_2") == 0)
{
fread( );
}
else
{
fseek(f,blocksize,SEEK_CUR);
}
}
fclose(f);
When I do this, the while loop never exits if, for example, the last dataset is unknown, it seems that the fseek() function has no effect on the next "while (!feof(f))" call.
I must take care of something about fseek under NT or WinXP or I must look for an error elsewhere ?
By now, I assume the data to be written well.
Thanks in advance for any suggestion.
|
|
|
|
|
from the MSDN for fseek:
"
You can use fseek to reposition the pointer anywhere in a file. The pointer can also be positioned beyond the end of the file. fseek clears the end-of-file indicator and negates the effect of any prior ungetc calls against stream.
"
fseek doesn't care about EOF.
-c
"What the hell are you getting so upset about? I thought you didn't believe in God".
"I don't," she sobbed, bursting violently into tears, "but the God I don't believe in is a good God, a just God, a merciful God. He's not the mean and stupid God you make Him out to be".
-- Joseph Heller
Smaller Animals Software, Inc.
|
|
|
|
|
Ok, but does feof() take care of a previous fseek() ?
This loop never exits in a test program I've done... try it out plz if you can:
FILE* f;
long i;
f = fopen("c:\\a.txt","rb");
i = 0;
while (!feof(f))
{
fseek(f,i++,SEEK_SET);
}
fclose(f);
The file "a.txt" contains three simple characters.
|
|
|
|
|
Is your program C ( not C++) ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
It's C++, MFC app.
By now I have solved with something like this:
while (fread(id,sizeof(char),32,f) != 0)
{
}
But I thought that it had should exit if fseek() seeks the position over the EOF marker...
|
|
|
|
|
OK - I am curious, is there a reason you're using C functions ? What advantage do you get from fread, as opposed to C++ equivelants, souch as ifstream ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
Only because I'm in the abit of using them, so I can reuse some old code
Do you suggest me using ifstream instead ?
|
|
|
|
|
I would always recommend using C++ code over C equivelants, the C++ libraries were written not just to do the same as the C stuff, but to do it better. I was seriously asking, because I notice a lot of people posting C code and I'm happy to learn that it does some things better, better to ask and find out than wade in with my opinion and be told
Your code looked to me like it would be a lot more readable using ifstream though, although I admit I only glanced over it.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
I'm rewriting the functions using fstream, if you say fstream acts better, I trust you
Thanks for the advice
|
|
|
|
|
Hi, I have a small problem with my SDI app. There are several modal dialogs in the program. Sometimes, if I activate a different program and then press alt+tab, or even click on the program in the taskbar, only the modal dialog is brought to the foreground. The main SDI window does not appear below the dialog. This only happens when some of the dialogs are shown, but they are all created in the same way! To show the dialogs I do:
CMyDialog dlg(AfxGetMainWnd());
if (dlg.DoModal() == IDOK) {
...
}
Please help if you can. I've just spent hours searching through messages and couldn't find anyone who had a similar problem.
By the way, I'm running Windows XP, but I have the same problem under Windows ME.
Thanks!
|
|
|
|
|
Hi i need to Uninstall a program programmatically. ie. Programmatically simulating Add/Remove option from control panel .Any help ?
|
|
|
|
|
Have a look in the registry
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
There all uninstallable programs are registered.
Some notes on the keys which can be found there:
- "DisplayName" is the displayed name in the listbox.
- "UninstallString" tells you which command is executed when the user clicks the "Add/Remove" button in the control panel.
|
|
|
|
|
Hi.
I would like to change the initial location of a dialog box (modal and/or modeless.
For example, in the program I can current working on, Windows paints the the modal dialog box in th center of the program. I have to move the dialog box to the size to see the main window. I would like to change the initial location of a dialog box.
Thanks,
Kuphryn
|
|
|
|
|
Use the MoveWindow API call
Nish
If I am awake and my eyes are closed, it does not necessarily mean that I am thinking of naked women.
|
|
|
|
|
OnInitDialog() is called before the dialog is actually shown. In this function, use either SetWindowPos() or MoveWindow() to change the window position. In this way, when it is shown it will appear initially in the correct place.
I would strongly suggest that if this is a commonly used dialog you save and restore the window position; this way users can put it whereever they want it, and it will appear there initially from then on.
Sometimes i only remember, The days when i was young Nowadays no one remembers when they were young and stupid... ADEMA, The Way You Like It
|
|
|
|
|
Thanks.
MoveWindow(...) works great.
Now I just need to save the position in the registry.
Kuphryn
|
|
|
|
|
kuphryn wrote:
Now I just need to save the position in the registry.
May I ask you why do you want to do this?
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
Sure. Shog9 implied that the dialog box should at the last position before the user closes it. The only way to do that is to save its last position int he registry.
Kuphryn
|
|
|
|
|
I would like to know what this printprocessor means for PRINTER_INFO_2 while using Addprinter. Basically i am trying to add printer programmatically but i cannot succed. Any help is most appreciated.
Somu.l
|
|
|
|
|
I want to read from file ,line be line and after reading each line modify it and write modify string to file.I use this code:]
CStdioFile inFile;
inFile.Open(strpath , CFile::modeReadWrite | CFile::typeBinary);
char buf[80];
while(inFile.ReadString(buf,5))
{
CString outdatastring;
for (int i =0 ;i < 5; i++)
{
}
inFile.WriteString(outdatastring);
}
inFile.Close();
But I got this error after in run time:
Disk full while accessing F:\Doc\Change List - Beta2 to RTM.doc.
Any suggestion?
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
First question: you use CStdioFile, why do you open the file with the CFile::typeBinary parameter?????? Normally CStdioFiles are opened with CFile::typeText! If you need to read binary data you should use the normal CFile class. My suggestion: change CFile::typeBinary to CFile::typeText.
Second question: why is the char buf[80] 80 chars long and you use only 5 chars of it? My suggestion: read the COMPLETE string (can be much longer than 80 chars, so extend the size of buf) and then process only the first 5 chars. Thats much better. I don't know how ReadString reacts when it doesn't reach the end-of-line character and then is called again.
|
|
|
|
|
is there a notification message that will tell me when a dialog has finished initializing for the first time?
thank you
|
|
|
|
|
hi friend
wut u want??
for y u specify at first time????
WM_INITDIALOG is a message will post when a dialog initiates..
i think u aimed to do some trick with single instance...am i right??
Renjith
Hai Friends me from Pandalam..and i think there is a sofware behind everything...
so enjoy with the codes...
|
|
|
|