Tag Archives: windows

Setting the minimum Windows version supported (C++)

Recently, I was trying to use the Shell function SHGetFolderPath. Despite including the correct header file (shlobj.h), the compiler wasn’t recognizing it. My code looked like this:

CString strPath; HRESULT hResult = SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, strPath.GetBufferSetLength(MAX_PATH)); strPath.ReleaseBuffer();

What I did was lookup the definition of SHGFP_TYPE_CURRENT in shlobj.h, and found this:

#if (NTDDI_VERSION >= NTDDI_WIN2K) SHSTDAPI_(void) SHFlushSFCache(void); typedef enum { SHGFP_TYPE_CURRENT = 0, // current value for user, verify it exists SHGFP_TYPE_DEFAULT = 1, // default value, may not exist } SHGFP_TYPE; SHFOLDERAPI SHGetFolderPathA(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, __out_ecount(MAX_PATH) LPSTR pszPath); SHFOLDERAPI SHGetFolderPathW(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, __out_ecount(MAX_PATH) LPWSTR pszPath); //etc...

It’s that first line that got me. My DDI version wasn’t >= that of Win2k’s. The solution is to modify the stdafx.h file. Before, it read:

#ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0400 #endif

That 0x0400 defines Windows 95 as the minimum supported OS. I don’t really care about 9x support, so I changed it to read like this:

#ifndef _WIN32_WINNT //define Windows 2000 as minimum necessary OS #define _WIN32_WINNT 0x0500 #endif


Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

How to solve severe driver problems in Windows

A colleague at work recently got a second video card–a bottom of the barrel (or close to it) nVidia MX 4000 (PCI). He had an existing AGP nVidia Vanta. Well…the installation did not go well. It did something to Windows so that it consistently blue-screened during the driver load process (the progress bar moving in the startup splash screen).

Windows would start in safe mode, but removing the non-working drivers for the new card did not work. Removing both drivers did not work. Choosing last-known good configuration got us up and running in Windows (finally), but with only the bare VGA driver. Installing a driver from either CD or nVidia’s site ended in the strange error “Access Denied.”

Then I remembered what I had read in Windows Internals about the location of driver configuration information in the registry.  Driver info is stored with service configuration in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services.

First we removed all hints of nVidia apps and videos drivers using Add/Remove Programs. Then we went into regedit, into the above key and deleted the keys “nv”, “nv4”, and “nvsvc” (I think they were those, but looking on my own machine at home, they’re a bit different, so I’m half-guessing). I’m sure there are similar keys for ATI chips.

In the meantime, we had found an unused AGP version of the MX 4000 just lying around (no joke), and replaced the Vanta with this. We reinstalled the drivers and everything worked great.


Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

ClearType is like a new pair of glasses

Many have said it already, but let me just add my voice: ClearType technology is the most wonderful thing to hit Windows in a long time. I recently received a new computer at work (3.4Ghz hyperthreaded, 1 GB RAM, 80/200 GB disks–a screaming machine, at least compared to what I used to have). and during the setup process (3 versions of Visual Studio, Office, dozens of developer tools) I remembered that I needed to turn ClearType on.

Wow. It’s like the same difference when you’ve been needing glasses for a while and finally get them and realize that the world isn’t that blurry after all.*

It doubles the perceived resolution of LCDs.

(* only a little ironic that ClearType works by deliberately “blurring” edges through antialiasing.)


Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

Windows Live Search Toolbar — not quite there yet

I forced myself to uninstall the Google toolbar and exclusively try out the new Windows Live Toolbar. I think I’m going to uninstall it today. First of all, I like a lot of things about it:

  • Customizable buttons
  • Lots of great features
  • Search history with automatic drop down list that shows past/related searches
  • Desktop search works as well as always. I couldn’t live without it.

I also noticed that the search results for Windows Live were just about as good as Google’s. That is a great thing–we need more competition in this space to keep things going.

