Showing tag results for Code

Aug 1, 2012
Post comments count0
Post likes count2

How do I find the most recently created file in a directory from a batch file?

Raymond Chen
Raymond Chen

We've reached Hump Day of Batch File Week. Remember, nobody actually likes batch programming. You merely tolerate it. Today, we'll find the most recently-created item in a directory. (For example, we have a server that holds our daily builds, and you might want to write a batch file that automatically installs the latest build.) There may be b...

Code
Jul 31, 2012
Post comments count0
Post likes count4

Reading the output of a command into a batch file variable

Raymond Chen
Raymond Chen

It's Day Two of Batch File Week. Don't worry, it'll be over in a few days. There is no obvious way to read the output of a command into a batch file variable. In unix-style shells, this is done via backquoting. The Windows command processor does not have direct backquoting, but you can fake it by abusing the command. Here's the evolution: ...

Code
Jul 30, 2012
Post comments count0
Post likes count1

Why don't any commands work after I run my batch file? I'm told that they are not recognized as an internal or external command, operable program, or batch file.

Raymond Chen
Raymond Chen

I sort of forgot to celebrate CLR Week last year, so let's say that CLR week is "on hiatus" until next year. To fill the summertime time slot, I'm going to burn off a busted pilot: This week is Batch File Week 2012. Remember, nobody actually enjoys batch programming. It's just something you have to put up with in order to get something done. Batch...

Code
Jul 27, 2012
Post comments count0
Post likes count1

Psychic debugging: Why your IContextMenu::InvokeCommand never gets called

Raymond Chen
Raymond Chen

A customer reported a problem with their shell context menu extension. I have implemented the shell extension, but when the user selects my custom menu item, my is never called. Can anyone please let me know what the problem could be and how to fix it? Since there really isn't much information provided in this request, I was forced to invoke m...

Code
Jul 25, 2012
Post comments count0
Post likes count1

One way to make sure you pass an array of the correct size

Raymond Chen
Raymond Chen

Another entry in the very sporadic series of "very strange code I've seen." The code has been changed to protect the guilty, but the essence has been preserved.

Code
Jul 19, 2012
Post comments count0
Post likes count1

Why do some font names begin with an at-sign?

Raymond Chen
Raymond Chen

It was a simple question. For some reason, my font selection dialog () shows a bunch of font names beginning with the at-sign (@). These fonts don't work correctly if I use them. Any idea what they are? (I tried searching the Internet, but search engines don't seem to let you search for so it's hard to make much headway.) (And that's why I...

Code
Jul 13, 2012
Post comments count0
Post likes count1

Why doesn't RealGetWindowClass return the real window class for my superclass?

Raymond Chen
Raymond Chen

A customer was reporting that the function was not reporting the base window class of their superclass. (Error checking has been elided for expository purposes.) The customer found that the assertion fails, returning a window class name of "AwesomeWindow" instead of "static". "I thought the point of RealGetWindowClass was to dig through the su...

Code
Jul 12, 2012
Post comments count0
Post likes count1

What happens when you mark a section as DISCARDABLE?

Raymond Chen
Raymond Chen

In the flags you pass to the linker, you can specify that a section be made discardable. What does that mean? If you are a kernel-mode driver, the discardable flag means that the contents will be removed from memory after initialization is complete. This is where you put your initialization code and data. But if you're writing user-mode code, t...

Code
Jul 5, 2012
Post comments count0
Post likes count1

How your taskbar auto-hide settings can keep getting overwritten

Raymond Chen
Raymond Chen

A customer reported that they were observing that some users were finding their taskbar set to auto-hide even though the standard configuration in the company is for the auto-hide feature to be disabled. Going into Taskbar Properties shows Auto-hide the taskbar checked. None of the users had changed their setting to auto-hide manually, so the quest...

Code
Jun 28, 2012
Post comments count0
Post likes count1

You still need the "safe" functions even if you check string lengths ahead of time

Raymond Chen
Raymond Chen

Commenter POKE53280,0 claims, "If one validates parameters before using string functions (which quality programmers should do), the 'safe' functions have no reason to exist." Consider the following function: What could possibly go wrong? You check the length of the string, and if it doesn't fit in the buffer, then you reject it. Therefore, y...

Code