Recent

Author Topic: Error:Automation Object Aplication  (Read 19862 times)

acapa

  • New Member
  • *
  • Posts: 10
Error:Automation Object Aplication
« on: October 10, 2012, 03:55:23 pm »
Hello

I´m my porting   to Lazarus (from Delphi )  software for astronomical telescopes mount control.
Its  is a standaloné windows GUI application   with  a embedded automation object compliant with ASCOM (most extended  windows com based architecture for astronomical device control and interoperation,not phone manufacturer).
http://www.ascom-standards.org/index.htm
 
I have ported graphical interface and logic for standalone operation with ease.It works fine now.
http://www.picgoto.com/
I'm using Lazarus1.0 ,2012-10-05 , FPC 2.6.0 SVN 38415 ,i386-win32-win32/64 under Windows XP sp3.

Automation objecs for it are many years working fine compiled for dellphi Delphi  and

To check for automation object under FPC I used delphi wizard to generate a type library  for  the simplest ascom device (motorized focuser).Compile it under Delphi and checked  it was accesible for  some ASCOM compliant software.

I convert it to Lazarus by  using IDE tools ,I Corrected some warnings and minor tips and got compiled aplication without error messages.
But when invoke my test application built under Lazarusaplication popups but after some time  got  this error
"Failed to load lazydriver.focuser System.RunTime.Interop.Services.COMexception(0x80080005)

Lazydriver.focuser is registered comobjet name.
I have checked windows registry for required interface , typelib ,objects and all is there in its place for this object

I really don know what Im doing wrong or it related to my FPC/ Lazarus  working version
I read  a post at this forum about  some comserv bugs correction for FPC 2.6.0.
I dont want to bother you posting my code.Only wanto to know if FPC is the actual state readyfor automation objects.
Thanks in advance
Angel Caparrós

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Error:Automation Object Aplication
« Reply #1 on: October 10, 2012, 04:27:59 pm »
"Failed to load lazydriver.focuser System.RunTime.Interop.Services.COMexception(0x80080005)

That looks like  a .NET exception:

http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.aspx

I've seen that before when .NET code traps an exception raised by a COM server.


With FPC 2.6.0, Automation on Windows works quite well as long as you're aware of the differences from Delphi. Notably you have to make sure you pass in WideString for string params. Delphi always converted AnsiStrings for you automatically, but his won't work with FPC. However, that doesn't sound like the problem you're having.

Thanks.

-Phil

acapa

  • New Member
  • *
  • Posts: 10
Re: Error:Automation Object Aplication
« Reply #2 on: October 10, 2012, 06:18:26 pm »
Ok Phil. Sorry , think  will have to bother a bit  with my sources :(
I not aware of these diferences.I have very little experience COM as I read once it works very close as  voodo does.
There are no string parameters  in any procedure or function excepting "createremote" method generated by delphi's wizard .at TBL unit
 
Code: [Select]
unit Lazfocus_TLB;

// ************************************************************************ //
// WARNING                                                                   
// -------                                                                   
// The types declared in this file were generated from data read from a       
// Type Library. If this type library is explicitly or indirectly (via       
// another type library referring to this type library) re-imported, or the   
// 'Refresh' command of the Type Library Editor activated while editing the   
// Type Library, the contents of this file will be regenerated and all       
// manual modifications will be lost.                                         
// ************************************************************************ //

// PASTLWTR : $Revision:   1.130.1.0.1.0.1.6  $
// File generated on 08/10/2012 15:32:57 from Type Library described below.

// ************************************************************************  //
// Type Lib: C:\Archivos de programa\Borland\Delphi6\Projects\lazyfocus\lazyfocusp.tlb (1)
// LIBID: {45589AD9-8197-4925-866B-E8F510842871}
// LCID: 0
// Helpfile:
// DepndLst:
//   (1) v2.0 stdole, (C:\WINDOWS\system32\stdole2.tlb)
//   (2) v4.0 StdVCL, (C:\WINDOWS\system32\stdvcl40.dll)
// ************************************************************************ //
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}
{$VARPROPSETTER ON}
interface

uses Windows, ActiveX, Classes, Graphics,  Variants;
 

// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:       
//   Type Libraries     : LIBID_xxxx                                     
//   CoClasses          : CLASS_xxxx                                     
//   DISPInterfaces     : DIID_xxxx                                       
//   Non-DISP interfaces: IID_xxxx                                       
// *********************************************************************//
const
  // TypeLibrary Major and minor versions
  LazfocusMajorVersion = 1;
  LazfocusMinorVersion = 0;

  LIBID_Lazfocus: TGUID = '{45589AD9-8197-4925-866B-E8F510842871}';

  IID_IFocuser: TGUID = '{97FBDD9A-A1B6-4663-9CEA-8DD237BA528D}';
  CLASS_Focuser: TGUID = '{70CB798E-182E-489A-8F05-3A9F2E14C5E9}';
type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary                   
// *********************************************************************//
  IFocuser = interface;
  IFocuserDisp = dispinterface;

// *********************************************************************//
// Declaration of CoClasses defined in Type Library                       
// (NOTE: Here we map each CoClass to its Default Interface)             
// *********************************************************************//
  Focuser = IFocuser;


// *********************************************************************//
// Interface: IFocuser
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {97FBDD9A-A1B6-4663-9CEA-8DD237BA528D}
// *********************************************************************//
  IFocuser = interface(IDispatch)
    ['{97FBDD9A-A1B6-4663-9CEA-8DD237BA528D}']
    procedure SetupDialog; safecall;
    function Get_Absolute: WordBool; safecall;
    function Get_MaxStep: Integer; safecall;
    procedure Set_MaxStep(Value: Integer); safecall;
    function Get_TempCompAvailable: WordBool; safecall;
    property Absolute: WordBool read Get_Absolute;
    property MaxStep: Integer read Get_MaxStep write Set_MaxStep;
    property TempCompAvailable: WordBool read Get_TempCompAvailable;
  end;

// *********************************************************************//
// DispIntf:  IFocuserDisp
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {97FBDD9A-A1B6-4663-9CEA-8DD237BA528D}
// *********************************************************************//
  IFocuserDisp = dispinterface
    ['{97FBDD9A-A1B6-4663-9CEA-8DD237BA528D}']
    procedure SetupDialog; dispid 1;
    property Absolute: WordBool readonly dispid 6;
    property MaxStep: Integer dispid 7;
    property TempCompAvailable: WordBool readonly dispid 8;
  end;

// *********************************************************************//
// The Class CoFocuser provides a Create and CreateRemote method to         
// create instances of the default interface IFocuser exposed by             
// the CoClass Focuser. The functions are intended to be used by             
// clients wishing to automate the CoClass objects exposed by the         
// server of this typelibrary.                                           
// *********************************************************************//
  CoFocuser = class
    class function Create: IFocuser;
    class function CreateRemote(const MachineName: string): IFocuser;
  end;

implementation

uses ComObj;

class function CoFocuser.Create: IFocuser;
begin
  Result := CreateComObject(CLASS_Focuser) as IFocuser;
end;

class function CoFocuser.CreateRemote(const MachineName: string): IFocuser;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_Focuser) as IFocuser;
end;

end.

I really have only implemented minimal class focuser interface  and coinitialize just before create AutoObjectFactory.
procedure registerthyself is comment out(uses ASCOM framework helper libraries)  because  objects registration is done at install using innosetup resources.
Code: [Select]
unit Lazyi;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  ComObj, ActiveX, Lazfocus_TLB, Dialogs;//, StdVcl;

type
  TFocuser = class(TAutoObject, IFocuser)
  protected
    function Get_Absolute: wordbool; safecall;
    function Get_MaxStep: integer; safecall;
    function Get_TempCompAvailable: wordbool; safecall;
    procedure Set_MaxStep(Value: integer); safecall;
    procedure SetupDialog; safecall;
    { Protected declarations }
  end;

implementation

uses ComServ;

function TFocuser.Get_Absolute: wordbool;
begin
  Result := True;
end;

function TFocuser.Get_MaxStep: integer;
begin
  Result := 10000;
end;

function TFocuser.Get_TempCompAvailable: wordbool;
begin
  Result := False;
end;

procedure TFocuser.Set_MaxStep(Value: integer);
begin
end;

procedure TFocuser.SetupDialog;

begin
end;

{--------------------------------------------------------------}
procedure RegisterThySelf;
{--------------------------------------------------------------}
// Test id this interface is registered int he ASCOM registry area
// If not register it so the Choose can find it and also to store persistent data
var
  ProfileObject: variant;