However, with all that good there are some pretty significant issues (at least for me).

  • It is sloooooooooooooooow. I mean, noticeably slow, painfully slow, distractingly slow. I want my search results nearly instantaneous. None of the pretty features matter if I have to wait 15 seconds for search results to show up when your competitor can come up with the same result in 2 seconds. Is it the web-site or the toolbar–I’m not sure yet.
  • Lack of Instant Answers. One of the things I love about MSN search is the ability to track packages, get weather, and lookup addresses. Why wasn’t this built into Windows Live from the beginning? I know they’ll be adding them, but still…
  • Sometimes, the toolbar refreshes or does something that erases what I’ve already typed. I think this is an issue when it first starts up–if I’m too quick to begin searching. Not a huge issue…

I’ll be getting a new computer at work in a few weeks. I’ll try again after that. Hopefully Microsoft will have made some improvements. I’ve submitted my list of issues to their feedback page, and hopefully they will make this product better.


Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

Windows Media Player 11 continued…

Some things I really like about the new media player:

  • It is a LOT faster. I have at least 15,000 songs I’ve ripped from my large CD collection. WMP 10 took far too long enumerating albums and songs.
  • The instant search may become my primary way of finding specific music to listen to.
  • I like the tile view — it makes the experience of picking music to play sort of like browsing a physical array of CDs. I have so much music that I often don’t know what I want to listen to–browsing is essential.
  • Very intuitive–I figured out how to navigate among the new views very easily.
  • The shuffle/repeat options is much more prominent on the play-control bar. I switch shuffle on and off constantly.

Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

Windows Media Player 11

The best media player just got better.

At work, I just downloaded the new version of Windows Media Player 11 in beta. From what little I’ve used it, it’s a HUGE improvement.

One potential thing I slightly miss is that I can’t view albums in the left-hand “browser” and the tracks in the right-hand “content” view. This allowed me to easily move tracks to differently-named albums during editing. But maybe there is a way to do it, or a completely different technique altogether that works just as well.

Also, the readme notes that there are potential problems with IE7 Beta 2, which I have at home. I’ll give it a try anyway and blog my results.

 


Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

What’s Wrong with this code? – 2 – Answer

In the last post, I showed some code that had a very simple problem.

The problem is that when you call HIWORD, it converts the 16 bits into an unsigned short, which then gets passed as an int padded with zeros–not sign extended (it’s not signed). It will NEVER be less than zero. The solution is to cast it to a signed short before calling the function or change the function parameters to be signed short instead of int.

 


Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

What’s Wrong with this code? – 2

What’s wrong with this code?

UINT a;
.
.
.
DoSomething(HIWORD(a));
void DoSomething(int x)
{
 if (x < 0)
 {
  //do something
 }
 
}

I recently ran into this in some code I was working on.


Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

Macros are evil

I’m innocently developing a device context class for my LFC framework and I want a method called SelectPen. All of a sudden I’m getting very weird linker errors about how SelectPen is not defined.

It turns out that SelectPen is a macro defined in windowsx.h as an alias for SelectObject.

#define SelectPen(hdc, hpen) ((HPEN)SelectObject((hdc), (HGDIOBJ)(HPEN)(hpen))) Very annoying.Very annoying.Very annoying.


Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

Editing Tracks in Windows Media Player

I recently embarked on a complete overhaul of my digital music library–including re-ripping all of my hundreds of CDs into WMA at 192 Kbps. It took a few weeks to get through  that, and now I’m going through each album “normalizing” it–fixing up names, album artists, composers, etc. It’s quite an effort and very tedious at times.

I just discovered yesterday that the keyboard is your friend in Windows Media Player. Using the mouse, you have to higlight a track, and then click again to enter the field (but be careful not to double-click, or it will start playing that track instead).

With the keyboard, you highlight a track, hit F2 to edit the first field (track number in my case). Don’t hit enter when you’re done editing a field, but use the tab/shift-tab keys to move between fields and the up/down arrow keys to move between tracks. This is saving a ton of time.

So why didn’t I realize this before? Part of me wants to say it’s my fault: I’m very computer-saavy and use the keyboard whenever I can and I ought to have tried something. However, another part of me is thinking that the interface does not indicate that the keyboard is a viable option here.


Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order: