Click here to Skip to main content
15,030,396 members

Comments by Chuck O'Toole (Top 200 by date)

Chuck O'Toole 13-Dec-12 4:19am View
This will have no effect on his problem. There is nothing wrong with his use of "thread_array"
Chuck O'Toole 24-Nov-12 18:39pm View
32KB is a very small stack these days, think in terms of MB
Chuck O'Toole 19-Nov-12 18:28pm View
Programmers define bits in registers as "masks", e.g., 0x00000002, 0x00000004. In my experience with hardware guys who write code define bits as "bit numbers", 0, 1, 2, 3, etc. It is a characteristic of code written by hardware guys is that they like to do lots of "shift" operators. It's "artistic" versus "sledgehammer" style of coding.
Chuck O'Toole 19-Nov-12 13:05pm View
you should put the in as a solution as it precisely answers his question
Chuck O'Toole 30-Oct-12 11:32am View
True. The ratio of "process the list" events versus "add or remove from the list" events is usually the deciding factor. Timers are something you scan every "tick" yet occasionally add (new process/thread sleeping) or remove (timer expiring) them.
Chuck O'Toole 30-Oct-12 11:29am View
Good explanation +5. It's how I implemented a process sleep queue in a RTOS from the '80's.
Chuck O'Toole 28-Oct-12 20:42pm View
Of course they run sequentially, each thread waits for the global mutex before doing its work and then released the mutex when done. Ergo only one thread is doing computation at a time.

PS, why do you create the one global mutex every time in the main loop that create the threads? How many Global Mutex objects do you need? If it's more than one, why do you store the Mutex Handle in a single variable?
Chuck O'Toole 23-Oct-12 18:55pm View
What the difference between "MAX_THREADS" and "max_threads"? You use both in this code.
Chuck O'Toole 20-Oct-12 22:51pm View
You are totally confusing the C language syntax for "escaped strings". The code shown uses "\\" to generate exactly one character that is a backslash. Therefore C code is replacing the two character string "\n" with the single character "newline". The user would not enter the three keystroke sequence "\\n" only the two character sequence "\n". If you are going to be coding in C/C++ then you need to study more about C character string language notations.
Chuck O'Toole 12-Oct-12 22:38pm View
What are the command line arguments? Are you sure there are two of them, "Username" and "password". A null for either will cause a crash, you should check in the code for either argv[1] or argv[2] being null before using them to protect against bad command line invocation.
Chuck O'Toole 5-Oct-12 1:40am View
My point is that you cannot return a value called "void", there is no such thing. Having "no return value" and "returning void" are not the same thing.

Yeah, "D" is strictly true of "pointers to functions" but in the same loose context as "return void", I let it pass.
Chuck O'Toole 5-Oct-12 1:27am View
What possible use would it be to know this *before runtime*? If you application isn't running, why would you care? Plus, it is so easily discoverable at runtime from argv or CWnd::m_CmdLine so why bother trying to figure out the "unknowable" ahead of time. Windows, Linux, pick your favorite OS and/or hardware platform, they all can do it differently yet they all follow the standard of argv for telling you where they put the args. This just seems like a silly exercise.
Chuck O'Toole 5-Oct-12 1:16am View
well, "B" is tricky. A function can be declared to return "nothing", that is, to not have a return value. You declare that by saying "void foo(arg-list)". However, there is no real thing called "void" so you can't return it.
Chuck O'Toole 5-Oct-12 1:14am View
All are true
Chuck O'Toole 5-Oct-12 1:11am View
I hate to state the obvious but what the heck. BINARY = 2. If you only pass 1 argument, it's a UNARY operator.
Chuck O'Toole 3-Oct-12 15:46pm View
First, when replying to someone, use the "Repky" button on the right side of their message. Since you didn't do that, I didn't get an e-mail saying you replied and you might have waited forever for a reply.

