devblogs.microsoft.com/oldnewthing

订阅源链接共 12 篇文章

Super Bowl LX creates an opportunity for symphonic friendly wagering

This upcoming Sunday is Super Bowl LX, the championship game of the top professional American football league. The Super Bowl thinks that it is so important that it uses Roman numerals.) The Super Bowl is the single largest sporting event in the United States. The entire country grinds to a halt when the game is on . If you aren’t interested in the game, it’s a great time to do public photography or run errands . Traditionally, the mayors of the home cities of the two teams competing...

2026-02-04 15:00原文链接
未翻译

How can I prevent the user from changing the widths of ListView columns?

Suppose you are using a Win32 ListView control in report mode, and you’ve got all your columns set up perfectly, and you don’t want the user to resize them. How do you do that? There is no ListView style for preventing column resize, but there is a header control style to prevent sizing: HDS_NOSIZING . This style requires Common Controls version 6, but I’m sure you’re all using that version already, right? auto hdr = ListView_GetHeader(hwndLV); SetWindowLong(hdr, GWL_STYL...

2026-02-04 15:00原文链接
未翻译

Some small stories about the giant satellite dish antenna that was behind Microsoft Building 11

Back in the day, if you wandered into the parking area behind Building 11 on the original Redmond Microsoft campus, you would find a very large satellite dish antenna. This antenna was used for receiving video signals, such as cable television feeds for distribution to the Redmond campus. One purpose was to provide cable TV service for internal development and testing to teams like the Windows Media Center team and later the Xbox One team. The satellite dish antenna was a Simulsat-5 which was ca...

2026-02-03 15:00原文链接
未翻译

Studying compiler error messages closely: Input file paths

A colleague was working in a project that used a number of data files to configure how the program worked. They wanted one portion of the configuration file to be included only if a particular build flag was set. Let’s say that the configuration file is C:\ repos\ contoso\ config\ Contoso.config . <providers> <!-- Widget version should be 1.0, or 2.0 if the useV2Widgets build flag is set --> <provider name="Widget" version="1.0"/> <!-- Gadget is needed only if the useV...

2026-02-02 15:00原文链接
未翻译

Why not store the SAFEARRAY reference count as a hidden allocation next to the SAFEARRAY?

When I described how Safe­Array­Add­Ref keeps its reference count in a side table , commenter Koro Unhallowed wondered why we couldn’t store the reference count either before or after the formal SAFEARRAY structure . Commenter Peter Cooper Jr. suspected that there might be cases where applications assumed how much memory a SAFEARRAY occupied . And indeed that is the case. Not all SAFEARRAY s are created by the Safe­Array­Create function. I’ve seen code that declared and filled out th...

2026-01-30 15:00原文链接
未翻译

How can I retain access to the data in a SAFEARRAY after my method returns?

The original problem our customer had was that the data in a SAFEARRAY disappeared even though they had called Safe­Array­Add­Ref . We learned why this is the case, but we still have to solve the customer’s problem: How can they extend the lifetime of a SAFEARRAY beyond the method that received it? The SAFEARRAY is a unique-owner object. Once the owner calls Safe­Array­Destroy , the array is gone. You can extend the lifetime of the memory with Safe­Array­Add­Ref , but the data itself has v...

2026-01-29 15:00原文链接
未翻译

Why did I lose the data even though I called Safe­Array­Add­Ref?

A customer had a method that received a SAFEARRAY , and they called Safe­Array­Add­Ref to add a reference to it so that they could continue using the array after the method returned, but they found that if they tried to use the array later, the safearray->pData was NULL , and if they called Safe­Array­Add­Ref again, it also gave them a null data pointer. They wanted to know if this was expected behavior. “Does COM invalidate a SAFEARRAY when a method returns, ignoring the reference coun...

2026-01-28 15:00原文链接
未翻译

A digression on the design and implementation of Safe­Array­Add­Ref and extending APIs in general

Last time, we learned about the difference between Safe­Array­Access­Data and Safe­Array­Add­Ref . I noted that Safe­Array­Add­Ref was a latecomer that was added to an existing API and that one of the design concerns was to minimize the impact upon existing code. When extending an existing API, a major concern is what the new feature means for people who were using the earlier version of the API. One design principle for extending an API is “pay for play”: Programs can call the new A...

2026-01-27 15:00原文链接
未翻译

What’s the difference between Safe­Array­Access­Data and Safe­Array­Add­Ref?

Once upon a time, there was SAFEARRAY , the representation of an array used by IDispatch and intended for use as a common mechanism for interchange of data between native code and scripting languages such as Visual Basic. You used the Safe­Array­Create function to create one, and a variety of other functions to get and set members of the array. On the native side, it was cumbersome having to use functions to access the members of an array, so there is also the Safe­Array­Access­Data function tha...

2026-01-26 15:00原文链接
未翻译

C++ has scope_exit for running code at scope exit. C# says “We have scope_exit at home.”

The Windows Implementation Library (commonly known as wil) provides a helper called scope_exit which creates and returns an RAII object whose destructor runs the lambda you specify. This helper provides roughly equivalent functionality in C++ to what is called try … finally in other languages such as C#. // If there is an active primary Gadget, then do a bunch of stuff, // but no matter what, make sure it is no longer active when finished. var gadget = widget.GetActiveGadget(Connection.Pri...

2026-01-23 15:00原文链接
未翻译

A simple helper function for attaching a progress handler to a Windows Runtime IAsync­Action­With­Progress or IAsync­Operation­With­Progress

The Windows Runtime has interfaces IAsync­Action and IAsync­Operation<T> which represent asynchronous activity: The function starts the work and returns immediately, and then it calls you back when the work completes. Most language projections allow you to treat these as coroutines, so you can await or co_await them in order to suspend execution until the completion occurs. There are also progress versions of these interfaces: IAsync­Action­With­Progress<P> and IAsync­Operation­With­...

2026-01-22 15:00原文链接
未翻译

On the proper usage of a custom Win32 dialog class

Some time ago, I discussed custom dialog classes . You can specify that a dialog template use your custom dialog class by putting the custom class’s name in the CLASS statement of the dialog template. A customer tried doing that but it crashes with a stack overflow. // Dialog template IDD_AWESOME DIALOGEX 0, 0, 170, 62 STYLE DS_SHELLFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION CAPTION "I'm so awesome" CLASS "MyAwesomeDialog" FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN ICON IDI_AWESOME,IDC_STAT...

2026-01-21 15:00原文链接
未翻译