DLL example in Oxygene
Asked Answered
C

2

0

Can somebody tell me where to find an example in how to make an DLL (WindowsControlLibrary) in Oxygene for .NET?
In the old Delphi, you make an export section.

Curriery answered 28/10, 2009 at 14:32 Comment(0)
L
2

To create an Unmanaged DLL Export using Delphi Prism and call it with Delphi 2010 you must do the following:

In Delphi Prism:

  1. File | New | Project
  2. In the Tree View on the Left, select Delphi Prism
  3. Select Windows Class Library

Press OK.

This will create the template for the Windows Class Library

Right Click on the Project "ClassLibraryX" and Select Properties:

  1. Under Compatibility select "Allow unsafe code"
  2. Under Build, find the General Section and change CPU Type to "x86"
  3. Right Click on the "ClassLibraryX" tab that was created and select "Save selected Items"

This sets up the project to support the UnmanagedExportAttribute.

Then in the code you will need to create a class method. In the example below I added a reference to System.Windows.Forms.

namespace ClassLibrary2;

interface

type
  Class1 = public class
  private
  protected
  public
    [UnmanagedExport('ShowMessage')]
    class method ShowMessage(aMsg : String);
  end;

implementation

class method Class1.ShowMessage(aMsg : String);
begin
 System.Windows.Forms.MessageBox.Show(aMsg);  
end;

end.

Using a PEViewer, I used the one that ships as an example in JCL, you should be able to see the new export. In the above exampele "ShowMessage"

Langdon answered 29/10, 2009 at 0:13 Comment(2)
Thanks. I made a Simple ClassLibrary with one procedure, but when i try to read from a Delphi2010 appl, it can't find the entry. Should it be possible? Does it mean, that only other Prism2010, can access the dll? I would like to access the DLL, from a Delphi2010 applicationCurriery
Updated the answer to Show what I did to create an export.Langdon
M
1

If you whant to make it compatible with delphi then you have to indicate a "stdcall" Calling Convention

namespace ClassLibrary2;

interface

type Class1 = public class

private

protected

public

[UnmanagedExport('ShowMessage'), System.Runtime.InteropServices.CallingConvention.StdCall]

class method ShowMessage(aMsg : String); end;

implementation

class method Class1.ShowMessage(aMsg : String);

begin

System.Windows.Forms.MessageBox.Show(aMsg);

end;

end.

Moloch answered 13/8, 2010 at 18:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.