Secondly, did you also run the release build on the XP machine? Where is your development done, XP or Win 7 or BOTH? You need to provide precise answers otherwise we do not know what environments are working / failing.
Chuck O'Toole 3-Oct-12 10:35am View
Search CodeProject for threads, there are many fine articles here that will help you get started. Also, Google for learning threads and you should find lots of "getting started" articles.
Chuck O'Toole 3-Oct-12 8:50am View
Your problem statment is unclear. Did you build/run it on Windows XP *AND* on Windows 7.0 or did you simply build it on Windows XP and move the binary to Windows 7 and then it doesn't work? If it's the latter, chances are you have some libraries missing from the Windows 7 machine. For example, are your building / moving the DEBUG build or the RELEASE build?
Chuck O'Toole 28-Sep-12 10:35am View
If you pass the arguments correctly, your statement with %Le should do the trick. Or use the link that I posted in the solution to look at all the ways available for formatting.
Chuck O'Toole 24-Sep-12 21:00pm View
Thanks, never did that one
Chuck O'Toole 24-Sep-12 19:18pm View
Initializing it in the constructor is a good suggestion, assuming he ever get to the constructor. With "this" set to NULL, a constructor wouldn't help :)
Chuck O'Toole 24-Sep-12 18:08pm View
Oh, and do people still say "Abend"? I thought that as an IBMism from the 60's. When I was writing IBM/360 code back then, my favorite abend code was User 240. It printed in hex so it came out "Abend UF0"
Chuck O'Toole 24-Sep-12 13:46pm View
In addition to CPallini's excellent response, you've "declared" m_pUAS to be external to your code. OK, but that doesn't "define" the instance of the variable. "extern" only declares an attribute of the variable not the instance of it.
Chuck O'Toole 19-Sep-12 15:30pm View
Yup, the pointer list is uninitialized. +5
Chuck O'Toole 17-Sep-12 13:20pm View
My issue is *not* with GetDlgItem(), I use it all the time. My issue is that you cast the return (CWnd *) to a CButton * which is NOT the correct thing to do. CButton is *derived* from CWnd, not the other way round. You are improperly UPCASTING to a higher object and none of the Vtable or member variables that are unique to CButton will be there. The only right way to do this is to subclass the control into a variable using DDX. Showing this incorrect technique to an obvious newbie isn't helping him at all.
Chuck O'Toole 16-Sep-12 22:24pm View
I don't have VS installed on this PC at the moment so I can't check but I'm pretty sure that GetDlgItem() returns a CWnd * not a CButton *. Since CButton is derived from CWnd, you are "Upcasting" an object and you can't be sure that "GetCheck()" will work. If it does work, it's by accident and not design.
Chuck O'Toole 14-Sep-12 22:57pm View
almost seems like you forgot to add the .o file to the "make" link line
Chuck O'Toole 14-Sep-12 21:35pm View
It would help if you included the actual linker error message. I don't see it in your post.
Chuck O'Toole 12-Sep-12 14:12pm View
In addition to this excellent answer and his response to your comment, let me add that while your C code (count++) looks like a single statement to you, it can be several executable statements in machine code, depending on the computer architecture. Plus, between any two of those machine instructions, one of your threads can be pre-empted by the kernel and the other thread scheduled and it can run to completion before your first thread gets another turn at the cpu. In fact, almost any scenario is possible. So you should *always* use proper data access synchronization techniques (semaphores, conditioned variables, etc) to properly protect any data "shared" among threads. This will prevent your program from being affected by the vagaries of the kernel and other things you have no control over. Learn this once and well and it will serve you forever.
Chuck O'Toole 10-Sep-12 17:57pm View
Well, I'm not exactly sure of Windows NT based kernels so I'll defer to msdn. Mutexes have been around longer than Windows NT and existed before POSIX codified them in a standard. As early as 1970 I was using read/modify/write instructions to do the "fast lock check" part of the mutex followed by a semaphore / queueing operation if the lock was taken. So, that's why I said that in theory, you don't need to involve "a kernel" until you need to block / wait for the release event.
Chuck O'Toole 10-Sep-12 15:49pm View
Theorethically, a mutex does not need the kerenl either. Mutex is supposed to be the best of a "spin lock" (requires a hardware atomic test-and-change instruction) and a "semaphore" to queue waiters. If there's no contention for the interlock, a mutex can determine that in a single instruction (test and set) and proceed but if another thread owns the lock then there's a queue to wait in. While "spin locks" are fast when acquiring a lock, they have the downside of chewing up cpu cycles waiting for the contending lock to release it. This can effectively slow down the system when the number of lock contenders is greater than the number of processors / cores available to run them.
Chuck O'Toole 8-Sep-12 22:25pm View
well, if you're not creating threads yourself, then these are threads created by windows on behalf of things you are doing. As such, they will come and go as they wish. Be aware, these threads then have absolutely no impact on why your program is getting random and incorrect answers. You have some other problem and you really need to debug it carefully. As you said in your original posting, you are not providing code and you'd like our best guess. Well, no more guessing until you provide some more concrete details about the failures, how the values are computed, examples of incorrect results, and, of course, code that has the problem. Once you've debugged as far as you can get and posted more info, you'll get more specific help.
Chuck O'Toole 7-Sep-12 16:16pm View
Amazing coincidence, the link in solution 2 below is to a question that is worded exactly the same but posted in November of 2005 :) I guess they're still using the same homework questions almost 7 years later.
Chuck O'Toole 7-Sep-12 15:55pm View
Assumes "v" is an integer type, doesn't work across the board for float / double
Chuck O'Toole 7-Sep-12 15:54pm View
Nope, that's a test for even / odd, multiple of 2 not power of 2
Chuck O'Toole 7-Sep-12 15:53pm View
Assumes "x" is an integer type, doesn't work across the board for float / double
Chuck O'Toole 5-Sep-12 10:05am View
ok, going from the specific "HTTP" to the generic "TCP Packets", when you are coding "send" and "recv", you are implementing your end of a "protocol", an agreement between you and the other program on what constitiutes a "message / command" and what constitutes a "reply / response". The number and sequences of "sends" has to match the other programs number and sequences of "recvs" and visa-versa, otherwize one of you has violated the protocol. In this instance, you are talking to an HTTP Server (WinInet, Apache, whatever) and the protocol they've implemented does *not* include sending you "acks".
Chuck O'Toole 5-Sep-12 9:44am View
How many times did you go through the "send" loop before it exited. Why would you expect a "recv" for each and every "send". HTTP protocol requires that you send a bunch of legal header stuff before the web site responds to you so until you are *done* sending, the web site will not respond so there's nothing to recv. That's why putting it outside the loop works, you completed sending the request, *then* you recv.
Chuck O'Toole 31-Aug-12 18:02pm View
Good pointer, 5ed
Chuck O'Toole 15-Jun-12 19:31pm View
I hope this is just a paste problem but your sample code has *both* beginthread and beginthreadex executed. I don't think you really mean to do both.
Chuck O'Toole 26-May-12 9:22am View
Did you include "Resource.h" too?
Chuck O'Toole 26-May-12 9:21am View
That covers it nicely +5
Chuck O'Toole 26-May-12 9:14am View
Most likely place for "IDD_DIALOG1" is "Resource.h". You'd be surprised how many people don't include "Resource.h" in the code module.
Chuck O'Toole 19-May-12 14:24pm View
Code-o-mat found that there's memory allocated in a "COleControlContainer" object that is not returned. Often that happens when you do not delete something you created with "new". Or, you did not delete an object you created that contained a member of type "ColeControlContainer". That's something to look for.
Chuck O'Toole 15-May-12 16:48pm View
A quick thing for you to check. What's the difference between "15" and "0x15"? Hint, it's the "number base" (decimal - base 10, hexidecimal - base 16). "015" is yet another "base" (octal, base 8). Each represents a completely different value and will show differently when printed out as an integer with "cout" (base 10).
Chuck O'Toole 15-May-12 8:05am View
Write this down in your little book of coding secrets:

