Recent

Author Topic: Accessing interfaces from the outside  (Read 3864 times)

loaded

  • Hero Member
  • *****
  • Posts: 824
Accessing interfaces from the outside
« on: April 25, 2017, 02:02:29 pm »
Hi All

Firstly;
I'm asking this question because I can use the generic Unique Identifier in interfaces.

Sample ;
Quoted from the http://stackoverflow.com/questions/12954973/putting-classes-in-a-dll

Code: Pascal  [Select][+][-]
  1. // The Interface-Deklaration for Main and DLL
  2. unit StringFunctions_IntfU;
  3.  
  4. interface
  5.  
  6. type
  7.   IStringFunctions = interface
  8.     ['{240B567B-E619-48E4-8CDA-F6A722F44A71}']
  9.     function CopyStr( const AStr : WideString; Index, Count : Integer ) : WideString;
  10.   end;
  11.  
  12. implementation
  13.  
  14. end.
  15.  

How can I access interfaces from an external exe with the CreateOleObject method like COM objects?

Code: Pascal  [Select][+][-]
  1. var
  2.   ComObje: OleVariant;
  3. begin
  4.     ComObje:= CreateOleObject('?');
  5.  

Respects.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: Accessing interfaces from the outside
« Reply #1 on: April 25, 2017, 05:11:12 pm »
I think, such library should be ActiveX server in this case - i.e. it should be special dll, that should export some special API, and you class should be registered in HKEY_CLASSES_ROOT section of registry. As I know, Delphi supports ActiveX dlls. But I don't see such option in Lazarus. I've seen how to create ActiveX dll manually somewhere, but I don't remember where.

If you don't want to use ActiveX - you should follow advice from article, you've quoted, and export some "CreateMyObjectX:IMyObjectX" functions from your dll and use it as usuall dll. If you still want to use Variant or OleVariant types even in this case - you should implement IDispatch interfaces for your classes.
« Last Edit: April 25, 2017, 05:20:25 pm by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

loaded

  • Hero Member
  • *****
  • Posts: 824
Re: Accessing interfaces from the outside
« Reply #2 on: April 25, 2017, 05:25:06 pm »
Thank you so much for your reply Mr.Madguy

As you said yes, this feature is also available in delphi.
Unfortunately, Lazarus does not exist directly
There are GUID values in ActiveX classes in Delphi.
When you see the GUID values in the above example.
I thought I could access the interfaces with the Createoleobject method.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11352
  • FPC developer.
Re: Accessing interfaces from the outside
« Reply #3 on: April 25, 2017, 05:48:40 pm »
You might want to look at the test programs in this bugreport:

http://bugs.freepascal.org/view.php?id=14919


ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: Accessing interfaces from the outside
« Reply #4 on: April 25, 2017, 06:04:25 pm »
How can I access interfaces from an external exe with the CreateOleObject method like COM objects?
See https://github.com/MartinTrummer/lazarus-com-example

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1311
    • Lebeau Software
Re: Accessing interfaces from the outside
« Reply #5 on: April 25, 2017, 08:42:05 pm »
I thought I could access the interfaces with the Createoleobject method.

CreateOleObject() requires the DLL and its classes to be registered in the Windows Registry.

When CreateOleObject() is called, it:

- looks up the specified ProgID in the Registry to determine the associated CLSID.
- calls CoCreateInstance() for the CLSID, asking for an IDispatch interface

When CoCreateInstance() is called, it:

- looks up the CLSID in the Registry to determine the path of the DLL and loads it, if not already loaded.
- calls the DLL's exported DllGetClassObject() function to get an IClassFactory interface
- calls IClassFactory.CreateInstance() to retrieve the requested interface (IDispatch) for the specified CLSID.

So, if you want to use CreateOleObject(), it is not enough that your DLL simply implement an interface, it has to implement and register a full-on ActiveX-compatible CoClass and class factory, too.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

loaded

  • Hero Member
  • *****
  • Posts: 824
Re: Accessing interfaces from the outside
« Reply #6 on: April 25, 2017, 09:42:21 pm »
Firstly;
For the answer
Markov thank you very much
I checked the link you sent. It got a bit confusing to me.
I'm going to check on the road again.
Thank you very much for your reply ASerge.
I think this is the answer I want;
There are interfaces in the Oleview program.
Regsvr32 registers with no problems, but when they are run from an external program, an error occurs. If I solve this problem, the problem will be solved.
I also thank you for Remy Lebeau.
For taking your precious time and responding.
God be pleased with you.
Respects.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

 

TinyPortal © 2005-2018