Showing tag results for Code

Mar 29, 2013
Post comments count0
Post likes count1

How do I convert a method name to a method index for the purpose of INTERFACEINFO?

Raymond Chen
Raymond Chen

The IMessage­Filter::Handle­Incoming­Call method describes the incoming call by means of an INTERFACE­INFO structure: typedef struct tagINTERFACEINFO { LPUNKNOWN pUnk; IID iid; WORD wMethod; } INTERFACEINFO, *LPINTERFACEINFO; The wMethod is a zero-based index of the method within the interface. For example, IUnknown...

Code
Mar 25, 2013
Post comments count0
Post likes count1

Using accessibility to monitor windows as they come and go

Raymond Chen
Raymond Chen

Today's Little Program monitors windows as they come and go. When people contemplate doing this, they come up with ideas like installing a WH_CBT hook or a WH_SHELL hook, but one of the major problems with those types of hooks is that they are injected hooks. Injection is bad for a number of reasons. It forces the hook to be in a DLL so it can be...

Code
Mar 22, 2013
Post comments count0
Post likes count2

When will GetMessage return -1?

Raymond Chen
Raymond Chen

A source of great consternation is the mysterious return value from : If there is an error, the return value is −1. For example, the function fails if is an invalid window handle or is an invalid pointer. That paragraph has caused all sorts of havoc, because it throws into disarray the standard message pump: But don't worry, the standard m...

Code
Mar 21, 2013
Post comments count0
Post likes count1

Does this operation work when file system redirection is disabled? The default answer is NO

Raymond Chen
Raymond Chen

A customer reported that when their program called to get the icon for a folder, the call failed. "It works on some machines but not others. We don't know what the difference is between the working and non-working machines." They included the offending function from their program, but everything in the function looked good. The problem was somethi...

Code
Mar 15, 2013
Post comments count0
Post likes count1

Playing with the Windows Animation Manager: Moving lots of stuff around

Raymond Chen
Raymond Chen

We saw last time a sample program that moved a circle around. Today I'll try to build the classic demo of animating a lot of objects in a list. This isn't the prettiest code, but I wanted to make as few changes as possible. Start with the Timer-Driven Animation, and make these changes to the Main­Window.h header file. struct Item { I...

Code
Mar 14, 2013
Post comments count0
Post likes count1

Playing with the Windows Animation Manager: Fixing a sample

Raymond Chen
Raymond Chen

Windows 7 provides a component known as the Windows Animation Manager, known to some people by its acronym WAM, pronounced "wham". There are some nice sample programs for WAM on MSDN, but for some reason, the authors of the samples decided to animate the three color components of a resultant color. Because apparently the authors of those ...

Code
Mar 13, 2013
Post comments count0
Post likes count1

Closing holes in the update notification pattern

Raymond Chen
Raymond Chen

Suppose you have a function that is registered to be called the next time something gets updated, and suppose that the notification is a one-shot notification and needs to be re-armed each time you want to wait for the next notification. (For example, the Reg­Notify­Change­Key­Value function behaves this way.) Consider the followi...

Code
Mar 11, 2013
Post comments count0
Post likes count1

How can I see what files and shares are being accessed remotely, and the general usage pattern for the NetXxx functions

Raymond Chen
Raymond Chen

Today's Little Program is a command line version of the Shared Folders MMC snap-in. Why? Because it illustrates the usage pattern for the Net­Xxx family of functions. (It's also a clone of the networking portion of the openfiles tool.) The Net­Xxx family of functions generally work like this: You pass in some parameters that describe ...

Code
Mar 7, 2013
Post comments count0
Post likes count1

What are the conventions for managing standard handles?

Raymond Chen
Raymond Chen

Consider this function: void ChangeConsoleColor(WORD wColor) { HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); if (h != INVALID_HANDLE_VALUE) { SetConsoleTextAttribute(h, wColor); CloseHandle(h); } } "When I call this function, it works the first time, but when I call it a second time, Get­Std­Handle returns a handle numerically ide...

Code