Anytime you find yourself writing things like "new char[64]", any fixed string sizes, say to yourself "This will NEVER be bigger than 64!". Then say, mischieviously, "How can I make it bigger than 64?". And if it's easy to do that, then you have a bad design and you must fix it. Use dynamically sized strings or check lengths before you use the strings. Remember that Microsoft's biggest security flaws were because somebody thought "oh, they'll NEVER exceed my buffer's size".
Chuck O'Toole 10-May-12 2:59am View
How can you possibly be using some members of the CFileFind Class (FindFile(), FindNextFile()) without knowing / looking up the other class members? Is this code something you just cut / pasted from the web somewhere? Double-Click on CFileFind (to highlight it) and hit "F1". Read the displayed documentation.
Chuck O'Toole 10-May-12 2:53am View
True, it makes a difference. Since the OP's registry key looks like it's related to the installation procedure, another thing to look for is a mismatch between the "bitness" of the install package versus the "bitness" of the running application. I had an issue where the application was 32-bit but the installation was 64-bit so the installation put the key in one registry hive and the code was looking for it in another.
Chuck O'Toole 7-May-12 14:13pm View
When the spec is ambiguous / open to interpretation, either interpretation is correct. The point here is that nobody should be relying on the pecularities of a particular compiler for their code to work properly. There are ways of writing this, using multiple statements, that will give the same and predictable result across all compilers. If the OP is interested in getting one or the other result, they should write consise code showing exactly when *they* want the increment to occur. Leaving it up to the compiler is just sloppy.
Chuck O'Toole 5-May-12 19:40pm View
Why? Will you get a bad grade on your homework?

And if you are so set on doing that, why not use the solution given to you by Sergey? What's wrong with that?
Chuck O'Toole 5-May-12 19:16pm View
You can either extend the stack as Sergey suggested or you can, as you've already demonstrated, declare the arrays statically, outside the scope of main(). If you do it that way, there are no changes to your code required, you don't need to fiddle with the stack, and you don't need to wait for someone to write the dynamic allocation code for you.
Chuck O'Toole 4-May-12 4:47am View
No, it does not "solve" your problem, it only makes the symptoms go away. The problem seems to be that you are using a mix of time conversions (including how you output the time which you haven't shown us yet). To "solve" the problem, you need to use the time conversion routines properly, as suggested by others using the links to examples and documentation as suggested by others.
Chuck O'Toole 3-May-12 18:10pm View
Continuing in our education series, how many characters are in inputstr? How many times will this go through the loop?
Chuck O'Toole 3-May-12 18:08pm View
To help your learning, let me offer this one hint as to why you got the answers you got. What do you think this statement will do
temp=inputstr[i] - '0';
When inputstr[i] is a '.' (period) :)
Chuck O'Toole 3-May-12 10:51am View
Yeah but now he won't learn anything. He'll turn in your code and get a failing grade because it's obviously too advanced for it to be his work. Or worse, the instructor will be impressed and pass him with flying colors and he'll get a job working at your bank's processing department.
Chuck O'Toole 1-May-12 11:53am View
Given the definition of LRC files ( it is most likely a UTF-8 file so only some characters should be "garbage" and need translated. If everything is "garbage", you've got some other file or problem.
Chuck O'Toole 26-Apr-12 13:20pm View
It would be better to ask the author of the article / code referenced than post it here and hope somebody who knows anything about the code reads it. It's not my code, I know nothing about it, nor did I write nor have the documentation.
Chuck O'Toole 24-Apr-12 10:19am View
So, the "doesn't work" has nothing to do with the code itself, it's what you do with the variable when you're done. Apparently you try to sent the code to a custom edit control (derived from CEdit or other type control) and that custom control has some code to check for the validity of the string. You should focus on that control's code and maybe fit it to allow a trailing space or to allow space as a "letter".
Chuck O'Toole 24-Apr-12 10:17am View
You should only post small snippets of code that exhibits the problem you are having. Nobody is going to paw over dozens or more lines of code and very few will actually try to paste the code into a development eviornment and try to run it.
Chuck O'Toole 24-Apr-12 9:53am View
Of course and you did exactly that in your very first post. Now I'd like to point out that you never did answer the question of "What exactly do you mean when you say it doesn't work". Why do I get the feeling that appending the blank is not working for you yet it appears that the code you posted should do the job. So you will continue to go around and around on this until you either post the real code that doesn't work or explain what you see when you try to append the blank. Your debugger should be a lot of help on this.
Chuck O'Toole 24-Apr-12 9:44am View
It's only over your head because you haven't done it yet. Everything was over your head at some point and that was true for us all. As Captain Kirk said, "we learn by doing", so take one of those examples and start using it and modifying it to do what you want it to do. Post messages here (as new topics) when you run into specific problems and you'll get some help.
Chuck O'Toole 23-Apr-12 18:57pm View
a+a = 2*a

Get a piece of paper and a pencil and "play computer" as you step through these calls, writing down all the intermediate answers.

Hint: Each time you "recurse" into the 'fun' function, you will get a new "a" to use inside 'fun' as when you return, the caller will still have their original "a".
Chuck O'Toole 23-Apr-12 18:51pm View
Echo all the above comments, you're going to have to carefully define "this does not work" because it sure looks like it should do something reasonable to us. Also, you said "I don't want to append any letter" in a reply above but you are willing to append " " (a blank character) so that does alter the string. Also, since both the true and false cases append a " " (blank) do you really want to go through the complications of the check for the value? Nothing in value will change the outcome, it will append a blank.
Chuck O'Toole 23-Apr-12 18:47pm View
Another nit, assuming you did
int val = (value >= 0)
to change the bool to an int, you'd have to reverse the logic (0 = false = '>', 1 = true = '>') or reverse the conditional (value < 0). Then you can use the shorter code.
Just nitpicking, assuming the OP wanted to use your shortcut.
Chuck O'Toole 23-Apr-12 18:44pm View
Basic logic flaw there. His condition is value >= 0. You can't use val (value) as the index because it can be *any* number, e.g. 999999 or -326 and that would be an unacceptable index for you "appendable_strings" array.
Chuck O'Toole 23-Apr-12 4:48am View
nope, I just focused on what would cause the warning the OP said they got.
Chuck O'Toole 21-Apr-12 17:43pm View
Wow, that way very kind and very helpful. +5
Chuck O'Toole 19-Apr-12 19:17pm View
It is a literal answer to the question is 'c' a digit. Well, it's a digit in hexidecimal. comes after 'b' and before 'd' :) In fact, it's a digit in any number expressed in a radix of 13 or greater. For example, it's not a digit in base 10. :)
Chuck O'Toole 19-Apr-12 19:15pm View
Funny. Useless, but funny. The laugh was worth a 5 :)
Chuck O'Toole 19-Apr-12 10:11am View
Of course, this works and is efficient if memory size is no object. The original poster said the arrays were "large / very large" which makes for an interesting intellectual exercise. What if you cannot contain both arrays *and* the concatenated array in memory at the same time? The "sample" code posted showed statically allocated initial arrays so it's easy to ignore the "size" problem. The "large / very large" arrays are probably not entered as constants into the compiler. If we knew where those came from, it might generate a different solution.
Chuck O'Toole 19-Apr-12 10:04am View
Didn't somebody ask a similar question last week? Search the CP site to see the resposes they got.
Chuck O'Toole 17-Apr-12 17:19pm View
Don't forget to make your buffer one character bigger than the recv() statement specified. If you receive a full buffer, you still need room for the null. i.e.

