Aug 24 2010

Get a Helpful Error Message from WinErrors.h in C#

Published by Matt

It’s been a while since I’ve posted something like this, but this is one of those things that did not show up under the search terms I thought to be appropriate. Hopefully this post will get sorted to the top of the search terms I was using.

The problem is that when you call into Win32 APIs from managed C# code, they often return a simple integer to inform you of the status of your invocation. Zero means success, and everything greater than zero corresponds to one of the many many WinErrors.h error codes. Of course, you could hard-code these helpful messages into your code, but this is bad for various reasons. Thanksfully, .NET provides you with the Marshal.GetExceptionFromHR() method to dynamically query any helpful error message you may need!

The pluralsight blog shows how to wrap this up into a nice set of functions:


static string getWin32ErrorMessage(int errorCode) {
int hr = HRESULT_FROM_WIN32(errorCode);
Exception x = Marshal.GetExceptionForHR(hr);
return x.Message;
}
static int HRESULT_FROM_WIN32(int errorCode) {
if (errorCode <= 0) return errorCode;
return (int)((0x0000FFFFU &
((uint)errorCode)) | (7U << 16) |
0x80000000U);
}

No responses yet

Jul 12 2010

San Francisco Triathlon at Treasure Island

Published by Matt

I completed my first ever triathlon this past weekend and it was incredible! I set a goal of finishing under 90 minutes, and came in at 82:08! The event started with a 500m swim in the San Francisco bay. I wore a wetsuit, but it was still very cold. The wetsuit was sleeveless, which did not help matters. When I came out of the water I was very numb and disoriented. I literally felt like I was about to pass out, and I have never really experienced that before.

I ran towards the bike rack and slipped out of my wetsuit, into my socks, cycling shoes, and helmet. I was riding away 3 minutes later. The cycling section went pretty well, the only difficult part was riding against some strong winds. Some of the other guys in the race sure did fly past me though. I even saw one racer with a flat tire - I’m sure glad that didn’t happen to me!

Transitioning into the run was much easier. I slipped off my cycling shoes and put on my running shoes at a hat. I made it out of there in 61 seconds! I started off with a rather slow pace, but picked it up at the end to bring it home at 1:22:08.

My official times were .5k Swim 12:57, T1 3:07, 20k Bike 38:40, T2 1:01, 5k Run 26:23. Total = 1:22:08. Age group rank = 5/11.

The main training I had been doing since the beginning of the year was geared towards fat loss, but I really enjoyed the race and will begin training for the Olympic distance triathlon next year.

Be sure to check out the pictures on the website!

No responses yet

Jul 03 2010

Half Dome, Yosemite National Park

Published by Matt

Here are some videos cataloging our adventure.

One response so far

Apr 26 2010

Backpacking at Henry Coe

Published by Matt

This past weekend I went on my first backpacking trip in the hilly terrain of Henry Coe State Park. It was incredible, and really gave me some perspective on what “real” camping is like. We were originally registered to participate in the Backcountry weekend, which is a section of the park that is only opened one weekend per year. However, some rain during the week made the road inaccessible, so that was cancelled. We still had a blast in the front section of Henry Coe, though!

We left work a bit early and arrived at the Hunting Hollow entrance around 5pm. After some preparations, we began the 3 mile, 1800-foot elevation gain hike to Wilson’s Peak – our first campsite. We didn’t fully realize it at the time, but this was by far the hardest portion of trail on the entire trip. Luckily we made it there by 7:30pm, or just as the sun was setting. We got our tents up and enjoyed a hearty dinner. I slept pretty well until about 4am, when it started getting really cold. I finally just got up at 6am to wait for the sun. I sat on a rock in the middle of the hillside on top of the peak and waited for some much needed solar radiation. It was an amazing time of solitude.

Finally, the sun came out and we made some oatmeal and protein bars for breakfast. My friend had a pretty sweet miniature stove made out of soda cans, and it did an excellent job of heating whatever we needed.

On Saturday, we made our way over the Kelly Lake. Luckily the elevation changes were only +/- 400 feet or so. The view from hiking along the mountains was really awesome. We were above the distant clouds at several points. There were also several different types of flowers growing on the hillside. It was really cool to witness such beauty with really no one else around. When we got to Kelly Lake, however, there were about 20 other people with tents set up. We had a nice lunch of apples and peanut butter, along with some various other goodies that we had packed, then set up camp. We got a prime location next to the water, complete with a large log that we relaxed on. After we dropped our gear, we hiked a few miles further, around Coit Lake. We saw several other hikers, and even a snake on the trail!

The next day we hiked the entire distance back to the parking lot, but it was much easier because it was downhill most of the way. It was an awesome trip, and taught me that backpacking is truly something that I would like to do more of in the future. Oh, and I finally have a new Facebook profile picture.

No responses yet

Jan 02 2010

We’re going to Jamaica!

Published by Matt

Thanks the crazy holiday travels and our willingness to take a 12 hour delay, AirTran gave Ashley and I each two free round-trip tickets to wherever they fly, which includes Jamaica! Not sure when, but sometime in 2010.

One response so far

Jan 02 2010

Milwaukee

Published by Matt

We had an overnight layover in Milwaukee on our way home, so we took advantage of the local art museum.

No responses yet

Jan 02 2010

Christmas 2009

Published by Matt

We had an awesome Christmas break over the past two weeks.  There are plenty of stories, but it’s really late and I just spent a good deal of time getting all the pictures up.  I’ll link in the videos here, and hope Ashley adds some prose to describe our vacation!

