Showing tag results for Code

Aug 12, 2008
Post comments count0
Post likes count0

The implementation of iterators in C# and its consequences (part 1)

Raymond Chen
Raymond Chen

Like anonymous methods, iterators in C# are very complex syntactic sugar. You could do it all yourself (after all, you did have to do it all yourself in earlier versions of C#), but the compiler transformation makes for much greater convenience. The idea behind iterators is that they take a function with yield return statements (and possible s...

Code
Aug 11, 2008
Post comments count0
Post likes count1

Psychic debugging: Why can’t StreamReader read apostrophes from a text file?

Raymond Chen
Raymond Chen

As is customary, the first day of CLR Week is a warm-up. Actually, today's question is a BCL question, not a CLR question, but only the nitpickers will bother to notice. Can somebody explain why StreamReader can’t read apostrophes? I have a text file, and I read from it the way you would expect: StreamReader sr = new StreamReader("myfil...

Code
Aug 8, 2008
Post comments count0
Post likes count1

If you return FALSE from DLL_PROCESS_ATTACH, will you get a DLL_PROCESS_DETACH?

Raymond Chen
Raymond Chen

If you return from , will you get a ? Yes. No. ... Yes. All three answers are correct, for different formulations of the question. From the kernel's point of view, the answer is a simple Yes. If a DLL's entry point returns to the notification, it will receive a notification. However, most C and C++ programs do not use the ra...

Code
Aug 6, 2008
Post comments count0
Post likes count1

The caret serves as the continuation character for batch files

Raymond Chen
Raymond Chen

We saw earlier that the caret is the escape character for the batch language. In a comment to that article, KJK::Hyperion mentioned that the caret serves as the line continuation character. A useful tip if you still find yourself messing with batch files. Mark Yocum elaborates on this point a bit more.

Code
Aug 1, 2008
Post comments count0
Post likes count1

I warned you: The dangers of attaching input queues

Raymond Chen
Raymond Chen

Some people didn't take to heart my cautions on the subject of attached input queues, item number five on the list of five things every Win32 programmer should know. And then they find that their application stops responding. // Code in italics is wrong void TryToStealFocus(HWND hwnd) { // First try plain SetForegroundWindow SetForegroundWi...

Code
Jul 25, 2008
Post comments count0
Post likes count1

Simulating a drop, part two

Raymond Chen
Raymond Chen

Last time, we wrote a tiny program to simulate dropping a file on another file, but we discovered that it didn't work for dropping a file onto Mail Recipient.MAPIMail. The reason, as you no doubt instantly recognized, is that the MAPIMail handler creates a worker thread, and we're exiting the process before the worker thread has finished its work....

Code
Jul 24, 2008
Post comments count0
Post likes count1

Reading a contract from the other side: Simulating a drop

Raymond Chen
Raymond Chen

Most people, when they think of the IDropTarget interface, think only of implementing a drop target. But you can read the contract from the other side, because the description of how a drag source interacts with a drop target tells you how to be a drag source. To summarize, the sequence of drop target operations go like this: IDropTarget::Drag...

Code
Jul 23, 2008
Post comments count0
Post likes count1

Theorize if you want, but if the problem is right there in front of you, why not go for the facts?

Raymond Chen
Raymond Chen

On an internal discussion list, somebody asked a question similar to this: My program launches a helper program. This helper program does different things based on the command line parameters, but the way I'm using it, it just prints its results to the console and exits. When I launch this program and wait for it to exit, my wait never completes....

Code
Jul 21, 2008
Post comments count0
Post likes count1

MessageBoxIndirect loads the icon itself; you can’t hand it a pre-loaded icon

Raymond Chen
Raymond Chen

Commenter 8 wants to know how to tell the function to use an existing instead of pointing it to an icon resource. You can't. The loads the icon itself. You can't hand it a pre-loaded icon. Of course, it's hardly rocket science to write your own function that lets you use whatever icon you want. There's no law that says all Yes/No dialo...

Code