char recvBuf[BUFLEN + 1];
int recvBufLen = BUFLEN;//512

Chuck O'Toole 17-Apr-12 5:57am View
Just to be sure, beside 'compiling' it without problem, you should 'run' it too. :)
Chuck O'Toole 17-Apr-12 5:57am View
No, I diagnosed this purely by code inspection. The problem is not the 'read' accesses but the statements that modify the array (item swap in bubblesort()). Who knows what items he is clobbering when he writes beyond the bounds of the array. 'reading' outside the bounds of the array may or may not yield access violations or just garbage data. 'writing' outside the bounds can cause a completely different set of consequences in code that is unrelated to the 'bounds bug'
Chuck O'Toole 16-Apr-12 12:37pm View
Well, that's one way. Of course, you would have to check that the newline was exactly the last character received not just somewhere in the buffer (otherwise you'd see it if multiple messages was were received). You want to distinguish between "receive all the data available" and "receive all the data I expect". Newline as the exact last character tells you that.

Here's a suggestion to debug / refine the algorithm. Right now your send (20) is an exact multiple of your receive (80) (as you said in your original post). Make them not line up. Change the receive to 67 (a nice strange number) and then pause the program to let message back up. Then step through your code that processes all imcoming messages.

The other way to approach the problem is to move all the "bit fiddling" to the lowest layers, in other words, create a class that returns a single message (terminated by "newline"). Let that routine manage the buffer walking and message framing / reassembly. Have it keep track of the number of residual bytes in the buffer, copy them to the final message, and use recv() when you need to refil the buffer. That way, only one bottom level routine needs to learn about the oddities of recv() and TCP/IP message buffering.
Chuck O'Toole 15-Apr-12 21:00pm View
Well, to clarify your thoughts about CreateProcess(). You need to consider what you are passing as the argument. Consider the difference between passing "pThrInfo" and "&pThrInfo". In the first instance, you are passing the "contents" of "pThrInfo", in the second you would be passing the address of "pThrInfo". So, when CreateProcess() creates the argument list to pass to the created thread, it's going to put the argument on the local stack of the created process for the initial "call" to the thread. Passing the "contents" of the pointer, as you do in your code, removes any concern you have about the original pointer in the caller's code. If you passed the "address of the pointer" you would still rely on the pointer in the caller's code being "safe" until you did something with it in the created thread. Depending on the contents of the caller's variable requires synchronization objects.
Chuck O'Toole 12-Apr-12 13:57pm View
It autodetects - picked Vietnamese
Chuck O'Toole 12-Apr-12 13:48pm View
The messasge would make much more sense if we knew what issued it. You tagged this with every known language (hyperbole intended).
Chuck O'Toole 12-Apr-12 13:46pm View
Gotta love Google Translate:

for arrays a and n elements; write subroutines perform the following requirements:
A. test array has to be a permutation from 1 to n or not?
2.tim appear first position of the element x in a.
3.kiem the monotony of a survey. .

Now we can properly flame him for just posting a homework assignment and expecting someone to do it for him.
Chuck O'Toole 1-Apr-12 23:26pm View
Chuck O'Toole 1-Apr-12 20:55pm View
Well, the first thing should be to answer his question. "Why" doesn't even figure into that. But I tend to stay out of religion discussions other than to say I worship at a different set of "general principles".
Chuck O'Toole 1-Apr-12 20:33pm View
Why not? It's a reasonable thing to do.
Chuck O'Toole 1-Apr-12 20:33pm View
why not? It's a reasonable thing to do.
Chuck O'Toole 1-Apr-12 20:32pm View
won't fix his problem, m1.value is still unknown at compile time because he does not have the class definiton in lib.h. Lib.H already includes an extern statement, putting in another one won't help at all.
Chuck O'Toole 22-Mar-12 9:50am View
Sorry, I'm running Windows 7 and your problem is Windows XP related. I also do not install other people's things on my PC. Sorry I cannot be of any help to you.
Chuck O'Toole 21-Mar-12 9:03am View
OnSysCommand() is when Windows is telling you that someone clicked on the menu or buttons to minimize / maximize / close your application and wants you to do something about that. This is different that the *notification* that minimize / maximize / restore has actually happened. You need to handle the OnSize() event / message for that.
Chuck O'Toole 21-Mar-12 2:34am View
Just FYI - the opposite action of "minimize" is not "maximize", it is "restore". Windows have 3 actions. Minimize (to taskbar), Restore (from taskbar) and Maximize (to the size of the screen). Which are you trying to really do?
Chuck O'Toole 15-Mar-12 2:13am View
Aren't you one of the first guys to jump on people for asking for free code to do their homework? How come this guy gets a complete project instead of the lecture about learning from doing homework himself, etc., etc.. Oh, wait, might it be the reference to By the way, this also demonstrates one of your other pet peeves, it's not a question.
Chuck O'Toole 6-Mar-12 10:18am View
Ah, you want my "Computer Examinations for Dummies - Instructor Edition" (it includes the answers). Only $49.95 (USD) at and fine brick and mortar book stores everywhere.
Chuck O'Toole 4-Mar-12 11:42am View
Before the invention of "panes of glass" screens, we used to use the "number of punched cards in the program as a normalization factor". AKA, paying programmers by the pound. The heavier the program deck, the better the programmer.
Chuck O'Toole 3-Mar-12 14:52pm View
he's "hiding" it my moving it into some magic subfolder of "control panel" as well as setting the attribute. Whatever floats his boat.
Chuck O'Toole 3-Mar-12 14:51pm View
You do realize that none of this works if the user enters a filename with a space in it
Chuck O'Toole 3-Mar-12 14:05pm View
How is this any different than the problem you posted the other day?
Chuck O'Toole 3-Mar-12 11:05am View
Jeez, doesn't anybody know how to do things for themselves. "Attrib /?" will give you help on the command. Use that, Learn. Or would you rather we do all the work for you?
Chuck O'Toole 3-Mar-12 11:04am View
Jeez, doesn't anybody know how to do things for themselves. "Attrib /?" will give you help on the command. Use that, Learn. Or would you rather we do all the work for you?
Sorry - wrong place
Chuck O'Toole 1-Mar-12 12:04pm View
Thanks. My primary language is C++ and I use C# occasionally, mostly for providing interfaces from .NET apps to Sockets, Pipes, etc. for C++ apps. I'm not fully conversational in all the Encoding permutations. I'll file that one away for later use.
Chuck O'Toole 27-Feb-12 16:10pm View
Depends on the definiton of "p". For you example to do just what you ask, p would itself have to be a pointer to an int.
int *p;
Chuck O'Toole 27-Feb-12 16:10pm View
Depends on the definiton of "p". For you example to do just what you ask, p would itself have to be a pointer to an *p;
Whoops, wrong place, meant to reply to the other comment
Chuck O'Toole 24-Feb-12 0:11am View
You really need to show the hash1() function.

