Tuesday, October 14, 2008

Dead and Alive

Few things that I can really count as strange happen to me.

I would have ignored the fact that my PSP inexplicably died on me, only to have it suddenly return to life, then intermittently work, and finally start working again. I would have relegated it to the perversity of the inanimate.

So it only served to raise the event to even higher levels of mystery when the same thing happened to someone else, at around the same time, and stranger still, to someone sharing my first name.

I'm just glad that my PSP is back and better (except for that piece of tape holding the LCD backlight flex cable to the connector)

Thursday, October 2, 2008

WiiMote in Action

As you know I got a WiiMote a few months a go for my birthday, but I haven't been using it lately. The lack of buttons makes it difficult to play Final Fantasy X, which is what I'm spending my gaming time on nowadays.

Well, here's a couple of videos of my WiiMote setup in action.

I hadn't setup the Wii "sensor" bar I DIY'd when I made these videos, so there's no point n' click action here yet.



TrackMania Sunrise



Portal

Wednesday, October 1, 2008

Doh!

Fans of Point-and-click games would do well to be aware that Broken Sword 2.5 is out! And it's totally free!

I love point-and-click games (and their precursor, the click-and-type games?) Never mind that I probably haven't solved one yet without the help of a walkthrough.

In fact, I can't wait to have kids, have them grow up a bit and so I can install a PC-based media center with a 42-inch LCD, (or will OLED be the display of choice in the far future?) WiiMotes and ScummVM installed, and introduce them to Those Games Their Father Played Back In Those Days, encouraging them to play them as they will be the only games installed on the PC, and declaring lazy Saturday afternoons as Family Point-and-Click Time.

Oh they will hate me.

When I heard Broken Sword 2.5 even existed, my first thought was - is it ScummVM compatible? Does it use the same engine even?

My second thought was - if it did, maybe I could play it on my...

PSP...

Doh!

(The happy music playing in my head slowed to a stop like an audio tape stuck in the mechanism. Audio tapes? How archaic...)

Returning Strings from WinAPI in VB.Net

I know this has been covered a lot in other places, but the things is, all their examples have failed to work for me. Here I offer another method, one that worked for me.

Declare Auto Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer

This is the usual declaration of the API function GetWindowText. As we know lpString should be marshalled as a LPCSTR, but according to this article, VB.Net doesn't allow you to specify the marshaling attribute on parameters, and purportedly the above declaration works just fine.

When I tried this version of the API call, using GetWindowTextLength to determine the length of the string to be filled with spaces before passing to GetWindowText, I ended up with a bunch of non-ASCII characters. When I tried using the MarshalAs attribute, all I got was an empty string of the "correct" length.

After some exasperation I decided that since the API was expecting a pointer to a string, I might as well give one, or the closest to one, a byte array. The declaration was then:

Declare Auto Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpByteArray As Byte(), ByVal cch As Integer) As Integer

Then:

...
Dim Ret As Integer, sByte As Byte()
Ret = GetWindowTextLength(hwnd)
If Ret > 0 Then
ReDim sByte(Ret + 1)
lret = GetWindowText(hwnd, sByte, Ret + 1)
Return System.Text.Encoding.ASCII.GetString(sByte)
End if
...

Just as a sanity check (and before I found the Encoding.ASCII.GetString function), I stepped through the function to see what was being stored in sByte. They looked to be ASCII-flavored bytes (mmmm) so I looked for a function to convert them to a string, et voila!

I was actually expecting to be required to pass the first member of the byte array as a parameter to GetWindowText, but apparently .Net did the math and converted the byte array into a pointer of sorts.

I must admit I'm a bit new to .Net (two years of actual usage) and newer to managed and unmanaged code mixing, so I can't tell you that this is the right way to do it, but this method worked where others failed.

I'm on .NET 2003, in case you were wondering.