|
I am having a strange problem with the following dialog callback function:
BOOL CALLBACK MergeProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
static int MostRooms;
bool bError;
char *room,*year,*exam;
switch(Message)
{
case WM_INITDIALOG:
if (strlen(dlgdata[0])) {
year = new char [10];
strncpy(year,dlgdata[0]+2,4);
strcpy(year+4,"\0");
SendDlgItemMessage(hwnd,SD_MERGE_YEAR, WM_SETTEXT,20,(LPARAM) year);
delete year;
}
SendDlgItemMessage(hwnd,SD_MERGE_YEAR, EM_LIMITTEXT,4,0);
SendDlgItemMessage(hwnd,SD_MERGE_ROOM, EM_LIMITTEXT,30,0);
SendDlgItemMessage(hwnd,SD_MERGE_EXAM, EM_LIMITTEXT,10,0);
MostRooms = atoi(dlgdata[1]);
EnumChildWindows(hwnd,EnumChildProc,(LPARAM)hFnt);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
bError = false;
room = new char [30];
year = new char [10];
exam = new char [30];
room[0] = (char)10;
year[0] = (char)10;
exam[0] = (char)30;
SendDlgItemMessage(hwnd,SD_MERGE_YEAR,EM_GETLINE,0,(LPARAM)year);
SendDlgItemMessage(hwnd,SD_MERGE_ROOM,EM_GETLINE,0,(LPARAM)room);
SendDlgItemMessage(hwnd,SD_MERGE_EXAM,EM_GETLINE,0,(LPARAM)exam);
if (strlen(room) > 0) {
if (!count_rooms(room,MostRooms+1) ) {
char tmp [128];
sprintf(tmp,"Please enter rooms between 0 and %i!",MostRooms+1);
MessageBox(0,tmp,0,0);
bError = true;
}
}
else if (!bError) {
MessageBox(hwnd,"Please enter a room!",0,0);
SetFocus(GetDlgItem(hwnd,SD_MERGE_ROOM));
bError = true;
}
if ( (strlen(year) > 0) && (!bError) ) {
if ((atoi(year) > 2000)&&(atoi(year) < 2100)) {
char *text = new char [10];
strcpy(text,"¸ß");
strcat(text,year);
strcat(text,"¼¶");
strcpy(year,text);
delete text;
}
else if (!bError) {
MessageBox(hwnd,"Please enter a year between 2000 and 2100!",0,0);
SetFocus(GetDlgItem(hwnd,SD_MERGE_YEAR));
bError = true;
}
}
else if (!bError) {
MessageBox(hwnd,"Please enter a year!",0,0);
SetFocus(GetDlgItem(hwnd,SD_MERGE_YEAR));
bError = true;
}
if ((strlen(exam) > 0) && (!bError) ) {
}
else if (!bError) {
MessageBox(hwnd,"Please enter an exam name!",0,0);
SetFocus(GetDlgItem(hwnd,SD_MERGE_EXAM));
bError = true;
}
if (bError) {
delete exam;
delete room;
delete year;
MessageBox(0,"An Error occured",0,0);
}
else {
dlgdata[0] = year;
dlgdata[1] = room;
dlgdata[2] = exam;
EndDialog(hwnd,1);
}
break;
case IDCANCEL:
EndDialog(hwnd,0);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
Sorry to post so much. Basically all this does is retrieves the text from the three edit boxes, tests the values and returns. If you follow the IDOK event, you can see if an error occurs I display a message box and set the bError = true. Now for some reason, only with a release build, bError is false right through, until I test if it is true. No message boxes are displayed besides the final "An Error occured". I just can't understand why.
I have placed a message box on just about every line, they have confirmed that bError is false. But the if (bError) { is always true.
|
|
|
|
|
waldermort wrote: only with a release build,
Debug builds set local variables to zero (false) - release builds don't (so what you have is basically indeterminate). It's important to always initialize your local variables to a known state.
I'd start by setting bError to false when you declare it and check if the problem reccurs.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
I have already tried this. When declaring the berror variable I origionaly set it to false. Though thinking this may be a cause of the problem I removed it and instead set it to false in the IDOK handler.
Like I said in my post, bError is false right up until the final test, where for some reason it is being set to true. The problem lies here somewhere
if ((strlen(exam) > 0) && (!bError) ) {
}
else if (!bError) {
MessageBox(hwnd,"Please enter an exam name!",0,0);
SetFocus(GetDlgItem(hwnd,SD_MERGE_EXAM));
bError = true;
} However the "Please enter an exam name!" is never shown, suggesting the bError = true; line is never executed either.
|
|
|
|
|
Sometimes it helps to rewrite the logic tests to be more affirmative.
In the example you show, you're making use of what I call "testing for a negative" which can be very hard to follow.
Try rewriting the tests like this:
if ( (strlen(exam) <= 0) && ( bError == false ) )
{
MessageBox(hwnd,"Please enter an exam name!",0,0);
SetFocus(GetDlgItem(hwnd,SD_MERGE_EXAM));
bError = true;
}
This way is simpler, clearer, and easier to follow mentally.
|
|
|
|
|
I understand your logic, but I need it the way it is. I will later be adding code into that empty if statement which will check for previous instances of the entered text.
Though out of sheer baldness, I will test the change.
|
|
|
|
|
This is just bizzare. Your advice works, as it should do, but then again, my code should also work. I also tried the following
if ((strlen(exam) > 0) && (!bError) ) {
int i = 0;
}
else if (!bError) {
MessageBox(hwnd,"Please enter an exam name!",0,0);
SetFocus(GetDlgItem(hwnd,SD_MERGE_EXAM));
bError = true;
}
Which also works. So the ultimate question is, why the hell is an empty if statement causeing bError to become true?
|
|
|
|
|
Wow. If it suddenly starts working just with the addition of the int i = 0; , then I can't claim to know what is causing the problem.
Perhaps the issue has to do with optimizations applied by the compiler.
Try this: Go back to the original (non-working) code, and then go into the Project Properties, and turn OFF all compiler and linker optimizations. Then build it and see if it works.
|
|
|
|
|
I have played with all the project setting that I dare and nothing changes the fact that an empty if statement is causing me problems.
You won't believe how embaressed I was today when my boss asked for a demonstration. The whole thing came to a standstill simply because data could not be merged.
|
|
|
|
|
I would really think that the compiler is doing this to you. Set the optimization to DEBUG on your release build and rebuild everything.
Are you stepping through this with the debugger?
|
|
|
|
|
Hi All,
Can any one explain the behavior/output of following piece of code.
// TestApp.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "conio.h"
class B
{
private:
int i;
public:
B()
{
i = 10;
}
void fun()
{
printf("%s","Called\n");
}
};
class A
{
private:
A(){};
public:
static B *b;
static void intializeStatic()
{
A::b = new B();
}
};
B *A::b = NULL;
int main(int argc, char* argv[])
{
A::b->fun ();
printf("Hello World!\n");
getch();
return 0;
}
Output:
Called
Hello World!
Please Help
Thanks In Advance..
Suraj Gupta
|
|
|
|
|
Is this a quiz, or do you have a specific question? What are you having trouble with?
|
|
|
|
|
Gupta Suraj wrote: Output:CalledHello World!Please HelpThanks In Advance..
you are calling static function of the class A, is that your problem
|
|
|
|
|
yang__lee wrote: hen class A's constructor is private.It can not be instantiated.
have you ever read about usage of static variable in class or singleton pattern
|
|
|
|
|
Hi,
I am writing a report at the moment and I just wanted to ask for any tipps? I also actually hae a question...if I am writing about a function in the code and giving code snippets is it a good idea to just give the general form of that function, ie
" And then I used the function CWnd::AfxRegisterClass(Give Parameters) and the syntax is as follows"
or should I write just ...and then I used the AfxRegisterClass method? And then for code snippets...should I use the "general form" or the one from the code where I actually use instances of variables etc. Sorry if this unrelated and slightly confusing but just thought I might ask here cause just want the clearest way of doing things.
|
|
|
|
|
Just one suggestion. Think about who your report is targeted towards. If beginners then yes, it would be good to refrence the full function name and paramaters, if intermediates, then no. Also for some rarely used functions, and the not so obvious ones, it would be good to hyperlink them to the relevent MSDN page.
Nomatter who it is targeted towards, make sure your code snippets are well commented.
|
|
|
|
|
hi!
I've got this CString : "454628000211119369041932" which I want to convert into a long long int(64 bits). I try with atoi but the string is too big! Anybody have an idea how this be done? The reason why I need this is to add this number to an other smaller one.
thanks !!
-- modified at 12:00 Friday 7th April, 2006
|
|
|
|
|
_ttoi64() function should do the trick. Assuming that the string value is within the 64bit type range.
<EDIT>
and looking at your string, I can see that the number actually exceeds the range of a 64bit integer.
<EDIT>
I Dream of Absolute Zero
-- modified at 12:13 Friday 7th April, 2006
|
|
|
|
|
cool thanks! But I think my number is over range...I'll check it out!
thanks for answering
|
|
|
|
|
BigDan34 wrote: I think my number is over range...I'll check it out!
OT, where do you required such a big number
|
|
|
|
|
This is for a cryptographic work. I've got a very big encryption key and I need to add this key to an other one...pretty bad We have check it out with the projet manager and finaly we the key
thanks anyway
|
|
|
|
|
Hi all
I have such situation :
dwordValue = Byte1 Byte2 Byte3 Byte4
I want to write function foo(DWORD &x) and when I call
foo(wordValue)
I want dwordValue to be like this :
dwordValue = Byte2 Byte3 Byte4 Byte1
-- modified at 12:24 Friday 7th April, 2006
|
|
|
|
|
Unless I'm seriously mistaken, a "word" is two bytes long, not four.
Here's a technique you could use, although it is not the only one:
BYTE* BytePointer = (BYTE*) &wordValue;
BYTE Byte1 = BytePointer[0];
BYTE Byte2 = BytePointer[1];
BYTE Byte3 = BytePointer[2];
BYTE Byte4 = BytePointer[3];
INT ReversedValue = 0;
BytePointer = (BYTE*) & ReversedValue;
BytePointer[0] = Byte2;
BytePointer[1] = Byte3;
BytePointer[2] = Byte4;
BytePointer[3] = Byte1;
Hope this helps,
Rich
|
|
|
|
|
Troposphere wrote:
Unless I'm seriously mistaken, a "word" is two bytes long, not four.
He's using a DWORD which is four bytes.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: He's using a DWORD which is four bytes.
Look again, the post was modified. In the original post, it said simply "word", not "DWORD".
|
|
|
|
|
Hello. I wrote a dll for use with a VB front-end. The DLL runs mainly in a while loop which takes full control over the one thread VB allows, which ultimately freezes the VB form. I was wondering if adding multi-threading to the DLL would help. Theorhetically, I would think that it might. For example, VB App loads DLL in one thread, DLL creates new thread for while loop processing, thus the VB form should be able to function.
Here would be an example of my DLL layout:
while() {
for() {
if () {
}
}
}
So, I suppose I would need to through the entire while loop in its own thread, but I have no idea how. I have never multithreaded before, so I would really appreciate an example, if possible.
I thank you in advance.
|
|
|
|
|