CVS, Cygwin, and error code 0xc0000022

In short, if your project crashes at library load time after a round trip through CVS, you might want check your NTFS execute permissions on the DLLs that the project depends on. Also, if your application mysteriously blows up with error code 0xc0000022, you’d do well to make sure that:

  • all DLLs that your program depends on are valid and locateable.
  • Check all its DLL dependencies for permission problems. As in, permissions on the DLLs that your program depends on should be set to be executable for your user.

In one of my Windows projects, I wrote some code that relied a number of DLLs. To save myself sometime, I compiled these DLLs and checked in the compiled binaries into the CVS repository.

On another machine, I checked out the project via the cvs utility, under Cygwin, to work on it. As a Unix-y kind of guy, I prefer the tools that I’m used to. Everything compiled fine, but at runtime the application crashes before it gets to main(). ” The application failed to initialize properly (0xc0000022) … ” After some dependency tracking to find out if I lost a DLL somewhere, first via Dependency Walker, then via gflags, nothing unusual turned up.

Then I noticed that replacing the checked out libraries with fresh copies of the same DLLs fixed the issue. The problem was that upon checking md5 sum against the old and new libraries, they were exactly the same. There was no damage or corruption.

Turns out, of course, that Execute permissions were off on all those DLLs that I checked out. Apparently Cygwin’s cvs does not set execute bits on DLL files, and since you’re usually using ntsec settings with Cygwin, this causes a security/permissions problem on the Windows side. As a result, the project compiles just fine, fails at runtime, and gives you a completely obtuse error message that means very little unless you’ve done this sort of thing before. Cygwin and cvs’s role in this was also not a very obvious thing to deduce.

Two hours of my life, right there.

Extracting Address Book information

If you’ve left information in the Address Book in OS X, any other program on the machine can use Cocoa APIs to extract information automatically.

#import <Foundation/Foundation.h>
#import <AddressBook/AddressBook.h>
#import <AppKit/NSWorkspace.h>

void sayHello(void)
{
   ABPerson *currUser = [[ABAddressBook sharedAddressBook] me];
   NSString *firstName = [currUser valueForProperty:kABFirstNameProperty];
   NSString *lastName = [currUser valueForProperty:kABLastNameProperty];
   [[NSWorkspace sharedWorkspace] 
                           openURL:[NSURL URLWithString:
                                                     [NSString stringWithFormat:
                                                     @"http://www.google.com/search?hl=en&q=%@+%@", 
                                                          firstName,
                                                          lastName]]];
}

int main (int argc, const char * argv[])
{
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   sayHello();
   [pool release];
   return 0;
} 

This will take the name labelled as the currently logged in user and hit up Google, placing the first and last name in the search box and run a search with it. Other pieces of information are also accessible via the AddressBook API.

As you can well see, this can be used for many purposes: nifty automagical hacks in the OS’s built-in suite of personal information and communcation apps, for example. But I can think of less beneficial uses for this API. You should be able to trust the programs you run.

Hacking HoMM IV saved game


For the five of you who have a copy of Heroes of Might and Magic IV, Mac edition (and still play it on occasion), here’s something you might not know.

The .h4s saved game files are gzipped data files, with what appears to be a straight-up serialized form of in-memory data structures representing your heroes, their stats, creatures, etc. The implication is, then, this guide to in-memory editing on the PC edition also applies (mostly) to the saved games on the Mac.

There is a bug in Campaign mode, where certain skills are never offered to your heroes even when they are able to receive them natively. For example, if you played on the Might campaign, even if you hired a Mage from the external tavern (say, on Map 2), you will never be offered Life Magic or Death Magic for this mage at level-up time, even though these skills are within the allowable set for Mages. Instead, your Mage will actually get offered Nature Magic, Tactics, etc, which aren’t normally in the set of offerable skills. A Cleric would never be offered Order Magic, etc. It appears that campaign skill restrictions on your primary hero are also inadvertently applied to secondary carry-over heroes.

Since 3DO is dead, I don’t expect this to ever be patched. To workaround this bug, however, you can edit the saved games yourself.

You’ll first need to gunzip the saved game. The incantation is gunzip -S .h4s foo.h4s.

With a hex editor, find your hero’s name. There may be several instances of it, but the correct one has your hero’s description following. If you’ve done this correctly, you should see a block of hexes consisting of bytes such as FF FF FF FF, 00 00 00 00, etc. Each 4-byte signed integer represent one of your hero’s skills. They are, in order:

tactics, combat, scouting, nobility,
life, order, death, chaos,
nature, offense, defense, leadership,
melee, archery, resistance, pathfinding,
ships, stealth, estate, mining,
diplomacy, heal, spirituality, resurrection,
enchantment, wizardry, charm, occult,
daemonology, necromancy, conjuration, pyromancy,
sorcery, herbalism, meditation, summoning

The skills are represented by signed, 4-byte integers. On big-endian PowerPC machines, this would be:

FF FF FF FF == -1 == no skill
00 00 00 00 == 0 == basic
00 00 00 01 == 1 == advanced
00 00 00 02 == 2 == expert
00 00 00 03 == 3 == master
00 00 00 04 == 4 == grandmaster

Hypothetically, an Intel version would be little-endian. Since there isn’t HoMM IV Mac edition for Intel processors (not Universal binary, and not likely ever to be), however, the issue is kind of moot.

Change the various skill levels as you wish. I use this to workaround the aforementioned skills bug, so I decrement one skill and then take up the one I should have gotten, but you can also, of course, cheat like mad.

There are other values around that I haven’t really played with, but all the values are in here, including your amount of gold, resources, etc. One easy way to find them is to convert their values (well, if they’re reasonably unique values) to hex and search the file.

Once you’re done, don’t forget to use gzip to zip the file back up into a .h4s file and plop it back into your games directory. Fire up HoMM IV, and you’re ready to go.

Update
check out the comment section for additional notes on other data values