begin
  ProfileObject := CreateOLEObject('ASCOM.Utilities.Profile');
  ProfileObject.DeviceType := 'Focuser';
  if (not ProfileObject.IsRegistered('lazydriver.focuser')) then
  begin
    //ShowMessage('Self-Registering: ASCOM ' );
    ProfileObject.Register('lazydriver.focuser',
      'Lazarus Generated ASCOM TestFocuser');

    // set persistent default values if any
  end;//else ShowMessage('it was yet registered)
end;

initialization

  // RegisterThySelf;
  CoInitializeex(nil, COINIT_APARTMENTTHREADED);
  TAutoObjectFactory.Create(ComServer, TFocuser, Class_Focuser,
    ciMultiInstance, tmApartment);
end.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Error:Automation Object Aplication
« Reply #3 on: October 10, 2012, 06:37:43 pm »


Try using late binding and see if you can use very simple code to create your COM object without error. Late binding doesn't use any type library that you have to supply. See example for Word Automation server here:

http://wiki.lazarus.freepascal.org/Office_Automation

Thanks.

-Phil

acapa

  • New Member
  • *
  • Posts: 10
Re: Error:Automation Object Aplication
« Reply #4 on: October 10, 2012, 09:59:07 pm »
By default ASCOM helper libraries use late binding,early binding has been discouraged for lates version.
I test both and both failed with my code.
I think i will have to wait for Ludob wiki page about this subject .
Thanks a lot Phil.
Ángel.

acapa

  • New Member
  • *
  • Posts: 10
Re: Error:Automation Object Aplication
« Reply #5 on: October 10, 2012, 11:06:19 pm »
I take a look at fpc 2.6.0   sources bundle with Lazarus1.
comobj.pp its not patched for late binding .
I apply the patch patched  it.
Now only have to rebuild FPC and retry.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Error:Automation Object Aplication
« Reply #6 on: October 10, 2012, 11:11:24 pm »
I take a look at fpc 2.6.0   sources bundle with Lazarus1.
comobj.pp its not patched for late binding .
I apply the patch patched  it.
Now only have to rebuild FPC and retry.

2.6.0 works fine here with late binding on all sorts of Automation servers.

Thanks.

-Phil

acapa

  • New Member
  • *
  • Posts: 10
Re: Error:Automation Object Aplication
« Reply #7 on: October 11, 2012, 12:35:31 pm »
I read http://lazarus.freepascal.org/index.php?topic=17455.0 and pointed patch  is not applied to 2.6.0 sources.I have patched and recompiled comobject.pp and  comserv.pp move .o and ppu files to its right place but it still doesn´work ,I get the same error messages.
 
Just before I wrote typelib (idispatch) automation object ,I  wrote a plain com dll using (iunknow) and worked when early binding invoked .But failed when using late binding.
As most ASCOM load late binding i cant use it.

I found too, that forms cant not be embbeded  dll in Lazarus.(Delphi does)well you can... but it wont show unless you call it in tricky way at client side.And you do that trick on third party software.
My application is  current unique form  I supposed  unlike dlls was  is possible to have both, automation objects and forms in the same application .
I will check windows registry again.
Thanks
Ángel.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Error:Automation Object Aplication
« Reply #8 on: October 11, 2012, 01:08:02 pm »
The patch you are referring to is only needed when writing a COM server in fpc. Here you try to attach to a COM server.

Some comments on your code:
-FPC has its own typelib importer. Use that one instead of porting Delphi's TLB imported units. Some FPC specifics are solved in the fpc typelib importer. It can be found in fpc 2.6.1 or 2.7.1. If you don't want to install these, attach the lazyfocusp.tlb and I'll convert it for you.
- CoInitializeex is not needed. That is already done in the initialization section of comobj.
- I never used TAutoObjectFactory.Create to create a connection. Calling Create on the generated CoClass should be enough.
- 0x80080005 CO_E_SERVER_EXEC_FAILURE is unfortunately a catch all error message that is used for a lot of the object's internal errors
- is SetupDialog creating a new window or does it need an ActiveX like container? See http://wiki.freepascal.org/LazActiveX

Can you show us the Code for the late binding you are using?  A common problem is using the wrong ClassName for the OLE object.

acapa

  • New Member
  • *
  • Posts: 10