No responses yet

Nov 04 2009

Cycling and Studying

Published by Matt

I’ve been incredibly busy writing code over the past two months in order to hit our big Code Complete deadline last week.  Now that we’ve hit it, I’ve got a more reasonable schedule, so I figured I should post up a quick update.

I’m loving my bicycle.  I have gotten in the habit of riding to/from work several days (if not all days) a week.  The weather is getting cooler, but most days are >55, so it makes a brisk ride strenous enough to keep me warm.  I don’t know that I’ve seen a huge health benefit yet, but I’ve only been diligent about riding it the past week or so.  I really need to keep it up to keep in shape for our big Half Dome hike next summer.

One reason I have been biking more is that I started taking a class at Stanford, through their Center for Professional Development.  I have embarked on a “graduate certificate” program that will grant me a certificate in databases after taking 4 classes.  One way to describe this certificate is like “1/5 of a Master’s”.  The four classes count towards a Master’s degree, so after I complete them this time next year, I can re-evaluate going down that path depending on everything else going on in my life.  I really enjoy doing academia and industry computer science simultaneously - it’s a nice balance of “pure science” in academia, and “engineering” in industry.  Anyway, the bike is helpful around campus because Stanford is so huge, it would take forever to walk around.  I am mainly taking the class online, but I go to campus to study and work on programming projects due to the increased intra-network connectivity.  It’s challenging, but I am really enjoying it.

Oh yeah, I was Travis Bickle from The Taxi Driver (with Rober Deniro) for Halloween, so my hair is currently cut into a mohawk. :)

No responses yet

Sep 23 2009

Bought a Bicycle

Published by Matt

As you might have read a while ago, I thought I was going to train for a marathon. That went pretty well, until I started getting horrible shin splints. I read a lot of advice about getting new shoes, but this is not the first time I have suffered shin splints, so I kind of gave up trying to cure them. 

Instead, I decided to embark on a no-impact sport, cycling! I found a nice used Giant OCR3 road bike on Craigslist and am excited to get into the sport. I’ve only had it for a few days and I’ve already ridden several times. I really enjoy it, and it is much less painful than running! I am trying to work up to commuting to and from my office a few days a week… about 11 miles each way. If I can do that, I’m sure I’ll see great results both on my body and on my wallet from the gas savings.

The main thing Ashley and I are trying to get ready for now is doing the Half Dome hike in Yosemite next summer.  This hike is known as the most strenous charted day-hike in the nation!  It is about 8 miles of trail that climbs almost 5000 feet in elevation… one way!

2 responses so far

Jul 25 2009

Yosemite National Park

Published by Matt

One of my college friends decided to take a little summer vacation and visit us in California! He and his girlfriend arrived on Thursday evening and left Monday evening, for a long weekend. We took it pretty easy Thursday night, with a nice dinner (thanks Ashley!) and just chatted for a while. I took off on Friday, and we embarked on a leisurely 4 hour drive to a campsite at Yosemite Lakes, which is a private campground about 5 miles west of the Highway 120 entrance to Yosemite National Park. The campgrounds were pretty crowded, but luckily ReserveAmerica had a deal where we could stay in the “members only” spots. I can’t imagine the other spots, they must have been tiny!

We were able to setup camp rather quickly, and then walked down to swim and lounge around in the stream at the campgrounds. We cooked up some filet mignon and ribeyes with loaded baked potatoes for dinner and had a great time hanging out by the campfire. We were lucky to have a campfire at all, it took us quite some time (and money) to find someone who would sell us firewood!

The next morning, I used my fancy 3-burner camp stove to cook up some bacon and scrambled eggs to fuel our big day. Driving through Yosemite was incredible! The scenery there is unlike any I have ever seen, and the park is so big - there is so much to do! There are 5-6 campgrounds within the park and even a 4-star hotel. It’s really commercialized, but it does not detract from the beauty of the surroundings. We also found out that the weekend we were there was free entry to the park! It was a nice surprise when we got there, but it also meant that it was incredibly crowded. It took us nearly 15 minutes to find a parking spot so that we could get out and begin our hike. We set out on the John Muir Trail, which happens to extend for over 212 miles! We only made it about 2 miles up the mountain, and it was one of the most strenous hikes we have ever been on! It was pretty much 2 miles of huge stairs up a steep cliffside. We grew very tired and had to take several breaks, but the views were well worth it.

When we got up to the top of the falls, my friend and I decided to go for a swim in Emerald Pool. The snowmelt was pretty cold, but it was a hot enough day that it felt great! Yosemite valley was carved by glacier movement, so I have swam around in a glacial pool at the top of a waterfall! Refreshed by the cool waters, we started our trek down the mountain. It was MUCH easier going downhill, and we were able to get down in about 45 minutes. We walked around a little more in the park, and then started the 4 hour drive home (it took 45 minutes just to get out of the park and on the road)!

 

On Sunday, my friends borrowed our car to do the Alcatraz tour, and then Ashley and I took CalTrain to meet up with them later that afternoon.  We had lunch on Pier 39, walked around there, to Ghiradelli Square, and Lombard Street.  Then, we got back in the car to drive across the Golden Gate Bridge and take some pics from the other side.  We also explored a little around a beach near the bridge and found a great place for a picnic next time we visit!

All in all, it was an outstanding weekend and it was really cool to catch up with old friends around the city!

No responses yet

Next »