Bjarne Rene-Wrapping Spirit.OCX COM object
From: Bjarne Rene 
Subject: Programming Mindstorms
Date: Friday, September 11, 1998 4:17 PM

Hi Everyone!

I've been digging around in the spirit control com object, and I have
managed to make a little program that wraps the com-object (I found hints on
how to do that in a previous post on this group. I can't remember who sent
it though...), and enables you to call any function from the spirit control
via a C++ class. Before we go on, I suppose I should say that I am using MS
Dev version 5 (sp3), and that I am planning on making an MFC based app...

Oh, and one more thing. The 0bligatory disclaimer: Most of the stuff in here
I've just figured out through experimentation. I haven't managed to blow up
my RCX or my computer yet, but I won't guarantee that you won't. If you
follow these instructions, you do so entirely at your own risk.

The process is fairly simple, and goes as follows:

1) create a new project using "MFC AppWizard (exe)", name your project and
press "OK"

2) I'm making my app dialog based (we want lots of buttons to control our
creations!!), so I'll choose dialog based in this window. Once that is done,
hit next.

3) In this step, you can choose pretty much any options you like, but make
sure that you've got ActiveX controls ticked. Then hit next.

4) Now run through until the end of the AppWizard.

5) This is where the fun starts: Go to the 'Project' menu and select 'Add to
project'. From there, select 'Components and controls'. In the dialog that
pops up, open Registered ActiveX Controls, and scroll your way across until
you come across the 'Spirit Control'. It will have a nice little lego icon
on it. Click on that, and then click on 'Insert'. Hit 'OK', 'OK', 'Close'.
You will now have a class called CSpirit. (Would you look at all those
member functions :)

6) Now we need to make the class useable: Go find your dialog in the
ResourceView. If you look at the potential controls to insert, you'll see a
nice little Lego icon at the end of the normal controls. choose one of them,
and drop it on your dialog. There will now be a red box in your dialog that
says (funnily enough) LEGO.

7) Now go into ClassWizard. Go to the member variable pane, and click on the
control ID for the spirit control. Now click 'Add Variable'. Name your
variable, then make sure the category field says 'Control', and the Variable
type says whatever you named your spirit class (probably CSpirit). Hit 'ok'.

Congratulations! You now have a little dialog based MFC program that lets
you use the CSpirit class to communicate with your RCX. A few more tips

Before you can get anything useful out of your RCX, you need to set up the
communications. That means calling a few functions:
SetComPortNo(long no); // set this to whatever com port you've got your
IR-tower hooked up to.
SetLinkType(long type); // use 0 for IR-link. The other options are 1-Cable,
and 2-Radio
SetPBrick(long type); // use 1 for RCX - the other option is 0-Spirit
Now that that is done, you can call InitComm(); If you've done everything
right, you should be able to call any of the functions in the class.
Oh, and when you're done, you should be polite and call CloseComm();

Phew - That's about it for now. For a description on some of the functions,
have a look at

I hope that helps   B)

Russell Nelson's Mindstorms Internals Page
Home Page
Personal Investing
Information Page
Kidsware Page