Recent

Author Topic: An attempt to build ActiveX library - failed  (Read 5793 times)

Barvinok

  • Newbie
  • Posts: 6
    • SciLog forum
An attempt to build ActiveX library - failed
« on: July 26, 2009, 08:32:21 am »
Hello all!

My main goal is to build x64 version of some ASP object I previously wrote using Delphi 2009.
Since I absolutely can not wait until Delphi Commodore release, I chose to use FPC/Lazarus as the only viable solution. First of all, I wanted to try the concept, that is, if ActiveX can be compiled to win32 target by FPC and used. Here's the story.

1. Open CodeGear Delphi 2009, File => New => Other => ActiveX library. I didn't add anything, just saved all files and built the DLL, naming the project TestAX.dpr with TestAX_TLB.pas. The DLL worked -- at least, it can be registered/unregistered.

2. Open Lazarus (0.9.27 beta svn-rev 20746 + fpc 2.2.5), choose "Convert from Delphi project" opened TestAX.dpr. What I see is ComServ unit apparently not present in FPC winunits-base. No choice, take it from CodeGear (copied ComServ.pas to the TestAX project folder) and try to port in on the fly 8)

3. To make it complain less, I set Delphi language compatibility project-wide in Compiler Options. Then here comes the story I already read ten times here, only slightly different. The following is the detailed description of the porting process.

3.1. procedure UnregisterTypeLibrary() fired up with ComServer.TypeLib.ReleaseTLibAttr(LibAttr); type incompatibility, I just dereferenced it per Marc suggestion, okay.

3.2. function GetTypeLibName() fired up with wrong arguments type:
Code: [Select]
function GetTypeLibName(TypeLib: ITypeLib): string;
var
  Name: WideString;
begin
  OleCheck(TypeLib.GetDocumentation(-1, @Name, nil, nil, nil));
  Result := Name;
end;
I checked GetDocumentation() and found out it expect all declared variables out'ed. No problem, made it this way:
Code: [Select]
function GetTypeLibName(TypeLib: ITypeLib): string;
var
  Name, dummy1, dummy3 : WideString;
  dummy2 : DWORD;
begin
  OleCheck(TypeLib.GetDocumentation(-1, Name, dummy1, dummy2, dummy3));
  Result := Name;
end;
far from beauty but it worked.

3.3. function AutomationTerminateProc() fired up with undeclared resourcestrings SNoCloseActiveServer1, SNoCloseActiveServer2 and SAutomationWarning. Although ComConst IS present in FPC it DOES NOT contain those declarations so I pasted them directly from ComConst.pas (copyleft CodeGear) into ComServ as not to disturb the integrity of FPC winunits-base.

3.4. method TComServer.Initialize() fired up in the exception handler for the reason it doesn't know ErrorCode member of EOleRegistrationError class. Oops. Marc says here, that his FPC 2.2.4 does have ErrorCode property. May it be that my FPC 2.2.5 is from parallel universe? :D It doesn't. So I made it dirty way:
Code: [Select]
  except
    on E: EOleRegistrationError do
      // User may not have write access to the registry.
      // Squelch the exception unless we were explicitly told to register.
      // == okay, we will have a bug here
      // if (E.ErrorCode <> TYPE_E_REGISTRYACCESS) or (FStartMode = smRegServer) then
    raise;
  end;

3.5. procedure TComServer.LastReleased() fired up on unknown identifier MainThreadID, which I replaced with GetCurrentThreadID().

3.6. FPC then can't find Graphics and StdVCL units referenced in TestAX_TLB.pas, I removed them.

4. Finally it compiles with the following messages:
Quote
ComServ.pas(15,2) Warning: Illegal compiler directive "$DENYPACKAGEUNIT"
ComServ.pas(131,64) Hint: Local variable "FindData" does not seem to be initialized
ComServ.pas(185,33) Hint: Parameter "TypeLib" not used
ComServ.pas(92,11) Hint: Unit "comconst" not used in ComServ
TestAX_TLB.pas(29,2) Warning: Illegal compiler directive "$VARPROPSETTER"
TestAX_TLB.pas(33,22) Hint: Unit "ActiveX" not used in TestAX_TLB
Project "TestAX" successfully built. :)

It seemed all fine, until I tried to REGSVR32 the newly born DLL, and it failed to load.  >:(

I kindly ask the respected community to point out the proper way of compiling ActiveX libraries in Lazarus/FPC. Any help will be greatly appreciated.
Unlike reality, stupidity is inescapable

Paul Ishenin

  • Sr. Member
  • ****
  • Posts: 274
Re: An attempt to build ActiveX library - failed
« Reply #1 on: July 26, 2009, 01:56:52 pm »
Try to use fpc 2.3.1 (trunk). There were fixed many problems both with win64 dlls and some activex (for example r13449 was made for you by Florian).

 

TinyPortal © 2005-2018