devblogs.microsoft.com/oldnewthing
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...
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...
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...
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...
Why not store the SAFEARRAY reference count as a hidden allocation next to the SAFEARRAY?
When I described how SafeArrayAddRef 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 SafeArrayCreate function. I’ve seen code that declared and filled out th...
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 SafeArrayAddRef . 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 SafeArrayDestroy , the array is gone. You can extend the lifetime of the memory with SafeArrayAddRef , but the data itself has v...
Why did I lose the data even though I called SafeArrayAddRef?
A customer had a method that received a SAFEARRAY , and they called SafeArrayAddRef 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 SafeArrayAddRef 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...
A digression on the design and implementation of SafeArrayAddRef and extending APIs in general
Last time, we learned about the difference between SafeArrayAccessData and SafeArrayAddRef . I noted that SafeArrayAddRef 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...
What’s the difference between SafeArrayAccessData and SafeArrayAddRef?
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 SafeArrayCreate 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 SafeArrayAccessData function tha...
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...
A simple helper function for attaching a progress handler to a Windows Runtime IAsyncActionWithProgress or IAsyncOperationWithProgress
The Windows Runtime has interfaces IAsyncAction and IAsyncOperation<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: IAsyncActionWithProgress<P> and IAsyncOperationWith...
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...