Re: Error:Automation Object Aplication
« Reply #9 on: October 11, 2012, 04:40:36 pm »
-I did not import typelib  I build it with Delphi´s typelib  built editor to acomplish ASCOM standar.
-If I don´t use coinitializeex .application does not run built by Delphi.
-Seems mandatory for ASCOM to use TAutoObjectFactory don´t ask me why . I dont know it
-Setup dialog is a ascom defined method used to setup hardware and drives configuration poping  dialog ,most drivers are COM dll and did not have a graphical form for basic configuration(comport, moun type etc)  it can be left  empty if you have nothing to config.

I,m sure I didn´t explain myself very well.I have got  very basic english skills, but I will try it.

My application (Picgoto++ Server) implements a COM server ( automation object based) created  by using Delphi wizard.
It controls  a microcontroller device (PicGoto++ circuit) by serial port which commands (speed and position)up to four motors : two ones to drive telescope mount ,one more  to drive focuser, and the  last one to drive a filter wheel for CCD astronomical camera.
As standalone this video show how  Software drives the right ascension motor
http://www.youtube.com/watch?v=4Q69rQLvI-o
or a whole mount and  telescope
http://www.youtube.com/watch?v=xU3Y06iMFSo

ASCOM is "de facto" standard for most of astronomical software  available in Windows.
Skychart software  like Cartes du Ciel (developed firstly in Delphi and now in Lazarus for version 3) by Paul Chevalley ,The Sky,Skymap,Stellarium, include  clients to connect to these server called "ASCOM drivers".There are drivers for many astronomical brands and vendors.All o then f must  implement their on classes to satisfy    the common standard defined interface :Same properties same methods.

This applies too for  Astronomical software imaging adquisition and process There are specification for telescope mounts,focuser,filter wheel,derotator , and camera.

If you decide to develop (commercial or open source/hardware)an astronomical mount,camera you only have to write code to satisfy these standard properties and defined interfaces and your system will work with any compatible ASCOM Software.

In this video you can see how worksCDC skychart software, its client telescope module (It connect telescope drivers using createole object call).Select the Picgoto driver (my application) from a list of possible mount telescopes)  and telescope  mountcan be controlled from skychart application), pointing position is show as white bulls eye.

My application  is not a client.
http://www.youtube.com/watch?v=ZwmCs1R1x_E

My main interest for porting is because i want to develop the linux versión (in that case implementing INDI  protocols ,instead ASCOM which are not available for POSiX system ) to be able to work SDR , gnuradio for driving radio telescopes.
PicGoto is very extended control system for amaters because is free and can be home built .


I wish to thank you Ludo and Phil for all you work and patience.
PicgotoGroup  list have more than eight hundred members and sometimes to mantain  its like second job for me.




ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Error:Automation Object Aplication
« Reply #10 on: October 13, 2012, 06:43:56 pm »
OK that makes a big difference and explains also the use of TAutoObjectFactory.

Attached you'll find a IFocuser COM server that works for me. PicgotoPlus_1_0_TLB is obtained with importtl in FPC 2.7.1. There was a bug in comobj that caused a sigsegv when creating the COM object from the little PHP test program I have included. The SIGSEGV is fixed and I have submitted a patch to the FPC team. The zip includes the patch.
To register the server I ran
Code: [Select]
regsvr32 picgotoplus.dllThe class name is PicgotoPlus.Focuser.1

acapa

  • New Member
  • *
  • Posts: 10
Re: Error:Automation Object Aplication
« Reply #11 on: October 16, 2012, 10:18:27 pm »
Thanks! :)
I will switch to FCP2.7.0 and patch those file files to try again.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Error:Automation Object Aplication
« Reply #12 on: October 17, 2012, 08:26:20 am »
I will switch to FCP2.7.0 and patch those file files to try again.
The patch has been committed to 2.7.1 last saturday. So if you take a recent snapshot or download from svn, it will already be included.

acapa

  • New Member
  • *
  • Posts: 10
Re: Error:Automation Object Aplication
« Reply #13 on: October 18, 2012, 10:59:04 am »
I remember that I saw the sigsegv warn in one of my tries.

I built FPC2.7.1 from latest svn repository , compiled your example sources ,register dll and got working when invoked from focuser an ASCOM client.

I will try to adapt my application  again.Can you point me about how to run import typelib utility?
I dont know if its command line or I have to import it to lazarus external tools
Thanks again.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Error:Automation Object Aplication
« Reply #14 on: October 18, 2012, 11:26:34 am »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018