Friday, April 21, 2006

Continuing the development of my little utility

Previously I posted an article about the development of a little utility for controlling the fan on my Toshiba Tecra M4. The last thing I wrote was that I had tested the APIs for retrieving the current cooling method. Next up I had to find a way to set the cooling method.

The function SetCoolingMethod seemed to be a good starting point, and since I recently had some success using a pointer to a pointer to an integer (which in c# is declared as ref IntPtr paramname), I tried this with the SetCoolingMethod function as well. I wrote the interfaces in my little test project, and fired it up from within the debugger. This time the program crashed with a null pointer exception. I tried several different ways of declaring the parameter, using integers, pointers to integers and the pointer to a pointer to an integer.

I did some research to see how the Toshiba Power Management software were using the function, and saw that it seemed to send two parameters to the function. I tried to pass two pointer-to-a-pointer-to-an-int parameters to the function, and this time it worked – the fan suddenly stopped spinning like crazy when I fed it with the value 2 as the first parameter!

I now had a way of both getting and setting the cooling method, and was all set to go to build a real program that utilized this knowledge.

Stay tuned for my next post.

No comments: