Fun with Motorbee - Part 1-Written on 2009-08-03 19:03:21 by BONES |
|---|
This last weekend my brother was visiting, and we decided to have a look at programming for the motor-bee control adapter. type TInitMotorBee = function():boolean ;stdcall; As you can see, the InitMotorBee function takes no arguments and returns a Boolean if successfull. To Initialize, we simply create a variable of the type TInitMotorBee and pass the structure of the function to it with GetProcAddress. We can then instantiate a variable and do all sorts of cool error checking.(I have noticed that IE sometimes breakes the formatting of the highlighted code, if you have this problem, please click the "View plain" link at the top of the section.)
var
procedure InitBee;
...
procedure InitBee;
var
Handle: THandle;
InitMotorBee: TInitMotorBee;
i:Boolean;
begin
// -- Load the DLL -- //
Handle := LoadLibrary('mtb.DLL');
if Handle <> 0 then begin
// -- Get the address of the InitMotorBee function from the DLL -- //
@InitMotorBee := GetProcAddress(Handle, 'InitMotoBee');
if @InitMotorBee <> nil then begin
Form1.Memo1.Lines.Add('Found Proc address for InitMotorBee OK');
{
InitMotorBee passes back a boolean variable to indicate if
Init was successfull of failed Note. For some reason, the DLL
returns 0 if true and *something else* if false (An error number?)
so we check for NOT TRUE
}
i := InitMotorBee();
If not i then
Form1.Memo1.Lines.Add('Initialisation was successfull ')
else
Form1.Memo1.Lines.Add('Initialisation was not successfull ');
end else
Form1.Memo1.Lines.Add('Could not find proc address FOR InitMotorBee');
end else
Form1.Memo1.Lines.Add('Could not load Mtb.DLL');
end;
Part 2 - Get yer motors runin' !!
|