Showing tag results for Code

Jun 12, 2014
Post comments count0
Post likes count0

Can we continue to call FindNextFile() with the same handle that returned an error last time?

Raymond Chen
Raymond Chen

A customer wanted to know whether it was okay to call with the same handle that returned an error last time. In other words, consider the following sequence of events: The customer elaborated: Suppose that the directory contains four files, A, B, C, and D. We expect the following: After returns an error, can we continue to search with th...

Code
Jun 9, 2014
Post comments count0
Post likes count0

Improving the performance of CF_HDROP by providing file attribute information

Raymond Chen
Raymond Chen

The clipboard format is still quite popular, despite its limitation of being limited to files. You can't use it to represent virtual content, for example. For all of you still using , you can improve the performance of drag/drop operations by adding a little more information to your data object. Observe that the clipboard format is just a l...

Code
Jun 5, 2014
Post comments count0
Post likes count0

Closing over the loop variable is just as harmful in JavaScript as it is in C#, and more cumbersome to fix

Raymond Chen
Raymond Chen

Prerequisite reading: Closing over the loop variable considered harmful. JavaScript has the same problem. Consider: The most common case where you encounter this is when you are hooking up event handlers in a loop, so that's the case I used as an example. No matter which button you click, they all alert , rather than the respective button ...

Code
Jun 2, 2014
Post comments count0
Post likes count0

Obtaining information about the user's wallpaper on multiple monitors

Raymond Chen
Raymond Chen

Today we're going to dump information about the user's wallpaper settings on multiple monitors. The idea is simple. You use the interface on the object to get information about the desktop wallpaper. It will tell you the wallpaper positioning information, whether a single image is being used for all monitors, where those monitors are, and whic...

Code
May 30, 2014
Post comments count0
Post likes count0

Why does GetFileVersionInfo map the whole image into memory instead of just parsing out the pieces it needs?

Raymond Chen
Raymond Chen

Commenter acq responds (with expletive deleted), "the whole file is mapped into the process' memory only for version info that's certainly only a few kilobytes to be read?" Why not map only the parts that are needed? "I don't understand the necessity to map the whole file except that it was easier to write that code without thinking too much." Tha...

Code
May 26, 2014
Post comments count0
Post likes count0

Find the index of the smallest element in a JavaScript array

Raymond Chen
Raymond Chen

Today's Little Program isn't even a program. It's just a function. The problem statement is as follows: Given a nonempty JavaScript array of numbers, find the index of the smallest value. (If the smallest value appears more than once, then any such index is acceptable.) One solution is simply to do the operation manually, simulating how you wo...

Code
May 23, 2014
Post comments count0
Post likes count0

Why is the debugger telling me I crashed because my DLL was unloaded, when I see it loaded right here happily executing code?

Raymond Chen
Raymond Chen

A customer was puzzled by what appeared to be contradictory information coming from the debugger. We have Windows Error Reporting failures that tell us that we are executing code in our DLL which has been unloaded. Here's a sample stack: But if we ask the debugger what modules are loaded, our DLL is right there, loaded as happy as can be: ...

Code
May 22, 2014
Post comments count0
Post likes count0

Why does my radio button group selection get reset each time my window regains activation?

Raymond Chen
Raymond Chen

A customer reported (all incomplete information and red herrings preserved): We have an issue related to two radio buttons in a window. The code programmatically checks the second button by sending the message. We observe that if the user clicks somewhere else on the screen (so that our application loses focus), and then clicks on the taskbar i...

Code