When you say "input argument _word will change", you need to be more specific. Does the binary value of the pointer "_word" change so that is has a different hexidecimal value or does the string of characters pointed to by "_word" change to a different or clobbered string? Makes a difference.
Chuck O'Toole 20-Feb-12 8:51am View
Thank you, glad to be of help. Now maybe the person who downvoted my answer will re-consider now that it was proven to be spot on.
Chuck O'Toole 19-Feb-12 15:17pm View
Probably the most useful varient of this was on the old IBM 360 line which had "XC", Exclusive Or Characters, which could be used to swap up to 255 8 bit strings at a time. Single "int" temporaries are not as expensive then or now but whole blocks of memory for temps used to be expensive.
Chuck O'Toole 18-Feb-12 22:42pm View
You really need to post the code that calls this "as a thread" or at least the code that creates the thread. If the argument isn't set up correctly, look to the caller, not the callee.
Chuck O'Toole 18-Feb-12 16:46pm View
Reason for my vote of 1
Depends on compiler expression evaluation order, if "a=b" is evaluated first, the whole thing breaks. Also, the compiler is still forced to use temporary locations for intermediate expressions so it does not achieve the stated objective. There are other ways to do this correctly, including the well known "exclusive or" method
Chuck O'Toole 17-Feb-12 16:03pm View
Another point (or two). Note that the Microsoft documentation says that it ignores the first parameter as it is only for compatibility with Berkley sockets so that issue is off the list. Note that there is a comment in your code that says
FD_SET ( 0, &m_rset ); // this adds stdin to the set
implying that "stdin" is OK to add to "select()" yet the error you get is "NOT A SOCKET". stdin is definitely not a socket so it might be that it is complaining about. More magic numbes, "0" appears to mean "stdin" for Linux. Maybe Windows is not happy about that.
Chuck O'Toole 17-Feb-12 15:55pm View
Well, even for Linux the example attached to that documentation seems odd. It does

FD_SET(s1, &fds);
FD_SET(s2, &fds);
rc = select(sizeof(fds)*8, &fds, NULL, NULL, &timeout);

So it sets two arguments into the fds structure and then uses sizeof() and multiplies that by a magic constant 8 as the size argument for select(). It still seems like it relies on some underlying magic if multiplying by 8 after adding 2 arguments is the right thing to do. Personally, I don't think this is very clear documentation at all.
Chuck O'Toole 13-Feb-12 11:49am View
All of my TCP/IP code needs to work on both Unix/Linux and Windows so I use direct calls, not MFC. I'm sorry I cannot be of much help with respect to the MFC Socket Class.
Chuck O'Toole 10-Feb-12 14:35pm View
Do you have the breakpoint where you think it should have the data or do you have the breakpoint on the "recv()" statement to verify that you ever get there?
Chuck O'Toole 7-Feb-12 10:50am View
Also, I don't know how you define "repeated" but the file you point to sure looks like a unique name to me. It may very well be "wrong" but it is definitely not "repeated"
Chuck O'Toole 7-Feb-12 10:49am View
Yeah, what Chris said. Filenames that start with "." are special in Unix and may be supressed in an "ls" listing but will be seen by a programatic search of the directory.
Chuck O'Toole 7-Feb-12 10:47am View
This is correct, "time02 = time_now();" could return the exact same value for the time a thousand times before the clock ticks to the next second. You are not doing "timing based output". As noted, you are doing "iteration based output".
Chuck O'Toole 4-Feb-12 22:22pm View
Technically you should wrap the usage of macro arguments with parens to avoid any expression precedence issues.
#define SQUARE(A) ((A) * (A))
#define min(a,b) (((a) < (b)) ? (a) : (b))
Chuck O'Toole 28-Jan-12 17:25pm View
Please post the relevant client and server code that established the named pipe and the code that attempts the connection on both the client and server. There are lots of ways for this to fail but without your code, we'd only be guessing.
Chuck O'Toole 10-Jan-12 15:44pm View
Years ago I discovered that the Crtl functions allowed '/' for folder separation. I assumed it was DOS'es Unix Roots showing through.
Chuck O'Toole 5-Jan-12 12:47pm View
Double-Clicking on each line will take you to the code for that call. Is "NewCamD_test" your program? If so, the call around line 327 (or the line before) in pre_cpp_init() is the call.

PS, blowing up in a routine called "IsValidHeapPointer()" is a clue in itself, you probably exceeded some structure or array bounds.

you need to learn to debug your code with the tools available, single stepping, etc. I am not going to debug this for you one message at a time.
Chuck O'Toole 5-Jan-12 10:52am View
Crashing where there is "no source code available" usually means off in some library routine you called with bad arguments. When this happens, use the debuggers "stack" window and walk the call frames backwards until you find yourself back in your code. That should identify where *you* called something that blew up.
Chuck O'Toole 4-Jan-12 3:44am View
Don't forget SetFilePointer()
Chuck O'Toole 2-Jan-12 20:11pm View
it would keep moving right until it hit a character that was "not a number". '\0' is "not a number". Also, I noticed you return a double so _atof() is more appropriate than _atoi(). Sorry for missing that.
Chuck O'Toole 2-Jan-12 12:12pm View
Yeah, that's what I have to do.
Chuck O'Toole 31-Dec-11 8:42am View
Remember, "AI" is better than no "I" at all
Chuck O'Toole 29-Dec-11 12:18pm View
2011.11.11 does not tell us if it's or format. What's Christmas look like in this format :)
Chuck O'Toole 27-Dec-11 12:57pm View
Sorry pal, you'll have to ask those to the general forum. I don't have any quick pointers to documents for you and you can search for them just as easily as I could.
Chuck O'Toole 26-Dec-11 8:26am View
please 'accept' this answer so your problem will be marked as "solved"
Chuck O'Toole 26-Dec-11 8:25am View
Please 'accept' this answer so your question will be marked as solved.
Chuck O'Toole 25-Dec-11 20:29pm View
Nope, sorry. In the code above, all instances of unary ++ or -- are in single statements for loop control. i++ or ++i have absolutely no difference in how it affects i in those statements, same thing for j. Yes, the order of operations may be inportant in other type of uses for unary ++ or -- but not in this instance and it is not the source of whatever perceived problem this user has. Note that both SA and I have built the code the OP posted and do not have the problem.
Chuck O'Toole 23-Dec-11 17:07pm View
Ah, you totally changed your solution so now my comment is out of context. Might as well delete it.
Chuck O'Toole 23-Dec-11 17:05pm View
Haha, Google Translate even changed the "fr-FR" to "en-US" in the code part. Good one :)
Chuck O'Toole 23-Dec-11 17:02pm View
Thank God for Google Translate:

I've thought about this solution but the problem is that I have an application that runs a program and this program is launching a program through a service (windows service).
The pogramme launched by the service windows (system account) has a different culture from that of the normal user and it is not possible to change the culture simply by "System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo ("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = culture; "
You know what i want to do?.
Chuck O'Toole 23-Dec-11 16:42pm View
Just curious, how would you like it if every time you ran my application, I set your PC's settings to US-English, Eastern Time Zone, US $ currency?
Chuck O'Toole 23-Dec-11 16:40pm View
Absolutely agree. The application does not "own" the PC it runs on and it is quite arrogant to think that the application can and should change things like the global culture, language, number format, etc.
Chuck O'Toole 23-Dec-11 16:37pm View
while that is true, since he does absolutely nothing with the value returned from the plus function, I can't see how that caused bad memory references. What is true is that he's moving around some large objects on the stack but not enough to cause a stack overflow, on my system anyway.
Chuck O'Toole 23-Dec-11 16:02pm View
Dunno dude, it doesn't blow up for me. Using VS2008.
Chuck O'Toole 23-Dec-11 8:12am View
Albert, he is doing that for the element in the list:
delete list[i];
But he's expecting something to reach up into the other place that points to the memory, value and zap it too. That ain't happening.
Chuck O'Toole 23-Dec-11 7:55am View
I read the article and it does make it clear that ASSERT is useful in debugging but it also states that ASSERT is not a substitute for good error handling. Too often, people write ASSERT statements *instead* of handling the error properly. For example, doing an "ASSERT (ptr != NULL)" after a malloc() statement will allow you to proceed with a null pointer in RELEASE mode so you will still need an intelligent error process to deal with the fact that you ran out of memory. Too many (bad) programmers rely on DEBUGGING tools to find things and leave out the RELEASE mode checks for conditions. For this reason, I do not like ASSERT. I use my own Macro that is an ASSERT in DEBUG and a call to Throw an Exception in RELEASE. That way, the logic is always tested and the code does not plod onwards with bad values in RELEASE mode.
Chuck O'Toole 21-Dec-11 8:57am View
Dude, there are lots of ways to screw up client/server communications. Without seeing any of your code, we have no way of knowing which one you chose.
Chuck O'Toole 21-Dec-11 8:49am View
Consider two people using remote desktop to log into a server. On that server, define what you mean by "currently logged in user", there are two distinct ones.
Chuck O'Toole 20-Dec-11 13:15pm View
Oh, sorry for the "4", I mis-clicked and now it won't let me go back and fix it.
Chuck O'Toole 20-Dec-11 13:14pm View
Agreed, there is nothing "Special" about the folder name "Program Files" on the "D" drive, it's just another name.
Chuck O'Toole 20-Dec-11 12:47pm View
Actually, your question was "why when I use 1 millisecond that result seem incorrect?" and that's what I answered. If you want to know about QueryPerformanceFrequency(), that's a whole other question.
Chuck O'Toole 20-Dec-11 11:21am View
Yo dude, there are at least 10 API calls that deal with Pipes and every one of then can return INVALID_HANDLE. Since I cannot see your screen nor read your mind, you'll need to be more forthcoming with information.
Chuck O'Toole 19-Dec-11 13:25pm View
Ha, didn't see that. It popped up on the radar because of solution 3. Prashant answered the original question a few 20 minutes before I did so I just followed through.
Chuck O'Toole 19-Dec-11 13:04pm View
Generically, if a program takes a long time to start up the first time and then starts up faster the 2nd thru nth time, the reason is probably loading DLLs or assemblies into memory. The first time, the cost of doing this is high, subsequent loads probably get the DLL / assembly from cache (disk cache or memory cache). So, unless you are really sure of what fixed your problem, you may just be seeing that it loads faster this time but the underlying problem may still be around.
Chuck O'Toole 19-Dec-11 11:26am View
Wow, deja vu. This was my final homework assignment for Computer Science 1 in 1966. They're still using it! Of course, that was before the internet so I had to do it myself.
Chuck O'Toole 15-Dec-11 20:28pm View
both modules need to declare "x" as extern. That way, the module with the definiton "offers the variable to the global linker name space" while the other module "looks for something appearing in the global linker name space"
Chuck O'Toole 15-Dec-11 20:25pm View
FYI - you should respond to people's answers using the "Have a Question or Comment" found in each answer. That is what I am doing now. This way, the person gets an e-mail when you respond, otherwise your additional comment / question just sits here until I came back here by chance to read it.
Chuck O'Toole 15-Dec-11 1:58am View
Oh, I don't know about this. Isn't it more natural to ask a person a question and have then enter "y" or "n" (or the whole words "yes" or "no"). Humans don't generally answer yes/no questions with 0/1. It's up to a programmer to make thing easier on the human, not the other way around. Fix the code to read a string.
Chuck O'Toole 14-Dec-11 23:56pm View
Sounds like something from a Mutual Fund Prospectus
Chuck O'Toole 14-Dec-11 16:05pm View
Read my updated solution
Chuck O'Toole 14-Dec-11 16:05pm View
Read my updated solution
Chuck O'Toole 14-Dec-11 14:56pm View
Yes, it has to really be in the GUI thread and used during the process of some event that starts the long running process. The rule is kind of "do threads or do a message pump but don't do both".
Chuck O'Toole 14-Dec-11 14:50pm View
Thanks, my bad :)
Chuck O'Toole 7-Dec-11 20:23pm View
you know, I hate it when someone posts something without having any context first. Like the fact that the original poster has a long history of just dumping things into these forums without doing any research for themselves. At some point, you just have to tell them to lookup things themselves first. Learn how to fish. Of course, the "go google this" also included the relevant link for the answer. Thanks for playing.
Chuck O'Toole 6-Dec-11 13:59pm View
MS Policies wouldn't be much good if there was an easy way around them, like CMD prompt. Of course, you could always disallow cmd.exe too.
Chuck O'Toole 5-Dec-11 22:03pm View
that's "explorer", not "iexplorer". But it is part of a larger group policy setting. See the "technet" entry in this search
Chuck O'Toole 5-Dec-11 13:25pm View
Why not just delete the sucker
Chuck O'Toole 28-Nov-11 23:21pm View
perform a simple "problem isolation" experiment. Reduce your WndProc() to be just the "return DefWindowProc()" statement. If everything is working then, it's your code not getting to that on non-minimize messages. If it still doesn't move or maximize, then there's another problem. Step one is to determine where to look.
Chuck O'Toole 28-Nov-11 20:24pm View
When do you try to "but I cannot move or maximize or close window"? Before or After it is hidden? Before should work just fine. As for after, well seriously, once you hide it how do you expect to click on it again or bring it back?
Chuck O'Toole 26-Nov-11 11:52am View
There is no leak in that code. How'd you determine that there was?
Chuck O'Toole 24-Nov-11 11:25am View
Well, beside, as Richard says, the line doing nothing functional, you increment the Idx index *before* doing the statement so Idx does not point to the data you just filled in. Should it ever try to do something useful, it's using the wrong (or uninitialized) data.
Chuck O'Toole 21-Nov-11 9:23am View
ha, not a good example for showing printing out the numbers in reverse, 17 decimal = 1001 binary = a palendrome. Did you print it out forwards or backwards :)
Chuck O'Toole 20-Nov-11 7:06am View
What does GetLastError() say after CreateWindowEx() returns NULL?
Chuck O'Toole 20-Nov-11 7:06am View
What does GetLastError() say after CreateWindowEx() returns NULL?
Chuck O'Toole 19-Nov-11 22:33pm View
z = (x/1);

