The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts
Keep your eye on the code page: C# edition (the mysterious third code page)
A customer was having trouble manipulating the console from a C# program: We found that C# can read only ASCII data from the console. If we try to read non-ASCII data, we get garbage. Observe that this program is unable to read the Å and ö characters. They come back as garbage. Although there are three code pages that have special treatment in Windows, the CLR gives access to only two of them via . CharSet.Ansi = CP_ACP CharSet.Unicode = Unicode (which in Windows means UTF16-LE unless otherwise indicated). Unfortunately, the console traditionally uses the OEM code page. Since the ...
Keep your eye on the code page: C# edition (warning about DllImport)
Often, we receive problem reports from customers who failed to keep their eye on the code page. Does the function support files with non-ASCII characters in their names? We find that the function either fails outright or returns question marks when asked to provide information for files with non-ASCII characters in their name. If we ask for the display name, the function fails even though the file does exist. If we also pass the flag to force the system to act as if the file existed, then it returns the file name but with question marks where the non-ASCII characters should be. The function supports ...
Revival of the Daleks: Act One, Scene One
In 2009, a group of volunteers on a routine cleanup of a pond in Hampshire, England discovered a Dalek. (Later in the episode, the story may introduce a scientist who is thawing out a 30,000-year-old-virus.)
If you want to set a thread's apartment model via Thread.CurrentThread.ApartmentState, you need to act quickly
Welcome to CLR Week 2014. Don't worry, it'll be over in a few days. A customer wanted to know why their was displaying the infamous Current thread must be set to single thread apartment (STA) mode before OLE calls can be made error. "Even though we set the to , the apartment state is still . Curiously, if we put the above code in a standalone test program, it works fine." The problem is that the customer is changing the apartment state too late. On the first call to unmanaged code, the runtime calls CoInitializeEx to initialize the COM apartment as either an MTA or an STA apartment. You can...
The case of the orphaned LpdrLoaderLock critical section
A customer found that under heavy load, their application would occasionally hang. Debugging the hang shows that everybody was waiting for the critical section. The catch was that the critical section was reported as locked, but the owner thread did not exist. How can a critical section be owned by thread that no longer exists? There are two ways this can happen. One is that there is a bug in the code that manages the critical section such that there is some code path that takes the critical section but forgets to release it. This is unlikely to be the case for the loader lock (since a lot of really smart ...
The latest technologies in plaintext editing: NotepadConf
On November 13, 2014 November 14, 2014, Saint Paul, Minnesota will be the home to NotepadConf, which bills itself as "the premier technology conference for Notepad.exe users and text enthusiasts." I'm still not sure whom Microsoft will send to the conference, but maybe that person could give a talk on how you can use Notepad to take down the entire Internet. Update: The conference has been rescheduled to Friday the 14th.
Since clean-up functions can't fail, you have to soldier on
Clean-up functions can't fail, so what do you do if you encounter a failure in your clean-up function? You have to keep cleaning up. Some people like to follow this pattern for error checking: And some like to put it inside a cute flow control macro like or even Whatever floats your boat. But you have to be careful if using this pattern in a clean-up function, because you might end up not actually cleaning up. For example: What if there is an error disconnecting the doodad? (Maybe you got because the doodad lives on a remote server which crashed.) The cleanup code treats this as an error and...
Why does Explorer say "File too large" for my custom file system, when the problem has nothing to do with the file being too large (heck it's not even a file)
When Explorer copies files around, it doesn't really know what the maximum file size supported by any file system happens to be. (That information is not reported by .) So it guesses. If the file system name is or , then Explorer assumes that the maximum file size is 4GB − 1. Also, if a file operation fails with the error , and Explorer can't figure out why the parameter is invalid, it assumes that the reason is that the file has exceeded the maximum allowed file size. Why does Explorer map "invalid parameter" to "file size too large"? Because some file systems use to report that a file is too large in...
Microspeak: 1 – 1 is not zero
In his reddit AMA, Joe Belfiore wrote i have regular 1-1 meetings with my counterparts in Office, Skype, Xbox. The little bit of jargon there is 1-1 meeting. This is an abbreviation for one-on-one meeting, a common business practice wherein two people, typically a manager and a direct report, have a face-to-face meeting with no one else present. In the case Joe used, the meeting is not between a manager and a direct report but between two peers. The term is also abbreviated 1:1, which like 1 − 1 also looks like a bit of mathematical nonsense. But it's not zero or one. It's just an abbreviation for bu...