is simply

z = (int)x;
Chuck O'Toole 19-Nov-11 22:20pm View
Sorry but I don't see anything here that instantiates the class, inits, or calls the create function.
Chuck O'Toole 18-Nov-11 16:55pm View
Are you asking how to popup your own menu when somebody clicks on the icon you've already placed in the system tray?
Chuck O'Toole 18-Nov-11 11:12am View
The site you reference also has a complete and active Forum section where people who are expert in this thing lurk. You'll probably get better answers there.
Chuck O'Toole 18-Nov-11 11:11am View
The site you reference also has a complete and active Forum section where people who are expert in this thing lurk. You'll probably get better answers there.
Chuck O'Toole 18-Nov-11 11:11am View
The site you reference also has a complete and active Forum section where people who are expert in this thing lurk. You'll probably get better answers there.
Chuck O'Toole 18-Nov-11 8:05am View
have you used the debugger to tell you which line of your code is the culprit? You may have to follow the stack frame back to find your code as the error may be in a library routine barfing on your input parameters.

Did you properly initialize 'addrlen', it's an Input/Output parameter in the accept() call (
Chuck O'Toole 17-Nov-11 19:47pm View
PS, I went to the web site, there are hundreds of entries in that library. I'm not going to spend a lot of my time (actually, not any of my time) digging through all that. You are either calling functions that do not exist in that library at all as Albert suggests or there is some other issue that we cannot yet see. Provide the additional details as requested.
Chuck O'Toole 17-Nov-11 19:38pm View
I asked you to post the floatfann.h file. Have you done so? We're just guessing at what the .h file looks like so don't be surprised if we guess wrong until you post it.
Chuck O'Toole 17-Nov-11 16:27pm View
post the floatfann.h file so we can see what the definitons look like
Chuck O'Toole 17-Nov-11 14:05pm View
Oh I disagree, this is a terrible response. The OP is clearly trying to learn yet this example starts off by showing a NULL for the object, not allocating it and then jumps into assembly code to show some obscure point about not crashing for one reason or another. Talk about confusing someone who's trying to learn. My 1.

void caller()
SampleCode* p = NULL;
Chuck O'Toole 17-Nov-11 11:45am View
thanks, BTW, nothing stops you from accepting more than one answer :)
Chuck O'Toole 17-Nov-11 11:36am View
Oh, answer collision with Solution 1.
Chuck O'Toole 17-Nov-11 10:39am View
My guess is that the finder object has the directory that it is searching "open" so you could not delete the directory as it was "in use". The files themselves however, were not "open". finder only returns the names, it doesn't try to open the files.
Chuck O'Toole 17-Nov-11 10:13am View
Yeah, I was thinking you want to move the finder.Close() to before you try to delete the directory.
Chuck O'Toole 16-Nov-11 11:27am View
whoops, had that in my real code, forgot to type it here. Thanks, I updated the solution to reflect this.
Chuck O'Toole 14-Nov-11 22:11pm View
HA. Didn't see that, I read that as you intended, not as written. Nice catch.
Chuck O'Toole 14-Nov-11 22:06pm View
The doc on the IP control says you have to

"Creating an IP Address Control
Before creating an IP address control, call InitCommonControlsEx with the ICC_INTERNET_CLASSES flag set in the dwICC member of the INITCOMMONCONTROLSEX structure.

before using it. I assume you did that.
Chuck O'Toole 14-Nov-11 22:03pm View
Well, at least I was right that you weren't getting to the EndDialog() :)

The doc on IPM_GETADDRESS is pretty straightforward so there can only be a few issues. IDC_IPADDRESS1 isn't properly defined to be in IDD_DIALOG1 or the Control itself isn't created properly. I don't use that control myself and don't have any experience with it.
Chuck O'Toole 13-Nov-11 15:45pm View
FYI - it's in the standard so every compiler / RTL has to allow it. That doesn't mean it's a good thing to do.
Chuck O'Toole 13-Nov-11 15:34pm View
Ignore my previous reply (I deleted it but you probably saw it in e-mail), it was to a different question you asked. Yes, you have some things of type "xyz" in the "global scope" and some in the "local scope". Locals go on the stack, the others are in the main data space.
Chuck O'Toole 13-Nov-11 15:31pm View
Yes. union only defines the content/layout of an object, much like "struct" does. You still need to declare a variable of that type (union or struct) and it's where/how you declare that variable that matters (and how the compiler finds it).
Chuck O'Toole 11-Nov-11 10:59am View
What does the processing of ON_WM_SYSCOMMAND have to do with this question? And hey, I recognize that, didn't I post that to some other question you asked over here (
Chuck O'Toole 10-Nov-11 11:46am View
when he says "project" I think we should read "assignment"
Chuck O'Toole 10-Nov-11 9:45am View
Remember, only your friend can see your privates :)
Chuck O'Toole 9-Nov-11 9:55am View
Interesting that the linker says it can't a function that take three "unsigned char" arguments yet you are calling it with three "boolean" arguments. Regardless of the linker issue, are you sure you're calling this correctly?
Chuck O'Toole 8-Nov-11 23:41pm View
What better affirmation is there than watching your own code compile and execute properly? My "eyeballing" the code won't help a bit.
Chuck O'Toole 8-Nov-11 23:26pm View
Are you asking if I think it will work? Wouldn't trying it be the better way of finding out?
Chuck O'Toole 8-Nov-11 22:42pm View
And after all your discussion with Richard in your other question ( you should see that the error is telling you that you are using a "wide string" when the function takes a "char *" string. You've already done the conversion from string to wstring in that question, now do the reverse.

This is the problem with just cut / paste other people code and suggestions without understanding what is going on. You've now mixed wide and regular strings in your code and are having to deal with the consequences.
Chuck O'Toole 8-Nov-11 15:32pm View
Well, I understand the notion of separation of "access rights" within the domains, almost a "C2 level" separation with rights. I also get the idea of "marshalling" the arguments that cross the API calls. However, the documentation / description talks about "starting and stopping other Application Domains" almost as if they were separate execution "entities" within the process. Now if all that means is "loading" or "unloading" assemblies, then I get it. It's just the reference to "start / stop" that bothers me. I also read about "separate virtual address space" in the domains. The question is, does the address ranges overlap? That is, are they really separate address spaces or is the one big address space broken up into multiple "protection zones" that only certain domains can access (the rights thing). If it's just protection zones, then I get that too, using "portal instructions" to jump from one level of access to another. Otherwise you are dealing with an entire duplicate memory management system for each domain within a process and that's something I'd have to figure out.
Chuck O'Toole 8-Nov-11 14:27pm View
Hummm, Application Domains are a relatively new concept for me, I'll have to read up on those to understand how the addressing / process context works out to allow for multiple applications to run within the process family. Something new to figure out.
Chuck O'Toole 8-Nov-11 14:14pm View
Well, "declared" is rather ambiguous, does he mean the "actual location of the statement the defines the variable" or the "creating of the object (e.g., CreateEvent()) in another thread"? It turns out that it's really not important where / which thread does the "Create" function, the object created (via its "handle") is visible to the entire process / thread family. What is important is the "scope" of the reference to the variable, could be global, could be passed by value (HANDLE) or could be only scoped to be referenced in one thread. So if you're going to look at this as a 'newbie' type question, you have to allow for the imprecise use of "declared" to mean more than the placement of the variable name.
Chuck O'Toole 8-Nov-11 14:07pm View
did you miss the statement "Stack (one per thread)" in talking about the address space? How much more explanation is needed? I also said " careful of is passing the address / pointer to a variable that lives in the stack space of a function / thread". That should be enough for this level of reply, I'm not writing a document on memory allocation after all.
Chuck O'Toole 8-Nov-11 10:00am View
That's what I said :) Split it with you :)
Chuck O'Toole 8-Nov-11 9:48am View
Well, technically he did answer this part of your question "How one thread gets access to the syncronization variable declared in another thread?" so don't be too harsh :)
Chuck O'Toole 8-Nov-11 9:36am View
It's a veritable family reunion, see here:
and here:
Chuck O'Toole 8-Nov-11 9:33am View
Hey jyotymol, are you related to jyoty who posted this : ?
Chuck O'Toole 8-Nov-11 9:31am View
I am in urgent need of getting paid to provide such code to a customer.
Chuck O'Toole 8-Nov-11 8:34am View
Put in your name and phone number so some future debugger can call you in on a consultation. Don't forget to charge more when they do.